Help me correct my C++ code please! Pictures included. My current code with the error picture; #include using namespace std; class Employee { public: string first_name; string last_name; int monthly_sal; Employee() { first_name=""; last_name=""; monthly_sal=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; this->monthly_sal=monthly_sal; } string getFirst_Name() { return first_name; } string getLast_Name() { return last_name; } int get_salary() { return monthly_sal; } int get_yearly_salary() { return 12*monthly_sal; } }; int main() { Employee ob; string first_name,last_name; int monthly_sal; cout<<"Enter: the employee's first and last name: "; cin>> last_name; cout<<"Enter: the employee's monthly salary: "; cin >> monthly_sal; cout<<"salary before the raise was 0" <
Help me correct my C++ code please! Pictures included. My current code with the error picture;
#include <iostream>
using namespace std;
class Employee
{
public:
string first_name;
string last_name;
int monthly_sal;
Employee()
{
first_name="";
last_name="";
monthly_sal=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;
this->monthly_sal=monthly_sal;
}
string getFirst_Name()
{
return first_name;
}
string getLast_Name()
{
return last_name;
}
int get_salary()
{
return monthly_sal;
}
int get_yearly_salary()
{
return 12*monthly_sal;
}
};
int main()
{
Employee ob;
string first_name,last_name;
int monthly_sal;
cout<<"Enter: the employee's first and last name: ";
cin>> last_name;
cout<<"Enter: the employee's monthly salary: ";
cin >> monthly_sal;
cout<<"salary before the raise was 0" <<endl;
cout<<"yearly salary after the raise is 0" <<endl;
return 0;
}
![**Problem Analysis**
The image illustrates an error encountered during a coding test concerning standard output discrepancies. Here's a detailed breakdown:
**Issue Details:**
- **Input Given:**
- First and Last Name: John Doe
- Monthly Salary: -23
- **Displayed Output (Incorrect):**
- "Enter the employee's first and last name: Enter the employee's monthly salary: salary before the raise was 0 John Doe's yearly salary after the raise is 0."
- **Expected Output:**
- "Enter the employee's first and last name: Enter the employee's monthly salary: John Doe's yearly salary before the raise was 0 John Doe's yearly salary after the raise is 0."
The main issue seems to involve incorrect handling of salary calculations and output formatting, possibly due to negative or zero values influencing the printed results.
**Failed Test Run #1 Details:**
- **Input for Test #1:**
- First and Last Name: John Smith
- Monthly Salary: 10,000
- **Expected Behavior:**
- Enter: John Smith
- Enter the employee's first and last name: Enter: 10000
- The employee's monthly salary: John Smith's yearly salary before the raise was
- John Smith's yearly salary after the raise is 132000
- **Actual Output (Incorrect):**
- Enter: John Smith
- The employee's first and last name: Enter: 10000
- The employee's monthly salary is salary before the raise was 0
- Yearly salary after the raise is 0
The problem in the test run suggests that the salary calculations are incorrect, likely because the input monthly salary is not being processed correctly into a yearly salary.
**Conclusion:**
The error lies in the mismatched output versus the expected results due to likely miscalculations of salary when dealing with negative or zero salary inputs.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1c4b0a35-b7ae-4682-9b93-5e61724ed9d4%2F000d778c-2f2b-4489-b824-2f3904edc0df%2Fxddrol_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 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)