[Dev-C++] I have a problem with class method, need help.......
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Julio L. <ju2...@ya...> - 2001-07-20 18:30:39
|
I am having problems getting getRoundedSalary to
return salary(rounded to the nearest 1,000). When I
try to get it to output employ->getRoundedSalary() to
the screen later in the code it says it is of unknown
type and wont let it be displayed to screen. Can
anyone suggest how I should rewrite getRoundedSalary
so I can get it to output salary rounded to the
nearest 1,000? Here is my code :
#include <iostream.h>
#include <stdlib.h>
class Employee
{
public:
unsigned short int getAge(){return age;}
void setAge(int setAgeTo){ age =setAgeTo;}
unsigned short int getYearsOfService(){return
yearsOfService;}
void setYearsOfService(int
setYearsOfServiceTo){yearsOfService
=setYearsOfServiceTo;}
unsigned long int getSalary(){return salary;}
void setSalary(long int setSalaryTo){salary
=setSalaryTo;}
float getRoundedSalary()
{
return (salary+500)/1000;
}
private:
unsigned short int age;
unsigned short int yearsOfService;
unsigned long int salary;
};
int main()
{
unsigned long int emplOneAge, emplTwoAge, emplOneServ,
emplTwoServ, emplOneSal, emplTwoSal;
cout << "How old is employee 1?: ";
cin >> emplOneAge;
Employee *employOne= new Employee;
employOne->setAge(emplOneAge);
cout << "\n\nFor how many years has employee 1 been
working for you?: ";
cin >> emplOneServ;
employOne->setYearsOfService(emplOneServ);
cout << "\n\nHow much money does employee 1 make?: ";
cin >> emplOneSal;
employOne->setSalary(emplOneSal);
cout << "\n\nHow old is employee 2?: ";
cin >> emplTwoAge;
Employee *employTwo= new Employee;
employTwo->setAge(emplTwoAge);
cout << "\n\nFor how many years has employee 2 been
working for you?: ";
cin >> emplTwoServ;
employTwo->setYearsOfService(emplTwoServ);
cout << "\n\nHow much money does employee 2 make?: ";
cin >> emplTwoSal;
employTwo->setSalary(emplTwoSal);
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
while(true)
{
unsigned short int menuChoice;
cout << "\t\t\t****************************\n";
cout << "\t\t\t* Employee Directory *\n";
cout << "\t\t\t* Choices: *\n";
cout << "\t\t\t* *\n";
cout << "\t\t\t* 1)Employee 1 Info. *\n";
cout << "\t\t\t* 2)Employee 2 Info. *\n";
cout << "\t\t\t* 3)Exit *\n";
cout << "\t\t\t****************************\n";
cout << "\t\t\t Enter Choice: ";
cin >> menuChoice;
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
switch(menuChoice)
{
case 1: cout << "Current Information on Employee
1:\n\n";
cout << "Age: " << employOne->getAge() << endl;
cout << "Years of Service: " <<
employOne->getYearsOfService() << endl;
cout << "Salary: " << employOne->getSalary() << endl;
cout << "Salary (To nearest $1,000): " <<
employOne->getRoundedSalary << endl;
system("PAUSE");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
continue;
case 2: cout << "Current Information on Employee
2:\n\n";
cout << "Age: " << employTwo->getAge() << endl;
cout << "Years of Service: " <<
employTwo->getYearsOfService() << endl;
cout << "Salary: " << employTwo->getSalary() << endl;
cout << "Salary (To nearest $1,000): " <<
employTwo->getRoundedSalary << endl;
system("PAUSE");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
continue;
case 3: break;
default: continue;
} //end switch(menuChoice)
break;
}//end while(true)
delete employOne;
delete employTwo;
} //end main()
=====
Julio
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
|