בעייה ב++C
אני עוד תקוע בתוכנית הראשונה. והתייאשתי על ההתחלה. ולמרות שניסיתי לעבוד כפי מה שהבנתי מselalerer עכ"ז אני ממשיך לקבל את השגיאות דלהלן:
||=== Portfolio, Debug ===|
\Portfolio\main.cpp||In function 'int main()':|
\Portfolio\main.cpp|15|error: invalid use of 'class Portfolio'|
\Portfolio\main.cpp|15|error: 'm_id' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'm_hourlySalary' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'm_totalHours' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'm_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: 9 errors, 0 warnings ===|
להלן קוד התוכנית
mine.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(m_id, m_hourlySalary, m_totalHours, m_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:
int setId();
float setDate();
Portfolio()
{
id=0;
hourlySalary=totalHours=overTime=0;
}
Portfolio(int m_id, float m_hourlySalary, float m_totalHours, float m_overTime);// פונקציה בונה
float salaryCalculation(float hourlySalary, float totalHours, float overTime);// חישוב שכר
};
#endif // PORTFOLIO_H_INCLUDED
//Portfolio.cpp
#include "Portfolio.h"
Portfolio:
ortfolio(int m_id, float m_hourlySalary, float m_totalHours, float m_overTime)
{
cin>>m_id;
if(!cin)
{
cerr<<"Enter id";
cin.clear();
}
id=m_id;
cin>>m_hourlySalary;
if(!cin)
{
cerr<<"Enter hourly Salary";
cin.clear();
}
hourlySalary=m_hourlySalary;
cin>>m_totalHours;
if(!cin)
{
cerr<<"Enter total Hours";
cin.clear();
}
totalHours=m_totalHours;
cin>>m_overTime;
if(!cin)
{
cerr<<"Enter over Time";
cin.clear();
}
overTime=m_overTime;
}
inline float salaryCalculation(float hourlySalary, float totalHours, float overTime)
{
float sum;
return sum=(hourlySalary*totalHours)+(hourlySalary*overTime*OVER_TIME);
}
מישהו יכול להסביר לי בבקשה איך ליצור מערך אובייקטים ולאתחל אותם באמצעות קלט מהמשתמש ע"י פונקציה בונה ?
תודה למשיבים
אני עוד תקוע בתוכנית הראשונה. והתייאשתי על ההתחלה. ולמרות שניסיתי לעבוד כפי מה שהבנתי מselalerer עכ"ז אני ממשיך לקבל את השגיאות דלהלן:
||=== Portfolio, Debug ===|
\Portfolio\main.cpp||In function 'int main()':|
\Portfolio\main.cpp|15|error: invalid use of 'class Portfolio'|
\Portfolio\main.cpp|15|error: 'm_id' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'm_hourlySalary' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'm_totalHours' was not declared in this scope|
\Portfolio\main.cpp|15|error: 'm_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: 9 errors, 0 warnings ===|
להלן קוד התוכנית
mine.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(m_id, m_hourlySalary, m_totalHours, m_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:
int setId();
float setDate();
Portfolio()
{
id=0;
hourlySalary=totalHours=overTime=0;
}
Portfolio(int m_id, float m_hourlySalary, float m_totalHours, float m_overTime);// פונקציה בונה
float salaryCalculation(float hourlySalary, float totalHours, float overTime);// חישוב שכר
};
#endif // PORTFOLIO_H_INCLUDED
//Portfolio.cpp
#include "Portfolio.h"
Portfolio:
{
cin>>m_id;
if(!cin)
{
cerr<<"Enter id";
cin.clear();
}
id=m_id;
cin>>m_hourlySalary;
if(!cin)
{
cerr<<"Enter hourly Salary";
cin.clear();
}
hourlySalary=m_hourlySalary;
cin>>m_totalHours;
if(!cin)
{
cerr<<"Enter total Hours";
cin.clear();
}
totalHours=m_totalHours;
cin>>m_overTime;
if(!cin)
{
cerr<<"Enter over Time";
cin.clear();
}
overTime=m_overTime;
}
inline float salaryCalculation(float hourlySalary, float totalHours, float overTime)
{
float sum;
return sum=(hourlySalary*totalHours)+(hourlySalary*overTime*OVER_TIME);
}
מישהו יכול להסביר לי בבקשה איך ליצור מערך אובייקטים ולאתחל אותם באמצעות קלט מהמשתמש ע"י פונקציה בונה ?
תודה למשיבים