yllee
asked on
round up
#include <iostream.h>
#include <string.h>
class Employee
{
private :
char *name;
int age;
int YearsOfService;
float Salary;
public :
Employee();
void setEmployeeDetail();
void setEmployeeName(char*);
void setAge(int);
void setYearsOfService(int);
void setSalary(float);
void display();
};
Employee::Employee()
{
name = "";
age = 0;
YearsOfService = 0;
Salary = 0;
}
void Employee::setEmployeeDetai l()
{
const int Max = 80;
char eName[Max];
int eAge, eYOS;
float eSalary;
cout << "Enter employee name : ";
cin.getline(eName, Max);
cout << "Enter age : ";
cin >> eAge;
cout << "Enter salary : $";
cin >> eSalary;
cout << "Enter Years of service : ";
cin >> eYOS;
cin.ignore();
cout << endl;
setEmployeeName(eName);
setAge(eAge);
setSalary(eSalary);
setYearsOfService(eYOS);
}
void Employee::setEmployeeName( char *eName)
{
name = new char[strlen (eName) + 1];
strcpy(name, eName);
}
void Employee::setAge(int x)
{
age = x;
}
void Employee::setYearsOfServic e(int x)
{
YearsOfService = x;
}
void Employee::setSalary(float x)
{
Salary = x;
}
void Employee::display()
{
cout << endl;
cout << "Employee name : " << name;
cout << endl;
cout << "Age : " << age;
cout << endl;
cout << "Salary : $" << Salary;
cout << endl;
cout << "Year of service : " << YearsOfService;
cout << endl;
cout << endl;
}
void main()
{
int i;
Employee erecord[2];
for (i = 0; i < 2; i++)
erecord[i].setEmployeeDeta il();
for (i = 0; i < 2; i++)
erecord[i].display();
}
How can I rounded the salary to the nearest 1,000?
#include <string.h>
class Employee
{
private :
char *name;
int age;
int YearsOfService;
float Salary;
public :
Employee();
void setEmployeeDetail();
void setEmployeeName(char*);
void setAge(int);
void setYearsOfService(int);
void setSalary(float);
void display();
};
Employee::Employee()
{
name = "";
age = 0;
YearsOfService = 0;
Salary = 0;
}
void Employee::setEmployeeDetai
{
const int Max = 80;
char eName[Max];
int eAge, eYOS;
float eSalary;
cout << "Enter employee name : ";
cin.getline(eName, Max);
cout << "Enter age : ";
cin >> eAge;
cout << "Enter salary : $";
cin >> eSalary;
cout << "Enter Years of service : ";
cin >> eYOS;
cin.ignore();
cout << endl;
setEmployeeName(eName);
setAge(eAge);
setSalary(eSalary);
setYearsOfService(eYOS);
}
void Employee::setEmployeeName(
{
name = new char[strlen (eName) + 1];
strcpy(name, eName);
}
void Employee::setAge(int x)
{
age = x;
}
void Employee::setYearsOfServic
{
YearsOfService = x;
}
void Employee::setSalary(float x)
{
Salary = x;
}
void Employee::display()
{
cout << endl;
cout << "Employee name : " << name;
cout << endl;
cout << "Age : " << age;
cout << endl;
cout << "Salary : $" << Salary;
cout << endl;
cout << "Year of service : " << YearsOfService;
cout << endl;
cout << endl;
}
void main()
{
int i;
Employee erecord[2];
for (i = 0; i < 2; i++)
erecord[i].setEmployeeDeta
for (i = 0; i < 2; i++)
erecord[i].display();
}
How can I rounded the salary to the nearest 1,000?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, you put the line in the SetSalary method just after Salary = x; and put the #include with the other #includes.
It would be nice if the accepted answer was correct!
Sorry guys, I didn't really look at the code. I was rushed. Its just a general rounding algorithm I jotted down. And yes, jc, I forgot to *1000.
try the following:
#include <math.h>
....
Salary = floor(Salary/1000+0.5)*100