help with classes
Oct 31, 2011 at 2:31am UTC
ok all i need help here, im trying to figure out in this code, in main, where it says it is going to display employee information, it to go from main, to the class and run the cout statements in the class...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include "employee.h";
#include "payroll.h";
using namespace std;
int hours;
double hourlyrate;
double grosspay;
int maxhours;
employee::employee ()
{
employee employee1;
employee employee2;
employee employee3;
employee1.firstname = "susan" ;
employee1.lastname = "meyers" ;
employee1.idnum = "47899" ;
employee1.dept = "accounting" ;
employee1.position = "vice president" ;
employee2.firstname = "mark" ;
employee2.lastname = "jones" ;
employee2.idnum = "39119" ;
employee2.dept = "it" ;
employee2.position = "programer" ;
employee3.firstname = "joy" ;
employee3.lastname = "rogers" ;
employee3.idnum = "81774" ;
employee3.dept = "manufacturing" ;
employee3.position = "engineer" ;
cout << employee1.firstname << " " << employee1.lastname << " id number: " << employee1.idnum << " " << employee1.dept << " " << employee1.position << endl;
cout << employee2.firstname << " " << employee2.lastname << " id number: " << employee2.idnum << " " << employee2.dept << " " << employee2.position << endl;
cout << employee3.firstname << " " << employee3.lastname << " id number: " << employee3.idnum << " " << employee3.dept << " " << employee3.position << endl;
}
void payroll ()
{
cout << "please enter the payrate:" ;
cin >> hourlyrate;
cout << "please enter the hours:" ;
cin >> hours;
if (hours > 60)
{
hours = 0;
cout << "hours must be less then 60. " ;
cout << "please reenter hours:" ;
cin >> hours;
}
else
{
grosspay = hourlyrate * hours;
}
cout << "the gross pay for the week is " << grosspay << endl;
}
int main ()
{
cout << "here are three random employees from a random company" << endl;
cout <<"now lets calculate last weeks paycheck for them:" << endl;
}
Oct 31, 2011 at 2:47am UTC
Well it looks like your constructor creates new objects, which in turn create new objects, this seems ... like it shouldn't work? But anyhow, if you just want to call your constructor function, all you have to do is declare a new variable of the class type.
for instance:
1 2 3 4
int main(){
employee failtrainwatchmesegfault;
return -10000;
}
You mayyyyy have to slightly
tweak your constructor (the employee::employee())
Topic archived. No new replies allowed.