Create a class called Employee that includes three data members: a first name (type string), a last name (type string), and monthly salary (type int). The class will have a constructor that initializes the three data members. Include the set and get member functions for each data member. If the monthly salary is not positive, the set function will set it to 0. Also include a member function that returns the yearly salary (i.e. twelve times the monthly salary). Write a test program that prompts the user to enter the first and last name of an employee as well as their monthly salary. The program will then output the yearly salary of the employee, give them a 10 percent raise, and output the yearly salary again.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
C++ Help me fix my code please! I'm missing something and can't figure it out. Code and error picture are below. Original question is in the pictures too.
#include <iostream>
using namespace std;
class Employee
{
public:
string first_name;
string last_name;
int monthly_sal;
int increment;
Employee()
{
first_name="";
last_name="";
monthly_sal=0;
increment=0;
}
void setFirst_Name(string first_name)
{
this->first_name=first_name;
}
void setLast_Name(string last_name)
{
this->last_name=last_name;
}
void setSal(int monthly_sal)
{
if(monthly_sal<0){
this->monthly_sal=0;
}
else{
this->monthly_sal=monthly_sal;
}
}
void setInc(int increment)
{
monthly_sal =monthly_sal+(monthly_sal*increment);
}
string getFirst_Name()
{
return first_name;
}
string getLast_Name()
{
return last_name;
}
int get_salary()
{
return monthly_sal;
}
int get_increment()
{
return increment;
}
int get_yearly_salary_before()
{
return 12*monthly_sal;
}
int get_yearly_salary_after()
{
return 12*(monthly_sal+(monthly_sal*increment));
}
};
int main()
{
Employee ob;
ob.increment=1000;
string first_name,last_name;
cout<<"Enter: the employee's first and last name: ";
cin>> first_name >> last_name;
cout<<"Enter: the employee's monthly salary: ";
cin >> ob.monthly_sal;
ob.setSal(ob.monthly_sal);
cout<< first_name << " " <<last_name <<"'s yearly salary before the raise was "<< ob.get_yearly_salary_before() <<endl;
cout<<first_name << " " << last_name <<"'s yearly salary after the raise is "<< ob.get_yearly_salary_after() <<endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images