Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program named Lab6A that will determine if a student is in elementary, middle or high school based on his grade. Ask the user

  1. Write a program named Lab6A that will determine if a student is in elementary, middle or high school based on his grade.
  • Ask the user to input a grade level (1-12), and then use a switch statement 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.
  • 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 could be due to a letter being typed instead of a number.)
  • Use a switch statement to determine the student's school, and print your results in the following format:

Grade studentGradegoes 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....

2. Write a program named Lab6B that asks the user for three different numbers in any order. It should then print the numbers in ascending order. Test your program with all of the following test cases and make sure it prints them correctly. (You have no idea what order the numbers will be entered in, so you will probably need to have some if and else if statements to try different options.)

  1. 1 2 3
  2. 1 3 2
  3. 2 3 1
  4. 2 1 3
  5. 3 2 1
  6. 3 1 2

3. Write a program named Lab6C that will act as a calculator, allowing the user to type in an equation and calculating the result.

  1. Ask the user to enter 2 integers with a character between them, all separated by spaces. The character should be +, -, *, /, or %
  2. Input the 2 numbers and the character oper.(oper will be the operator, but we can't use operator as a variable name because it's a reserved word.)
  3. Write a switch statement based on oper, that will perform the mathematical operation on the numbers.
  4. 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.)

Here are some examples of what the program will print with different inputs from the user.

If the user types this The program will print this
27 + 15 27 + 15 = 42
46 / 5 46 / 5 = 9
10 - 2 10 - 2 = 8
55 % 2 55 % 2 = 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions