Lab Assignment 4
Lab Assignment 4
NOTE: All programs that you write must have comments at the top with the program name, your
name, and a description of what the program will do.
1. Create a program called Lab4A that will calculate an employee’s pay for the week.
Ask the user for the employee’s pay rate and the total hours that the employee worked during
the week. (I recommend making the variables for these doubles.)
Follow the logic steps given below.
3. Write a program named Lab4C that will determine if a student is in elementary, middle, or high
school based on his grade.
Ask the user to input an integer grade level (1-12).
Add an if statement that checks for input failure when the user enters the grade. If
there’s an error, it should print an error message and exit the program. (This would be
for something like a letter being typed instead of a number.)
COSC 1436
Use if statements to determine which school the student will attend – elementary,
middle, or high school. Grades 1-5 will be in elementary, 6-8 will be in middle school
and 9-12 will be in high school.
Print your results in the following format:
Grade studentGrade goes to studentSchool
So if the user types 8, the output would be
Grade 8 goes to middle school
If they enter 10, it would be
Grade 10 goes to high school
And so on….
4. Write a program named Lab4D that will act as a calculator, allowing the user to type in an
equation and calculating the result.
a. Ask the user to enter 2 integers with a character between them, all separated by spaces.
The character should be +, -, *, /, or % (So you should have 2 int variables and 1 char
variable for these.)
b. Input the 2 numbers and the character operator.
c. Write a switch structure based on the char variable, that will calculate the result of the
mathematical operation on the numbers.
d. Print the whole equation with the result in the following format:
If the user types in 40 / 5, then the output should be: 40 / 5 = 8
(You have worked with output statements enough that you should be able to do this.)
Sample input/output below (These are just examples of what the user could type in.)
Input Output
27 + 15 27 + 15 = 42
46 / 5 46 / 5 = 9
10 - 2 10 - 2 = 8
55 % 2 55 % 2 = 1
Hint – You input 2 integers (perhaps num1 & num2) from the user, and you also get a char
value for the operator (perhaps we can call it op). Set up a switch statement based on op.
If op is ‘+’, then the answer is num1 + num2
If op is ‘-‘, then the answer is num1 – num2,
And so on…
After your switch statement print both numbers, the character operator and the answer in the
format shown.
(And if you still run into issues with it, you could always ask your professor for help.)