CS304 ASSIGNMENT 3 SOLUTION SPRING 2021
Provide by VU Answer
Submit your assignment only in the .cpp format file.
Check Correct Code Result after assignment code
Assignment Code:
#include <iostream>
#include<string>
#include<windows.h>
using namespace std;
class Employee{
public:
string name;
int age;
void setname(string name){ this->name=name;}
void setage(int age){ this->age=age;}
string geter(){ return name;}
double calculatesalary();
void print();
};
class salariedEmployee:public Employee{
public:
double weeklysalary;
double calculateSalary(){ return weeklysalary;}
void print(){
cout<<""<<endl;
cout<<"----------Employee Details----------"<<endl;
cout<<""<<endl;
cout<<"Employee Name: "<<name<<endl;
cout<<"Employee Age: "<<age<<endl;
cout<<"Employee Salary: "<<weeklysalary<<endl;
}
};
class hourEmp:public Employee{
public:
double hours;
double wage;
double salary;
double calculateSalary(){
if(hours<=40){ salary=wage*hours; }
else{ salary = (40*wage) +((hours-40)*wage*1.5); }
return salary;
}
void print(){
cout<<""<<endl;
cout<<"----------Employee Details----------"<<endl;
cout<<""<<endl;
cout<<"Employee Name: "<<name<<endl;
cout<<"Employee Age: "<<age<<endl;
cout<<"Employee Salary: "<<salary<<endl;
}
};
int main()
{
int iterate,x=0,y=0;
system("Color 07");
// For Change text or background color use following code
// 1 Blue 9 Light Blue
// 2 Green 0 Black
// Provided by VUAnswer.com
// 3 Aqua A Light Green
// 4 Red B Light Aqua
// 5 Purple C Light Red
// 6 Yellow D Light Purple
// 7 White E Light Yellow
// 8 Gray F Bright White
cout<<"How many Employees data you want to enter?"<<endl;
cin>>iterate;
cout<<""<<endl;
salariedEmployee sE[iterate];
hourEmp hE[iterate];
char choice;
for(int i=0;i<iterate;i++){
cout<<"Enter choice: S for SalariedEmployee , H for hourlyEmployee"<<endl;
cin>>choice;
cout<<""<<endl;
if(choice=='S' || choice=='s'){
cout<<"Enter Name: "<<endl;
cin>>sE[x].name;
cin.ignore();
cout<<"Enter Age: "<<endl;
cin>>sE[x].age;
cout<<"Enter Salary: "<<endl;
cin>>sE[x].weeklysalary;
x++;
}
else if(choice=='H' || choice=='h'){
cout<<"Enter Name: "<<endl;
cin>>hE[y].name;
cout<<"Enter Age: "<<endl;
cin>>hE[y].age;
cout<<"Enter Hours:"<<endl;
cin>>hE[y].hours;
cout<<"Enter Wage: "<<endl;
cin>>hE[y].wage;
y++;
}
}
for(int i=0;i<x;i++){
sE[i].calculateSalary();
sE[i].print();
}
for(int i=0;i<y;i++){
hE[i].calculateSalary();
hE[i].print();
}
return 0;
}
CODE RESULT
PLEASE NOTE:
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before submitting copy-paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an assignment check your assignment requirement file.
If you need some help and question about files and solutions.
0 Comments