Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unkown error when I try running this script (HELP)... please

Status
Not open for further replies.

Exodious

Programmer
Jan 6, 2001
1
GB
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 << &quot;\nName: &quot; << name;
cout << &quot;\nPayrate: &quot; << payrate;
}
};
class manager : public employees
{
private:
public:
void putdata()
{
cout << &quot;\nName: &quot; << name;
cout << &quot;\nPayrate: &quot; << payrate;
}
};
class salesman : public employees
{
private:
public:
void putdata()
{
cout << &quot;\nName: &quot; << name;
cout << &quot;\nPayrate: &quot; << payrate;
}
};
class employee: public employees// employee class
{
private:
public:
void putdata()
{
cout << &quot;\nName: &quot; << name;
cout << &quot;\nPayrate: &quot; << payrate;
}
};
void employees::getdata(void)
{
satPayrate = payrate * satPayMultiplier; // calc saturday pay rate
sunPayrate = payrate * sunPayMultiplier;// calc sunday pay rate
cout << &quot;Enter salesman's name : &quot;; cin >> name;
cout << &quot;Enter payrate : &quot;; cin >> payrate;
for(int i=0;i<monthsPerYear;i++)//months
{
cout << &quot;\nEnter hours worked for the month of &quot; << monthName(i) << endl;
for(int s=0;s<weeksPerMonth;s++)//weeks
{
for(int g=0;g<daysPerWeek;g++) //days
{
cout << &quot;Enter hours worked for &quot; << weekDay(g) << &quot; : &quot;;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();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top