this question using C++, please In this assignment, you will practice using the switch statement inside of a while loop. The program you need to write is an interactive calculator for loading a light-duty electric truck. This truck moves equipment between warehouses, with each item restricted to 50 pounds to 1000 pounds. If the user attempts to add items to the load which weighs outside this range, write code to bring up an item rejection message and do not add that item to load. The maximum load that the truck can safely carry weighs 2000 pounds, so you will need to write code that enforces the limit. To ensure that your algorithm and implementation worked correctly, test the program and make sure that works up to and including the maximum load.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question

this question using C++, please

In this assignment, you will practice using the switch statement inside of a while loop. The program you need to write is an interactive calculator for loading a light-duty electric truck. This truck moves equipment between warehouses, with each item restricted to 50 pounds to 1000 pounds. If the user attempts to add items to the load which weighs outside this range, write code to bring up an item rejection message and do not add that item to load. The maximum load that the truck can safely carry weighs 2000 pounds, so you will need to write code that enforces the limit. To ensure that your algorithm and implementation worked correctly, test the program and make sure that works up to and including the maximum load.

 

Program requirements:

Use the switch statement inside of a while loop, as well as any other control structures such as if-else.

Prompt for a command.

There are four valid commands, ‘a’, ‘r’, ‘i’, and ‘e’ which are iteratively displayed. The output prompt should look like a menu:

Truck load calculator menu

( a ) Add an item to the load.

( r ) Display remaining load capacity.

( i ) Display number of items loaded.

( e ) Exit program.

 

Output results.

Option ‘a’: Get an integer representing the weight of the item in pounds. Attempting to add items to the load which are not between 50 pounds and 1000 pounds will bring up an item rejection message and go back to the menu (i.e., do not try to make another input loop in order to force the user to type in a valid value). The user also will get a rejection message if a valid weighted item would put the load over 2000 pounds – in this case the program needs to NOT add the weight to the load, NOT increase the item count, and go back to the menu. Points will be marked down if the number of items loaded is incremented during these error conditions. For valid weights add the item to the load, increment the number of items loaded, and display the resulting current weight of the load in pounds.

Option ‘r’: Display the remaining load capacity in pounds followed by the units (e.g., “270 pounds ”).

Option ‘i’: Display the number of items loaded.

Option ‘e’: Exit the program.

All other input: Display a friendly message indicating that the selected input command was invalid.

 

Program template:

Copy the code below and fill in the blanks. If you like extend these comments listing all variables in the program.

/*CS 161 Assignment 4

  Filename: a04.cpp

  Author:   ___

  Date:     ___

  Summary:  (describe the program’s purpose, and then describe how the input is transformed into the output)

 

Variables (data type, name, purpose):

    ___

 

Equations (include logic equations!):

    ___

*/

Expert Solution
Step 1

Computer Science homework question answer, step 1, image 1

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning