Define and implement the overloaded constructors that support the following test
ID: 1812577 • 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
#include <iostream>
using namespace std;
class StudentEmployee
{
public:
int age;
char name[100];
char DSI[100];
float salary;
StudentEmployee();
StudentEmployee(int age1, char name1[100], char DSI1[100], float salary1 ) ;
StudentEmployee(int age1 ) ;
StudentEmployee(int age1 , char name1[100] ) ;
StudentEmployee(int age1, char name1[100], char DSI1[100] ) ;
StudentEmployee(int age1, char name1[100], float salary1 ) ;
};
StudentEmployee::StudentEmployee(void){
age = 0; // I have taken the following Default Values//
name = "Null";
DSI = "Null";
salary=0.0;
cout<<"Age:"<<age<<endl;
cout<<"Name:"<<name<<endl;
cout<<"DSI:"<<DSI<<endl;
cout<<"Salary"<<salary<<endl;
}
StudentEmployee::StudentEmployee(int age1, char name1[100], char DSI1[100], float salary1){
age = age1;
name = name1;
DSI = DSI1;
salary=salary1;
cout<<"Age:"<<age<<endl;
cout<<"Name:"<<name<<endl;
cout<<"DSI:"<<DSI<<endl;
cout<<"Salary"<<salary<<endl;
}
StudentEmployee::StudentEmployee(int age1){
age = age1;
name = "Null";
DSI = "Null";
salary=0.0;
cout<<"Age:"<<age<<endl;
cout<<"Name:"<<name<<endl;
cout<<"DSI:"<<DSI<<endl;
cout<<"Salary"<<salary<<endl;
}
StudentEmployee::StudentEmployee(int age1, char name1[100]){
age = age1;
name = name1;
DSI = "Null";
salary=0.0;
cout<<"Age:"<<age<<endl;
cout<<"Name:"<<name<<endl;
cout<<"DSI:"<<DSI<<endl;
cout<<"Salary"<<salary<<endl;
}
StudentEmployee::StudentEmployee(int age1, char name1[100], char DSI1[100], float salary1){
age = age1;
name = name1;
DSI = DSI1;
salary=0.0;
cout<<"Age:"<<age<<endl;
cout<<"Name:"<<name<<endl;
cout<<"DSI:"<<DSI<<endl;
cout<<"Salary"<<salary<<endl;
}
StudentEmployee::StudentEmployee(int age1, char name1[100], float salary1){
age = age1;
name = name1;
DSI = "Null";
salary=salary1;
cout<<"Age:"<<age<<endl;
cout<<"Name:"<<name<<endl;
cout<<"DSI:"<<DSI<<endl;
cout<<"Salary"<<salary<<endl;
}
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;
cout<<"Age:"<<s7.age<<endl;
cout<<"Name:"<<s7.name<<endl;
cout<<"DSI:"<<s7.DSI<<endl;
cout<<"Salary"<<s7.salary<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.