You are on page 1of 2

Adama Science and Technology University

School of Electrical Engineering and Computing


Department of Computer Science and Engineering

Worksheet 5
1. An employee is paid at a rate of $16.78 per hour for regular 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 $10 per head 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 that will then output the worker’s gross pay, total withholding amount, and the net
take-home pay for the week.
2. Write a program a two digit hexadecimal number and print its decimal equivalent. Accept
upper letters for values from 10 to 15. An invalid entry should be handled appropriately.
3. Write a program to compute the real roots of a quadratic equation (ax 2 + bx + c = 0). Your
program should consider all possible cases.
4. Write a program that implements a simple calculator that performs the basic operations ( +,
-,*, /, and %). Your program should properly handle division by zero.
5. Write a program calculate the parking fare for customer who park their cars in a parking lot
when the following information is given.
 A character showing the type of the vehicle: ‘C’ for car, ‘B’ for bus, ‘T’ for truck.
 The time the vehicle entered the lot, entered as hour:minute.
 The time the vehicle left the lot, entered as hour:minute.
 To encourage people to park for a short period of time, the management uses two
different rates for each type of vehicle, as shown in the following table.

Type First rate Second rate


Car $0.00/hr, first 3 hr $1.50/hr, after the first 3 hr
Truck $1.00/hr, first 2 hr $2.30/hr, after the first 2 hr
Bus $2.00/hr, for first hr $3.70/hr, after the first hr
The output format is shown below
PARKING LOT CHARGE
Type of vehicle: Car or Bus or Truck
TME – IN XX:XX
TIME – OUT XX:XX
_________
PARKING TIME XX:XX
ROUNDED TOTAL XX
_________
TOTAL CHARGE $XX.XX

6. Write a program that reads three numbers and determines whether they could represent the
sides of a triangle.
7. Write a program that accepts a long integer and display the reversed number. For instance, if
user enters 57342, it displays 24375.
8. Write a program that calculates the greatest common divisor (GCD) and the least common
multiple (LCM) of two given numbers.
9. Write a program that establishes all the primes in the first positive integers.
10. Write a program that calculates the square root of a number. Assume number is double type.

1|Page
Adama Science and Technology University
School of Electrical Engineering and Computing
Department of Computer Science and Engineering

11. Write a program that accepts a sequence of character and determines whether or not the
sequence of characters represent a valid integer. If it is a valid integer, the program has to
display the square of the number. If not, the program displays appropriate message.
12. This program is a simple guessing game. The computer is to generate a random number
between one and 20. The user is given up to five tries to guess the exact number. After each
guess, the computer is to tell the user if the guessed number is greater than, less than, or
equal to the random number. If it is equal, no more guesses should be made. If the user hasn’t
guessed the number after five tries, the program should display the number with a message
that the user should know it by now and then terminate the game.
13. Write a program that counts the number of words in a text. The text is to be entered as a
sequence of characters. Use enter key as the end of the text.
14. A sequence of characters is encrypted as follows: Each character is replaced by the character
whose ASCII is the ASCII of the character plus 64 modulo 256. Then swap the even index
character with the odd index character.
a. Write a program that encrypt and displays a data encrypted by the above rule.
b. Write a program that decrypt and displays a data encrypted by the above rule.
15. Write a program that prints Pascal’s triangle of binomial coefficients for a given height
information where the height is defined as the number of output lines.
1
11
121
1331
14641
1 5 10 10 5 1
16. Write a separate program to generate each of the following
a) 1 b) 1 2 3 c) 12345
12 456 2345
123 789 345
1234 45
12345 5

d) 1 2 3 4 5 e) 543212345 f) 5
1234 5432345 454
123 54345 34543
12 545 2345432
1 5 123454321
545 2345432
54345 34543
5432345 454
543212345 5
g) ****** h) a i) abcdefg
***** ab abcdef
**** abc abcde
*** abcd abcd
** abcde abc
** abcdef ab
* abcdefg a

2|Page

You might also like