עזרה ב ++C
אני חדש ב ++ C. ונעזר בספר ++ C כשפת אם של יצחק גרבר. ומתקשה ביצירת פונקציה בונה לחישוב שכר.
//main.cpp
#include <iostream>
#include "Portfolio.h"
#include<conio.h>
#define SIZE 2
#define OVER_TIME 1.5
using namespace std;
int main()
{
int i;
Portfolio worker[SIZE];
for(i=0;i<SIZE;i++)
worker.Portfolio(id, hourlySalary, totalHours, overTime);
for(i=0;i<SIZE;i++)
cout<<setw(10)<<worker.salaryCalculation(hourlySalary, totalHours, overTime);
getch();
return 0;
}
//Portfolio.h
#ifndef PORTFOLIO_H_INCLUDED
#define PORTFOLIO_H_INCLUDED
class Portfolio{
int id;
float hourlySalary, // שכר לשעה
totalHours, // סך שעות יסוד
overTime;// שעות נוספות
public:
Portfolio(int id, float hourlySalary, float totalHours, float overTime);// פונקציה בונה
float salaryCalculation(float hourlySalary, float totalHours, float overTime);// חישוב שכר
};
#endif // PORTFOLIO_H_INCLUDED
//Portfolio.cpp
#include "Portfolio.h"
inline Portfolio:
ortfolio(int id, float hourlySalary, float totalHours, float overTime)
{
while(!id)
{
cout<<"Enter id";
cin>>id;
}
while(!hourlySalary)
{
cout<<"Enter hourly Salary";
cin>>hourlySalary;
}
while(!totalHours)
{
cout<<"Enter total Hours";
cin>>totalHours;
}
while(!overtime)
{
cout<<"Enter over Time";
cin>>overTime;
}
}
inline float salaryCalculation(float hourlySalary, float totalHours, float overTime)
{
float sum;
return sum=(hourlySalary*totalHours)+(hourlySalary*overTime*OVER_TIME);
}
השגיאות המתקבלות
\Portfolio\main.cpp||In function 'int main()':|
\Portfolio\main.cpp|13|error: no matching function for call to 'Portfolio:
ortfolio()'|
\Portfolio\Portfolio.h|10|note: candidates are: Portfolio:
ortfolio(int, float, float, float)|
\Portfolio\Portfolio.h|4|note: Portfolio:
ortfolio(const Portfolio&)|
\Portfolio\main.cpp|15|error: invalid use of 'class Portfolio'|
\Portfolio\main.cpp|15|error: 'id' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'hourlySalary' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'totalHours' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'overTime' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'setw' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'hourlySalary' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'totalHours' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'overTime' was not declared in this scope|
||=== Build finished: 10 errors, 0 warnings ===|
מה הבעיה בתוכנית?
תודה למשיבים.
אני חדש ב ++ C. ונעזר בספר ++ C כשפת אם של יצחק גרבר. ומתקשה ביצירת פונקציה בונה לחישוב שכר.
//main.cpp
#include <iostream>
#include "Portfolio.h"
#include<conio.h>
#define SIZE 2
#define OVER_TIME 1.5
using namespace std;
int main()
{
int i;
Portfolio worker[SIZE];
for(i=0;i<SIZE;i++)
worker.Portfolio(id, hourlySalary, totalHours, overTime);
for(i=0;i<SIZE;i++)
cout<<setw(10)<<worker.salaryCalculation(hourlySalary, totalHours, overTime);
getch();
return 0;
}
//Portfolio.h
#ifndef PORTFOLIO_H_INCLUDED
#define PORTFOLIO_H_INCLUDED
class Portfolio{
int id;
float hourlySalary, // שכר לשעה
totalHours, // סך שעות יסוד
overTime;// שעות נוספות
public:
Portfolio(int id, float hourlySalary, float totalHours, float overTime);// פונקציה בונה
float salaryCalculation(float hourlySalary, float totalHours, float overTime);// חישוב שכר
};
#endif // PORTFOLIO_H_INCLUDED
//Portfolio.cpp
#include "Portfolio.h"
inline Portfolio:
{
while(!id)
{
cout<<"Enter id";
cin>>id;
}
while(!hourlySalary)
{
cout<<"Enter hourly Salary";
cin>>hourlySalary;
}
while(!totalHours)
{
cout<<"Enter total Hours";
cin>>totalHours;
}
while(!overtime)
{
cout<<"Enter over Time";
cin>>overTime;
}
}
inline float salaryCalculation(float hourlySalary, float totalHours, float overTime)
{
float sum;
return sum=(hourlySalary*totalHours)+(hourlySalary*overTime*OVER_TIME);
}
השגיאות המתקבלות
\Portfolio\main.cpp||In function 'int main()':|
\Portfolio\main.cpp|13|error: no matching function for call to 'Portfolio:
\Portfolio\Portfolio.h|10|note: candidates are: Portfolio:
\Portfolio\Portfolio.h|4|note: Portfolio:
\Portfolio\main.cpp|15|error: invalid use of 'class Portfolio'|
\Portfolio\main.cpp|15|error: 'id' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'hourlySalary' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'totalHours' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'overTime' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'setw' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'hourlySalary' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'totalHours' was not declared in this scope|
\Portfolio\main.cpp|17|error: 'overTime' was not declared in this scope|
||=== Build finished: 10 errors, 0 warnings ===|
מה הבעיה בתוכנית?
תודה למשיבים.