RE: [Dev-C++] I have a problem with class method, need help...... .
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Schedler, K. <Kur...@hi...> - 2001-07-20 18:51:21
|
You are using employOne->getRoundedSalary instead of
employOne->getRoundedSalary().
-----Original Message-----
From: Julio Lajara [mailto:ju2...@ya...]
Sent: Friday, July 20, 2001 11:31 AM
To: dev...@li...
Subject: [Dev-C++] I have a problem with class method, need help.......
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/
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
"The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent. This message
and its attachments could have been infected during transmission. By
reading the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects. The sender's employer is not liable for any loss or damage
arising in any way from this message or its attachments."
|