SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Defining Classes
Exercise:
Self-test Exercises
Question:6 | ISBN:9780321531346 | Edition: 7

Question

Write a definition for a structure type for records consisting of a person’s

wage rate, accrued vacation (which is some whole number of days), and

status (which is either hourly or salaried). Represent the status as one of

the two char values 'H' and 'S'. Call the type EmployeeRecord.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

C++ PROGRA CODE:

//Header section
#include <iostream>
using namespace std;

// Define the structure type EmployeeRecord
struct EmployeeRecord
{
    double wageRate;        // Wage rate of the employee
    int accruedVacation;    // Number of accrued vacation days
    char status;            // Status of the employee ('H' for hourly, 'S' for salaried)
};

int main()
{
    // Create an instance of EmployeeRecord
    EmployeeRecord employee1;

    // Assign values to the fields of the structure
    employee1.wageRate = 15.50;
    employee1.accruedVacation = 10;
    employee1.status = 'H';

    // Print the values of the fields
    cout << "Employee Record:" << endl;
    cout << "Wage Rate: $" << employee1.wageRate << endl;
    cout << "Accrued Vacation: " << employee1.accruedVacation << " days" << endl;
    cout << "Status: " << (employee1.status == 'H' ? "Hourly" : "Salaried") << endl;

    return 0;
}


// Define the structure type EmployeeRecord
struct EmployeeRecord
{
    double wageRate;        // Wage rate of the employee
    int accruedVacation;    // Number of accrued vacation days
    char status;            // Status of the employee ('H' for hourly, 'S' for salaried)
};

int main() {
    // Create an instance of EmployeeRecord
    EmployeeRecord employee1;

    // Assign values to the fields of the structure
    employee1.wageRate = 15.50;
    employee1.accruedVacation = 10;
    employee1.status = 'H';

    // Print the values of the fields
    cout << "Employee Record:" << endl;
    cout << "Wage Rate: $" << employee1.wageRate << endl;
    cout << "Accrued Vacation: " << employee1.accruedVacation << " days" << endl;
    cout << "Status: " << (employee1.status == 'H' ? "Hourly" : "Salaried") << endl;

    return 0;
}

 

OUTPUT OF THE PROGRAM CODE:

Employee Record:
Wage Rate: $15.5
Accrued Vacation: 10 days
Status: Hourly

 

0 0

Discussions

Post the discussion to improve the above solution.