c++ please need help with this question Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and
c++ please need help with this question
Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows:
class Employee
{
private:
int age;
int id;
float salary;
public:
Employee( ); // default constructor: age=0, id=0, and salary=0
Employee(Employee &x); // copy constructor
Employee& operator = (Employee &x); // equal sign operator
void setAge(int x); // let age = x
void setId(int x); // let id = x
void setSalary(float x); // salary = x
int getAge( ); // return age
int getId( ); // return id
float getSalary( ); // return salary
void print( ); // print out the values of attributes on computer screen
};
You need to provide the definition of the default constructor and the first three member functions (setAge, setId and setSalary) inside the scope defined by the brackets of class Employee and other three member functions (getAge, getId, and getSalary) outside the scope defined by the brackets of class Employee, as shown in the following skeleton:
class Employee
{
Employee( )
{ ..... }
void setAge(int x)
{ ......... }
void setId(int x)
{ ......... }
void setSalary(float x)
{ ......... }
};
int Employee::getAge( )
{
.....
}
int Employee::getId( )
{
....
}
float Employee::getSalary( )
{
......
}
Write a main routine in which you create 5 Employee objects: a, b, c, d, and e. Set the values of a, b and c as follows:
Objects | Age | Id | Salary |
a | 40 | 111 | 30000 |
b | 41 | 112 | 31000 |
c | 42 | 113 | 32000 |
The skeleton of the main( ) is as follows:
void main( )
{
// create 4 Employee objects: a, b, c, d
..
// set the values of a, b and c according to the above table
// Use copy constructor to assign the content of object a to the content of object e
// print out the contents of a and e to show they are the same
// Use = operator to assign the content of object b to the content of object d
// print out the contents of b and d to show they are the same
// create an output file name: output.txt
// output the contents of d and e to the file, output.txt
}
You should open output.txt with a text editor and create a screenshot to show its contents.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started