בעייה ב++C

בעייה ב++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::portfolio(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);
}


מישהו יכול להסביר לי בבקשה איך ליצור מערך אובייקטים ולאתחל אותם באמצעות קלט מהמשתמש ע"י פונקציה בונה ?

תודה למשיבים
 

Guy Yafe

New member
הקומפיילר נתן לך את התשובה

כל המשתנים: m_id, m_overTme וכו' מעולם לא הוכרזו. המשתנים האלה לא קיימים.
 

nocgod

New member
בנוסף

אתה לא מכריז על מערך סטאטי של אובייקטים (מה שמחייב אותך בבנאי ריק/default) כי אז אתה מקבל מערך סטאטי של אוביקטים בנויים
אתה לא קורא על דעת עצמך לבנאי כי דברים לא עובדים ככה.
כדי לעשות מערך של אובייקטים שעבור כל אחד את מפעיל בנאי שהוא לא בנאי דיפולטיבי
אתה צריך לעשות מערך של מצביעים למחלקה
להקצות זיכרון באמצעות new ולהעביר את המידע לבנאי של האובייקט (שים לב שאת הבנאי בוחרת המערכת בשבילך בהתאם לפרמטרי שהעברת)
כלומר אתה צריך לכתוב קוד בסגנון של

Portfolio* arr[10];
int someData, someMoreData;

for (int i = 0; i < 10)
{
readData(&someData, &someMoreData);
arr = new Portfolio(someData, someMoreData);
}


זה כמובן בנוסף לעובדה שmain אינו מכיר את המשתנים שאתה מנסה לדחוף בקריאה מפורשת לבנאי שאתה עושה
 
למעלה