Define and implement the overloaded constructors that support the following test
ID: 3541068 • Letter: D
Question
Define and implement the overloaded constructors that support the following test function for a StudentEmployee class. The data members for the StudentEmployee class are:
%u2022 age - integer number
%u2022 name - String
%u2022 DSI - String
%u2022 salary - floating point number
int main()
{ //s1 will take all default value
StudentEmployee s1();
//s2 will take all supplied values
StudentEmployee s2 (50, "Jackie Chan", "D87654321", 10000000.99);
//s3 will take supplied age value, name, DSI and salary will take default values
StudentEmployee s3 (25);
//s4 will take supplied age and name value, DSI and salary will take default values
StudentEmployee s4 (35, "Jenny");
//s5 will take supplied age, name and DSI value, salary will take default value
StudentEmployee s5 (45, "Jack", "D11223344");
//s6 will take supplied age, name and salary value, DSI will take default value
StudentEmployee s6 (60, "James Bond", 65000.0);
//s7 will take the same value of s2
StudentEmployee s7=s2;
//the rest of the code
}
Explanation / Answer
class StudentEmployee
{
int age ;
string name;
string DSI;
float salary;
}
StudentEmployee()
{
age=0 ;
name="";
DSI="";
salary=0.0;
}
StudentEmployee(int a,string n,string d,float s)
{
age=a ;
name=n;
DSI=d;
salary=s;
}
StudentEmployee(int a)
{
age=a;
name="";
DSI="";
salary=0.0;
}
StudentEmployee(int a,string n)
{
age=a;
name=n;
DSI="";
salary=0.0;
}
StudentEmployee(int a,string n,string d)
{
age=a;
name=n;
DSI=d;
salary=0.0;
}
StudentEmployee(int a,string n,float s)
{
age=a;
name=n;
DSI="";
salary=s;
}
int main()
{ //s1 will take all default value
StudentEmployee s1();
//s2 will take all supplied values
StudentEmployee s2 (50, "Jackie Chan", "D87654321", 10000000.99);
//s3 will take supplied age value, name, DSI and salary will take default values
StudentEmployee s3 (25);
//s4 will take supplied age and name value, DSI and salary will take default values
StudentEmployee s4 (35, "Jenny");
//s5 will take supplied age, name and DSI value, salary will take default value
StudentEmployee s5 (45, "Jack", "D11223344");
//s6 will take supplied age, name and salary value, DSI will take default value
StudentEmployee s6 (60, "James Bond", 65000.0);
//s7 will take the same value of s2
StudentEmployee s7=s2;
//the rest of the code
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.