Week 4 Lab Exercises PDF
Week 4 Lab Exercises PDF
College of Science
Department of Computer Science
COMP2002, Spring 2011
Week 4 Lab Exercises
Exercise 1
Write a C++ program to compute and display a person’s weekly salary as determined by the
following conditions: If the number of hours worked is less than or equal to 40, the person
receives RO 5/- per hour, otherwise the person receives RO 200/- plus RO 7.5/- for each hour
worked over 40 hours. The program should request the number of hours worked as input and
display the weekly salary as output with 3 digits after the decimal point.
Exercise 2
a) Write a C++ program that reads a number followed by one space and then a letter. If the
letter following the number is f, the program should treat the entered number as a
temperature in Fahrenheit, convert the number to the equivalent Celsius temperature and
print a suitable display message. If the letter following the number is c the program
should perform the opposite conversion (from Celsius to Fahrenheit). If the letter is
neither f nor c the program should print a message that the data entered is incorrect and
terminate. Use the following formulas for converting between Fahrenheit and Celsius:
5 9
Celsius ( Fahrenheit 32) and Fahrenheit Celsius 32
9 5
Use 2 digits after the decimal point when displaying the converted temperature.
c) Test the correctness of your program by comparing its results with results from hand
calculations.
d) Submit your source file named lab4_xxxxx.cpp on Moodle before the end of the lab
session (replacing xxxxx with your student ID).