Tags: %TAGME{ tpaction="" web="KenyonCpp" tag="" }% view all tags

# Lab 1

### Requirements:

1. Starting with this lab, you must follow the guidelines on Program Style described in section 2.5 of the textbook. In particular, follow the style given in Display 2.16 (page 95) of the textbook. You will lose points if you don't. You must follow these guidelines in all future labs (including Lab1).
2. For Project 7, all decimal point numbers must be printed with 2 digits after the decimal point. (e.g. 2.50 instead of 2.5). See pages 55-57 of the textbook for this.

### Part I (40 pts)

An employee is paid at a rate of \$16.78 per hour for the first 40 hours worked in a week. Any hours over that are paid at the overtime rate of one and one half times that. From the worker’s gross pay, 6% is withheld for social security tax, 14% is withheld for federal income tax, 5% is withheld for state income tax, and \$10 per week is withheld for union dues. If the worker has three or more dependents, then an additional \$35 is withheld to cover the extra cost of health insurance beyond what the employer pays. Write a program that will read in the number of hours worked in a week and the number of dependents as input, and will then output the worker’s gross pay, each withholding amount, and the net take-home pay for the week. Write your program so that it allows the calculation to be repeated as often as the user wishes.

### Part II (60 pts)

Write a C++ program which takes a 4-digit number (integer) as input from the user and prints the number in reverse order. For example, if the number entered is 5678 then the output should be 8765. The program should repeat this until the user decides to quit.

You need to pay attention to the following:

2. Use meaningful identifiers
3. Don't take the input as a sequence of characters. Take it as a single integer. Also, construct the output as a single integer, as opposed to printing it digit by digit.
4. Your program should give a warning message if the number (value) is not a 4-digit number. For example, 0345 is not considered to be a 4-digit number.
5. Your program should not be case-sensitive for the user choice i.e. both Q and q are should be acceptable quit.
6. You may assume that when asked to enter a 4-digit number, the user enters a positive integer (as opposed to other kind of data, such as a character)
7. When the last digit (units) of the input is 0, the reverse is not a 4-digit number. So it is Ok to report the reverse as a 3-digit number in that case.
Here is a typical dialogue for this program:
```Enter a 4-digit number
134
This is not a 4-digit number: Enter a 4-digit number
1234
The reverse number is 4321
Enter Q to quit, enter any letter to continue  C
Enter a 4-digit number
9001
The reverse number is 1009
Enter Q to quit, enter any letter to continue
Q
Thanks for using this program, bye !...
```

### Important hint

• The integer % operator gives the remainder of a division of two values. For example: x = 11 % 3; results in x = 2;
• When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded. For example: x = 11 / 3; results in x = 3.
• If the number entered is n, what does n%10 give you? How about n/10?
Edit | Attach | Watch | Print version |  | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r3 - 2015-09-06 - JimSkon

 Home KenyonCpp Web View Edit Account
 Edit Attach
Copyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback