This is alot if code so I won't be suprised if nobody can be bothered to help, but appreciate if you can
The problem is, I create one instance employees/manager salesman or employee, and no problem
When I try an instance of employee, manager and salesman, it crashs, I thought it may be a memory error but changing the model size to medium/large makes no difference.
I'm still experimenting but its beyond my meager efforts
Anyway, code (if you can be bothered, you might want to copy code to c prog)
go straight down to bottom (void main(void))
char* weekDay(char dayInfo);
char* monthName(int monthInfo);
int monthName(char monthInfo[8]);
const int LEN = 80;// maximum length of names
const int daysPerWeek = 7;
const int monthsPerYear = 12;
const int weeksPerMonth = 4; //including 0
const float satPayMultiplier = 1.2;
const float sunPayMultiplier = 1.5;
struct day{
float hoursWorked;
};
struct week{
//well, the days of the week, hours worked for each week
day days[daysPerWeek];
float totalHours;
};
struct month{
//well, the days of the week, hours worked for each week
week weeks[weeksPerMonth];
float totalHours;
float totalSaturdayHours;
float totalSundayHours;
float totalNormalHours;
};
struct year{
//
month months[monthsPerYear];
float totalHours;
float totalNormalHours;
float totalSaturdayHours;
float totalSundayHours;
float totalNormalPay;//pay total m-f
float totalSaturdayPay;//pay total for Saturdays
float totalSundayPay;//pay total for Sundays
float totalPay;//pay total for year
};
class employees
{
private:
protected:
char name[LEN];
float payrate;
float hours;
float satPayrate;
float sunPayrate;
year hoursWorked;//hours worked record
public:
void virtual getdata(void);
void virtual putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
class manager : public employees
{
private:
public:
void putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
class salesman : public employees
{
private:
public:
void putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
class employee: public employees// employee class
{
private:
public:
void putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
void employees::getdata(void)
{
satPayrate = payrate * satPayMultiplier; // calc saturday pay rate
sunPayrate = payrate * sunPayMultiplier;// calc sunday pay rate
cout << "Enter salesman's name : "; cin >> name;
cout << "Enter payrate : "; cin >> payrate;
for(int i=0;i<monthsPerYear;i++)//months
{
cout << "\nEnter hours worked for the month of " << monthName(i) << endl;
for(int s=0;s<weeksPerMonth;s++)//weeks
{
for(int g=0;g<daysPerWeek;g++) //days
{
cout << "Enter hours worked for " << weekDay(g) << " : ";cin >> hours;
hoursWorked.months.weeks.days[g].hoursWorked = hours;//get hours for day
hoursWorked.months.weeks.totalHours += hours;//add to week total
hoursWorked.months.totalHours += hours;//add total for month
if(g==5)//add saturday hours in month
{
hoursWorked.months.totalSaturdayHours += hours;
hoursWorked.totalSaturdayHours += hours; //add hours to sat year total
hoursWorked.totalSaturdayPay += hours * satPayrate; // calc pay and add to total
}
else if(g==6)//add sunday hours in month
{
hoursWorked.months.totalSundayHours = hours;
hoursWorked.totalSundayHours += hours; //add hours to sat year total
hoursWorked.totalSundayPay += hours * sunPayrate; // calc pay and add to total
}
else//add normal hours in month
{
hoursWorked.months.totalNormalHours += hours;
hoursWorked.totalNormalHours += hours;
hoursWorked.totalNormalPay += hours * payrate; // calc pay and add to total
}
}//end week
// calc/add to total pay for all months
hoursWorked.totalPay += hoursWorked.totalNormalPay + hoursWorked.totalSaturdayPay + hoursWorked.totalSundayPay;
}//end month
}//end year
}
void main(void)
{
char ch;
manager mEmp; // with one of these, it works but not with all three
//salesman sEmp;
//employee eEmp;
//eEmp.getdata();
}
The problem is, I create one instance employees/manager salesman or employee, and no problem
When I try an instance of employee, manager and salesman, it crashs, I thought it may be a memory error but changing the model size to medium/large makes no difference.
I'm still experimenting but its beyond my meager efforts
Anyway, code (if you can be bothered, you might want to copy code to c prog)
go straight down to bottom (void main(void))
char* weekDay(char dayInfo);
char* monthName(int monthInfo);
int monthName(char monthInfo[8]);
const int LEN = 80;// maximum length of names
const int daysPerWeek = 7;
const int monthsPerYear = 12;
const int weeksPerMonth = 4; //including 0
const float satPayMultiplier = 1.2;
const float sunPayMultiplier = 1.5;
struct day{
float hoursWorked;
};
struct week{
//well, the days of the week, hours worked for each week
day days[daysPerWeek];
float totalHours;
};
struct month{
//well, the days of the week, hours worked for each week
week weeks[weeksPerMonth];
float totalHours;
float totalSaturdayHours;
float totalSundayHours;
float totalNormalHours;
};
struct year{
//
month months[monthsPerYear];
float totalHours;
float totalNormalHours;
float totalSaturdayHours;
float totalSundayHours;
float totalNormalPay;//pay total m-f
float totalSaturdayPay;//pay total for Saturdays
float totalSundayPay;//pay total for Sundays
float totalPay;//pay total for year
};
class employees
{
private:
protected:
char name[LEN];
float payrate;
float hours;
float satPayrate;
float sunPayrate;
year hoursWorked;//hours worked record
public:
void virtual getdata(void);
void virtual putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
class manager : public employees
{
private:
public:
void putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
class salesman : public employees
{
private:
public:
void putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
class employee: public employees// employee class
{
private:
public:
void putdata()
{
cout << "\nName: " << name;
cout << "\nPayrate: " << payrate;
}
};
void employees::getdata(void)
{
satPayrate = payrate * satPayMultiplier; // calc saturday pay rate
sunPayrate = payrate * sunPayMultiplier;// calc sunday pay rate
cout << "Enter salesman's name : "; cin >> name;
cout << "Enter payrate : "; cin >> payrate;
for(int i=0;i<monthsPerYear;i++)//months
{
cout << "\nEnter hours worked for the month of " << monthName(i) << endl;
for(int s=0;s<weeksPerMonth;s++)//weeks
{
for(int g=0;g<daysPerWeek;g++) //days
{
cout << "Enter hours worked for " << weekDay(g) << " : ";cin >> hours;
hoursWorked.months.weeks
hoursWorked.months.weeks
hoursWorked.months.totalHours += hours;//add total for month
if(g==5)//add saturday hours in month
{
hoursWorked.months.totalSaturdayHours += hours;
hoursWorked.totalSaturdayHours += hours; //add hours to sat year total
hoursWorked.totalSaturdayPay += hours * satPayrate; // calc pay and add to total
}
else if(g==6)//add sunday hours in month
{
hoursWorked.months.totalSundayHours = hours;
hoursWorked.totalSundayHours += hours; //add hours to sat year total
hoursWorked.totalSundayPay += hours * sunPayrate; // calc pay and add to total
}
else//add normal hours in month
{
hoursWorked.months.totalNormalHours += hours;
hoursWorked.totalNormalHours += hours;
hoursWorked.totalNormalPay += hours * payrate; // calc pay and add to total
}
}//end week
// calc/add to total pay for all months
hoursWorked.totalPay += hoursWorked.totalNormalPay + hoursWorked.totalSaturdayPay + hoursWorked.totalSundayPay;
}//end month
}//end year
}
void main(void)
{
char ch;
manager mEmp; // with one of these, it works but not with all three
//salesman sEmp;
//employee eEmp;
//eEmp.getdata();
}