Figure 2.1

/* studentPay.cpp computes a student worker's pay,
*
* Input: A student's name, id number, hourly wage, hours worked.
* Precondition: hoursWorked >= 0.0 && hoursWorked <= 40 &&
* hourlyWage > 0.0 && idNumber > 0.
* Output: The student's name, id number, and pay.
*******************************************************************/
#include <iostream> // cin, cout, <<, >>
#include <string> // string
using namespace std;
int main()
{
const double HOURLY_WAGE = 6.75; // dollars/hour
cout << "\nEnter the student's name (L, F, MI): ";
string lastName, firstName;
char middleInitial;
cin >> lastName >> firstName >> middleInitial;
cout << "Enter their id number: ";
int idNumber;
cin >> idNumber;
cout << "Enter their hours this pay period: ";
double hours;
cin >> hours;
double pay = hours * HOURLY_WAGE;
cout << "\nName: "
<< firstName << ' ' << middleInitial << ". " << lastName
<< "\nId Number: " << idNumber
<< "\nPay: $" << pay << '\n';
}

 

Figure 2.1 Sample Runs

Enter the student's name (L, F, MI): VanderDoe Van V
Enter their id number: 12345
Enter their hours this pay period: 1
Name: Van V. VanderDoe
Id Number: 12345
Pay: $6.75

Enter the student's name (L, F, MI): Smith John Q
Enter their id number: 98765
Enter their hours this pay period: 10
Name: John Q. Smith
Id Number: 98765
Pay: $67.5

Enter the student's name (L, F, MI): FoneBone Fran F
Enter their id number: 33234
Enter their hours this pay period: 38.5
Name: Fran F. FoneBone
Id Number: 33234
Pay: $259.