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;
}
![Create a class called Employee that includes three data members: a first
name (type string), a last name (type string), and monthly salary (ty.pe 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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1c4b0a35-b7ae-4682-9b93-5e61724ed9d4%2F460f9cc4-e20d-4b45-b1c7-6e3d83509346%2Fk8pbqeq_processed.png&w=3840&q=75)
![Problems Detected:
The contents of your standard output is incorrect.
Given the following was entered from the keyboard:
John Smith
10000
you displayed:
Enter:-the-employee's-first-and·last-name: Enter:-the employee's-monthly salary:-John-Smith's•yearly-salary-before-the raise•was-1200
John Smith's yearly•salary-after•the raise-is 120120000
instead of:
Enter:•the employee's-first-and·last name: Enter:•the employee's-monthly•salary:-John Smith's-yearly salary•before the raise•was 1200
John•Smith's•yearly•salary•after•the•raise•is•132000J
Failed 2 out of 4 test runs.
Failed Test Run #1 -
The contents of your standard output is incorrect.
Interactive Session
Hide Invisibles
Highlight: None
Show Highlighted Only O
Expected Result:
Your Code's Actual Result:
Enter:John- Smithe
· the· employee's first·and -last name: Enter:100004
·the employee's monthly salary: John- Smith's yearly salary before the raise wa
John - Smith's.yearly salary·after the raise is 1320004
Enter:John - Smithe
· the employee's first and ·last name: · Enter:100004
·the employee's monthly salary: John- Smith's yearly salary before the raise wa
John - Smith's yearly salary after the raise·is 1201200004](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1c4b0a35-b7ae-4682-9b93-5e61724ed9d4%2F460f9cc4-e20d-4b45-b1c7-6e3d83509346%2F11n5ey_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)