Question

In: Computer Science

C++ Programming Enum - Structure - Array You are asked to develop software for HR department...

C++ Programming

Enum - Structure - Array

You are asked to develop software for HR department to calculate employee’s weekly salary. The program should contain the following information about a student by declaring a struct:

Name (string of characters)

       Employee ID (string of characters)

       Level (ENGINEER, MANGER, DIRECTOR)

       Hourly Rate (floating-point number)

       Working Hours (floating-point number)

       Weekly Salary (floating-point number)

Your program will read an employee data and print the information of employee’s Name, Employee ID, level, weekly salary, and gender. Program will perform to calculate each employee’s weekly salary and display all employee’s data. The program will be terminated when users enter “N” to discontinue entering information.

The calculation formula:

  1. If employee is an engineer, working hours is less or equal 40 hours, his/her weekly pay will be hourly rate * working hours. If working hours is over 40 hours, the salary will be paid over time pay.

             Over time pay = hourly rate * (working hours - 40) * 1.15.

  1. If employee is a manger, working hours is less or equal 40 hours, his/her weekly pay will be hourly rate * working hours. If working hours is over 40 hours, the salary will be paid over time pay.

             Over time pay = hourly rate * (working hours - 40) * 1.20

  1. If employee is a director, working hours is less or equal 40 hours, his/her weekly pay will be hourly rate * working hours. If working hours is over 40 hours, the salary will be paid over time pay.

             Over time pay = hourly rate * (working hours - 40) * 1.3.

Test Data:

Name

Employee ID

Level

Hourly Rate

Working hours

Cindy

D001

Engineer

$30.57

40

Jeff

D002

Manager

$36.25

48

Tom

D003

Director

$40.05

42

  

Solutions

Expert Solution

Program screenshots:

Sample output:

Code to copy:

// Include the required header files.

#include<iostream>

// Use the standard namespace.

using namespace std;

// Create an enum to store the levels.

enum Level {ENGINEER, MANAGER, DIRECTOR};

// Create a structure to store the employee's data.

struct employee

{

    // Create string of characters to store the

    // name and id of the employee.

    char Name[25];

    char emp_id[10];

    char gender;

    // Declare an enum to store the level.

    Level level;

    // Declare the required floating-point variables.

    float hourly_rate;

    float working_hours;

    float weekly_salary;

};

// Define the main() function.

int main()

{

    // Declare the required variables.

    char choice = 'Y';

    float overtime;

    string level;

    employee emp;

    // Start the loop to store the user input.

    while(choice == 'Y')

    {

        // Prompt the user to enter the values.

        cout << "Enter the name of the employee: ";

        cin >> emp.Name;

        cout << "Enter the ID of the employee: ";

        cin >> emp.emp_id;

        cout << "Enter the gender of the employee (M/F): ";

        cin >> emp.gender;

        cout << "Enter the level of the employee: ";

        cin >> level;

        // Check the user input and set the enum value

        // for the employee.

        if(level == "Engineer" || level == "engineer")

        {

            emp.level = ENGINEER;

        }

        else if(level == "Manager" || level == "manager")

        {

            emp.level = MANAGER;

        }

        else if(level == "Director" || level == "director")

        {

            emp.level = DIRECTOR;

        }

        else

        {

            cout << "Error: Invalid input!" << endl;

            return 0;

        }

        // Prompt the user to enter the values.

        cout << "Enter the hourly rate of the employee: ";

        cin >> emp.hourly_rate;

        cout << "Enter the working hours of the employee: ";

        cin >> emp.working_hours;

        // Display the details of the employee.

        cout << endl << "The employee's data is as follows: " << endl;

        cout << endl << "Name: " << emp.Name << endl;

        cout << "Employee ID: " << emp.emp_id << endl;

        cout << "Level: ";

        

        // Use the switch condition to check and print

        // the value of the enum level.

        switch (emp.level)

        {

            case ENGINEER:

                cout << "Engineer" << endl;

                break;

            case MANAGER:

                cout << "Manager" << endl;

                break;

            case DIRECTOR:

                cout << "Director" << endl;

                break;

        }

        // Set the overtime to 0.

        overtime = 0;

        // Check if the number of working hours is

        // greater than 40 or not.

        if(emp.working_hours > 40)

        {

            // Calculate the salary for 40 hours.

            emp.weekly_salary = emp.hourly_rate * 40;

            // Use the switch condition to check and compute

            // the overtime pays.

            switch(emp.level)

            {

            case ENGINEER:

                overtime = emp.hourly_rate * (emp.working_hours - 40) * 1.15;

                break;

            case MANAGER:

                overtime = emp.hourly_rate * (emp.working_hours - 40) * 1.20;

                break;

            case DIRECTOR:

                overtime = emp.hourly_rate * (emp.working_hours - 40) * 1.3;

                break;

            }

            // Add the overtime pay in the weekly salary.

            emp.weekly_salary += overtime;

        }

        // Compute the weekly salary for working hours

        // less than or equal to 40.

        else

        {

            emp.weekly_salary = emp.hourly_rate * emp.working_hours;

        }

        // Display the details.

        cout << "Weekly salary: $" << emp.weekly_salary << endl;

        cout << "Gender: " << emp.gender << endl << endl;

        // Prompt the user to enter the choice.

        cout << "Do you want to add another employee? (Y/N): ";

        cin >> choice;

        

        cout << endl;

    }

    // Return 0 and exit the program.

    return 0;

}


Related Solutions

Explain the difference between array and structure based on their usage in C++ programming. Declare a...
Explain the difference between array and structure based on their usage in C++ programming. Declare a structure called studentScore which contains name of student, registration number of students, course code and marks. Declare structure variable named studentCS680 based on the structure in (b) to store fifty (50) students’ data. Write a program that prompts a user to enter data for 50 students in a structure variable declared in (b) and calculate the average mark.
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
C Programming Debug -> error: expected expression before 'score' typedef enum LetterGrade {     A =...
C Programming Debug -> error: expected expression before 'score' typedef enum LetterGrade {     A = 4,     B = 3,     C = 2,     D = 1,     F = 0 } score; score getLetterGradeFromAverage(const double avg) {     if (avg >= 90)         return score::A;         // error here     else if (avg >= 80)         return score::B;        // error here     else if (avg >= 70)         return score::C;       // error here     else if (avg >=...
You are a software development employee at a startup company. Your HR department has tasked the...
You are a software development employee at a startup company. Your HR department has tasked the IT department with developing a simple application (Windows Form Application) to load and display employee records. Your application will need to do the following: Create an Employee Class with the following properties: First Name Last Name Street Address City State Zip Create a sub class for Managers which inherits from the Employee Class. The Manager class will have the following additional properties: Cost Center...
IHE Profiles If you are working in the IS department and were asked to develop interoperability...
IHE Profiles If you are working in the IS department and were asked to develop interoperability between two applications, why might you want to use IHE profiles? Have you had any situations where you had been asked to help with an interoperability initiative and wondered how you would start - this can be a situation in healthcare or not, IT or not. How did you get started?
The head of the accounting department at a major software manufacturer has asked you to put...
The head of the accounting department at a major software manufacturer has asked you to put together a pro forma statement of the company's value under several possible growth scenarios and the assumption that the company’s many divisions will remain a single entity forever. The manager is concerned that, despite the fact that the firm’s competitors are comparatively small, collectively their annual revenue growth has exceeded 50 percent over each of the last five years. She has requested that the...
The head of the accounting department at a major software manufacturer has asked you to put...
The head of the accounting department at a major software manufacturer has asked you to put together a pro forma statement of the company's value under several possible growth scenarios and the assumption that the company’s many divisions will remain a single entity forever. The manager is concerned that, despite the fact that the firm’s competitors are comparatively small, collectively their annual revenue growth has exceeded 50 percent over each of the last five years. She has requested that the...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
The purpose of this C++ programming assignment is to practice using an array. This problem is...
The purpose of this C++ programming assignment is to practice using an array. This problem is selected from the online contest problem archive, which is used mostly by college students worldwide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest. For your convenience, I copied the description of the problem below with my note on the I/O and a sample executable. Background The world-known gangster Vito Deadstone...
c++ Redo Programming Exercise 14 by first sorting the array before determining the array elements that...
c++ Redo Programming Exercise 14 by first sorting the array before determining the array elements that are the sum of two other elements. Use a selection sort algorithm, discussed in this chapter to sort the array. Instructions and code for Programming Exercise 14 have been included for your convenience. Exercise 14 Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT