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" <

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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.
Transcribed Image Text:**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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY