Lab 10A: Enums and Structs

  < Previous  Next >

Objectives:

In this lab, we will practice:

Assignment:

Design an algorithm that reads in three employee data values and stores those values into a struct. Then, display those values from the struct. Implement your algorithm in a new project (within your existing CodeLite workspace). Use the 2170 template for this and all CodeLite projects.
Use a struct to store the employee's: Use an enum to store the Role as one of the following three categories: Write a helper function that takes an enum as an argument and returns a string. Additionally, write a helper function that takes a string and returns an enum. Furthermore, write a getEmployeeData function that has a reference parameter to an employee struct. The function should prompt the user to enter employee data and store it in the struct. Finally, write a displayEmployee function that has a parameter of an employee struct. Place the definitions of the enum and the struct (and the functions) in a header file named employee.h

Examples

Your program should match the following output exactly: (user input in bold text)
Please enter the employee's first name: Olivia
You entered Olivia
Please enter the employee's role (admin, engineer or staff): admin
You entered admin
Please enter the employee's salary: 80000.00
You entered 80000.00
Employee Olivia (administration) is paid $80000.00
Please enter the employee's first name: Noah
You entered Noah
Please enter the employee's role (admin, engineer or staff): engineer
You entered engineer
Please enter the employee's salary: 60000.00
You entered 60000.00
Employee Noah (engineer) is paid $60000.00
Please enter the employee's first name: Valerio
You entered Valerio
Please enter the employee's role (admin, engineer or staff): staff
You entered staff
Please enter the employee's salary: 44332.21
You entered 44332.21
Employee Valerio (staff) is paid $44332.21

Submission

Submit your source code (.cpp and .h files) using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  lab10A  main.cpp  employee.h
To verify your submission, type the following in a terminal window:
handin  lab10A

Rubric:

Points  Item
------  --------------------------------------------------------------
10      Documentation
        Header comment block at the beginning of each file with:
        + Your full name
        + Date(s) code was written
        + Description
        Comments explaining the role of each variable and major section of code

40      Correctness
        Program solves the assigned problem using methods described in program description
        Program compiles without errors
        Program executes without crashing
        Program produces the correct output
------  --------------------------------------------------------------
50      Total

Notes

  1. If you want to match my output exactly, then run the following on ranger:
    g++ main.cpp -o lab10A
    ./lab10A < echo "/nfshome/hcarroll/public_html/2170/private/closedLabs/lab10A-stdinOlivia_admin_80000.00.txt"  &>  output.txt
    diff /nfshome/hcarroll/public_html/2170/private/closedLabs/lab10A-answerKeyOlivia_admin_80000.00.txt  output.txt
    g++ main.cpp -o lab10A
    ./lab10A < echo "/nfshome/hcarroll/public_html/2170/private/closedLabs/lab10A-stdinNoah_engineer_60000.00.txt"  &>  output.txt
    diff /nfshome/hcarroll/public_html/2170/private/closedLabs/lab10A-answerKeyNoah_engineer_60000.00.txt  output.txt
    g++ main.cpp -o lab10A
    ./lab10A < echo "/nfshome/hcarroll/public_html/2170/private/closedLabs/lab10A-stdinValerio_staff_44332.21.txt"  &>  output.txt
    diff /nfshome/hcarroll/public_html/2170/private/closedLabs/lab10A-answerKeyValerio_staff_44332.21.txt  output.txt