Question
I am having issues I am using the code below but I am getting to many errors please help! With Visual Studio Please. Create a
I am having issues I am using the code below but I am getting to many errors please help! With Visual Studio Please.
Create a class called Employee that includes three pieces of information as data members
A first name (type string), a last name (type string) and a monthly salary (type floating point).
Your class should have a constructor that initializes the three data members.
Provide a set and get functions for each data member.
Create two Employee objects and display each object's yearly salary.
Then give each Employee a 10% raise and display each Employee's yearly salary again
/*
* Program in C++
*/
#include
#include
using namespace std;
class Employee
{
private:
string firstName, lastName;
float monthlySalary;
public:
/*Constructor to initialize all three data members*/
Employee(string fName, string lName, float sal) : firstName(fName), lastName(lName), monthlySalary(sal){}
/*Get methods for each data members to get values of each data members*/
string getFirstName() { return firstName; }
string getLastName() { return lastName; }
float getMonthlySalary() { return monthlySalary; }
/*Set methods for each data members to change values of each data members*/
void setFirstName(string fName) { firstName = fName; }
void setLastName(string lName) { lastName = lName; }
void setMonthlySalary(float sal) { monthlySalary = sal; }
};
int main()
{
/*Creating two Employee objects*/
Employee e1("Tony", "Stark", 25000);
Employee e2("Bill", "Gates", 30000);
/*Printing yearly salary of both employees*/
cout << "Yearly salary of Mr. " << e1.getFirstName() << " " << e1.getLastName() << ": $" << e1.getMonthlySalary() * 12 << endl;
cout << "Yearly salary of Mr. " << e2.getFirstName() << " " << e2.getLastName() << ": $" << e2.getMonthlySalary() * 12 << endl;
/*Raising 10% salary of both employees*/
cout << "Giving both employees a 10% raise..." << endl;
float newSalary1 = e1.getMonthlySalary() + e1.getMonthlySalary() * 10 / 100;//New salary for employee 1
float newSalary2 = e2.getMonthlySalary() + e2.getMonthlySalary() * 10 / 100;//New salary for employee 2
/*Updating salary of both employees*/
e1.setMonthlySalary(newSalary1);
e2.setMonthlySalary(newSalary2);
/*Printing yearly salary of both employees*/
cout << "Yearly salary of Mr. " << e1.getFirstName() << " " << e1.getLastName() << ": $" << e1.getMonthlySalary() * 12 << endl;
cout << "Yearly salary of Mr. " << e2.getFirstName() << " " << e2.getLastName() << ": $" << e2.getMonthlySalary() * 12 << endl;
system("pause");//To pause console screen;
return 0;
}
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