DOC PREVIEW
CSUN COMP 106 - Homework Solutions

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Jacaranda (Engineering) 3333 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062College of Engineering and Computer ScienceComputer Science DepartmentComputer Science 106 Computing in Engineering and ScienceSpring 2006 Class number: 11672 Instructor: Larry CarettoEngineering Building Room 2303 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062May 2 homework solutions Comp 106, L. S. Caretto, Spring 2006 Page 3Homework Solutions – May 2, 2006Page 474, program 6 – Write a program that uses the following arrays: empId an array of seven long integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845, 4520125, 7895122, 8777541, 8451277, 1302850, and 7580489. hours: an array of seven intgers to hold the number of hours worked by each employee payRate an array of seven floats to hold each employee’s hourly pay rate wages: an array of seven floats to hold each employee’s gross wagesThe program should relate the information in each array through the subscripts. For example, the number of element 0 of the hours array should be the number ofhours worked by the employee whose identification number is stored in element 0of the empId array. The same employee’s pay rate would be stored in element 0 of the payRate array.The program should display each employee number and ask the user to enter thatemployee’s hours and pay rate. It should then calculate the gross wages for that employee (hours times pay rate), which should be stored in the wages array. After the data has been entered for all employees, the program should display each employee’s identification number and gross wages.Input validation: do not accept negative values for hours or numbers less than $6.00 for pay rate.#include <iostream>using namespace std;int main(){// Declare arrays stipulated in the problem// Use symbolic constants for array limit and minimum wage// Initialize employee ID array with data provided const double MINIMUIM_WAGE = 6; const int MAX_EMPLOYEES = 7; int empId[MAX_EMPLOYEES] = { 5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489 }; int hours[MAX_EMPLOYEES]; float payRate[MAX_EMPLOYEES], wages[MAX_EMPLOYEES];// Loop over all employees to get input on hours and pay rate// compute wages after valid data are entered for( int count = 0; count < MAX_EMPLOYEES; count++ ); {// Input and validation of hours worked data cout << “\n\nEnter the hours worked for employee ID “ << empId[count] << “: “; cin >> hours[count];May 2 homework solutions Comp 106, L. S. Caretto, Spring 2006 Page 4 while ( hours[count] < 0 ) { cout << “\nHours worked cannot be negative; reenter hours: “; cin >> hours[count]; }// Input and validation of pay rate data cout << “\n\nEnter the payRate for employee ID “ << empId[count] << “: $“; cin >> payRate[count]; while (payRate [count] < 0 ) { cout << “\nPay rate worked cannot be less than: “; << MINIMUM_WAGE << “\nReenter pay rate now.” cin >> payRate[count]; }// Data entry complete; compute wages and end loop wages[count] = payRate[count] * hours[count]; }// Print header for output cout << “\n\nList of employees and total wages.\n\n” << “ Employee ID Hours worked Pay Rate Wages\n” << fixed << setprecision(2);// Now print all employee data in one loop for( count = 0; count < MAX_EMPLOYEES; count++ ); { cout << setw(12) << empId[count] << setw(14) << hours[count] << setw(12) << payRate[count] << setw(9) << wages[count]; } return


View Full Document

CSUN COMP 106 - Homework Solutions

Download Homework Solutions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Homework Solutions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Homework Solutions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?