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
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
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
};
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 an 2-D array of Employee x[2][3]. Set the values for all the elements of the array as follows:
| Age | Id | Salary |
x[0][0] | 30 | 111 | 30000 |
x[0][1] | 31 | 112 | 31000 |
x[0][2] | 32 | 113 | 32000 |
x[1][0] | 33 | 114 | 33000 |
x[1][1] | 34 | 115 | 34000 |
x[1][2] | 35 | 116 | 35000 |
Then, pass the array to a function, PrintEmployee(arg1, arg2, arg3), in which arg1 should be the array of Employee, arg2 is the length of the first dimension of the array (=2 in this case), and arg3 is the length of the second dimension of the array (=3 in this case). In PrinteEmployee(arg1, arg2, arg3), write a for loop to print out the information of each employee (in this case, we have six employees in total). In addition, an average age and an average salary should be also printed out.
The skeletons of the main( ) and PrintEmployee() are as follows:
void main( )
{
// create an array of Employee with two elements
..
// set the values for all the elements of the array by using public member functions
// call PrintEmployee( ) with a proper parameter list
PrintEmplyee( arg1, arg2, arg3);
}
void PrintEmployee(arg1, arg2, arg3)
{
// for loop
.
// print out an average age and an average salary
.
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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