Question: Purpose: Practice ifelse statements, loops, and string object/to_string(). Part1: The transcontinental company you are working for has developed its services, and it is going to
Purpose: Practice ifelse statements, loops, and string object/to_string().
Part1:
The transcontinental company you are working for has developed its services, and it is going to ship crates across oceans to all five other continents. The price of cargo ship space to each destination continent is different. Table 1 illustrates the different prices per cubic foot. Therefore, the company needs a menu to choose a specific destination continent. You should use the iomanip library to make the menu alignment.
1- The first line of the menu prompts the user to select an individual continent, and it has six options, as follows:
Please select the destination continent:
Africa (Af/af)
Asia (As/as)
Australia (Au/au)
Europe (Eu/eu)
The Americas (Am/am)
Quit (Q/q)
2- Once the menu shows up, the user selects an option, and the program assigns the chosen option to a string variable and checks whether it is valid or not. If the user enters a valid value, output the destination continent's name plus a welcome message. For example, suppose the destination continent is Asia. In that case, the user should enter As or as (both capital and small form of the first letter is acceptable), and the program should output "Welcome to Asia cargo shipping program. " Please check out example 2 at the end of the assignment.
3- If the user enters Q or q, output a thank you message and quit your program. Please check out example 3.
4- If the user enters wrong values that are not available on the menu, output an error message and quit your program. Please check out example 1.
5- You will add some functionality to the program to help quote prices to customers. As it is mentioned, a transportation to each continent has a different cost. You can find the minCost, medCost, and the maxCost for each destination continent in the following table. There are three values in the table named minCost (crates with volume less than
40 ft3), medCost (crates with volume more than 40 ft3 and less than 80 ft3), and maxCost (crates with volume more than 80 ft3). The costs are per cubic foot.
Table 1: crates prices per cubic foot to different continents
| Continent | minCost | medCost | maxCost |
| Africa, Asia | $4.0 | $5.5 | $8 |
| Australia, Europe | $7.8 | $5.7 | $10 |
| The Americas | $2.5 | $3.5 | $6 |
6- Declare three double variables called maxCost, medCost and minCost in your program, and use the above table and the user selected option from the menu to assign correct values to them.
Part 2:
1- Once the destination continent is selected, your program prompts and asks the user how many crates should be sent? Then this number will be assigned to an integer variable called iterationNum.
If the entered value for the number of crates is not an integer, use a loop here to keep asking the user to enter a correct value.
2- The company has 10 cargo ships overall, and because of this limitation there is a goal to maximize the number of crates being sent by each cargo ship. So, the company designed some standard crates sizes. There are three types of crates (a, b, and c) with the following properties. The only data needed from the Table 2 is the Volume column. You need three global constants to use the Volume size of the different crates type in your program.
a_volume = 24.0 // the volume size of the crates type a
b_volume = 125.0 // the volume size of the crates type b
c_volume = 30.0 // the volume size of the crates type c
Table 2: Different crates type.
| Type | Length | Width | Height | Volume | Surface Area | Diagonal |
| a | 2.0 | 3.0 | 4.0 | 24.0(ft3) | 52(ft2) | 5.4 |
| b | 5.0 | 5.0 | 5.0 | 125.0(ft3) | 150(ft2) | 8.7 |
| c | 3.0 | 5.0 | 2.0 | 30.0 (ft3) | 62.0(ft2) | 6.2 |
3- The program starts to prompt the user iterationNum times. (use loops)
In each iteration, a message shows up and asks the user, What type of crate do you want to send? (a/b/c). The entered value will be assigned to a character variable called crtType.
If the user enters something that isnt a character, output an error message, and ask again. (you need a loop here to check).
Use a switch statement for checking the crtType variable. Cases for characters a, b, and c will be checked, and if there would be other cases that are not acceptable, an error shows up and the counter of the loop should not change.
You need three different integer variables called num_a, num_b, and num_c to keep track of different crates numbers. In each iteration, based on the entered crates type, one of these three variables is incremented.
4- Once all the crates types are clarified. The program should calculate the total volume of the crates. All you need to do in this step is to multiply the number of that crates type by its volume. For example, if the iterationNum would be 5 and there would be one type a, two type b, and two type c of crates. Then the total volume will be (2*125) +(2*30) + (24) = 334 (ft3).
5- Every cargo ship has 300 (ft3) amount of space. Based on the calculated total volume in (4) find out how many ships are required to send these crates to the destination.
Number of cargo ships = [total volume 300]
6- Based on the total volume from (4) and the minCost, medCost, and maxCost (from part 1) calculate the total cost. Remember that each cargo ship has a $200 fixed cost. Based on the volume of the crates one of the minCost, medCost, and maxCost will be selected as the variable cost. For example, if the volume will be more than 80 ft3, and the destination would be Asia then the variable costs will be the maxCost which is $8.
Total cost = Total volume * (variable costs) + Number of cargo ships * $200
7- If more than 10 cargo ships are needed for the crates, output an error, and terminate the program. Otherwise, output, in a nice format, the following values:
The number of crates type a.
The number of crates type b.
The number of crates type c.
The calculated total volume of the crates.
The required number of cargo ships.
The calculated total costs.
Compiling:
Compile your program using the command: g++ as5.cpp -Wall -pedantic
Example Executions:
Example 1:
| esmailza@LAPTOP-DBUH9AD3: Assignments $ g++ as5.cpp -Wall -pedantic esmailza@LAPTOP-DBUH9AD3: Assignments $ ./a.out Please select the destination continent: Africa (Af/af) Asia (As/as) Australia (Au/au) Europe (Eu/eu) The Americas (Am/am) Quit (Q/q) ag Error, invalid input. Please try again and select a correct value. |
Example 2:
| esmailza@LAPTOP-DBUH9AD3: Assignments $ g++ as5.cpp -Wall -pedantic esmailza@LAPTOP-DBUH9AD3: Assignments $ ./a.out Please select the destination continent: Africa (Af/af) Asia (As/as) Australia (Au/au) Europe (Eu/eu) The Americas (Am/am) Quit (Q/q) af Welcome to Africa cargo shipping program. |
Example 3:
| esmailza@LAPTOP-DBUH9AD3: Assignments $ g++ as5.cpp -Wall -pedantic esmailza@LAPTOP-DBUH9AD3: Assignments $ ./a.out Please select the destination continent: Africa (Af/af) Asia (As/as) Australia (Au/au) Europe (Eu/eu) The Americas (Am/am) Quit (Q/q) q Thank you for using this program. Goodbye! :) |
Example 4:
| esmailza@LAPTOP-DBUH9AD3: Assignments $ g++ as5.cpp -Wall -pedantic esmailza@LAPTOP-DBUH9AD3: Assignments $ ./a.out Please select the destination continent: Africa (Af/af) Asia (As/as) Australia (Au/au) Europe (Eu/eu) The Americas (Am/am) Quit (Q/q) as Welcome to Asia cargo shipping program. How many crates will be sent? d Enter a number please, how many crates do you want to send? ss Enter a number please, how many crates do you want to send?? 5 what type of crate do you want to send? (a/b/c) just the first character will be accepted. a what type of crate do you want to send? (a/b/c) just the first character will be accepted. 12 Error, the selected crate's type is not available please select a, b or c. what type of crate do you want to send? (a/b/c) just the first character will be accepted. a what type of crate do you want to send? (a/b/c) just the first character will be accepted. nn Error, the selected crate's type is not available please select a, b or c. what type of crate do you want to send? (a/b/c) just the first character will be accepted. |
| a what type of crate do you want to send? (a/b/c) just the first character will be accepted. b what type of crate do you want to send? (a/b/c) just the first character will be accepted. c +--------------+--------+ |# TYPE a | 3 | +--------------+--------+ |# TYPE b | 1 | +--------------+--------+ |# TYPE c | 1 | +--------------+--------+ |#Cargo Ships | 1 | +--------------+--------+ |Total Volume | 227.0 | +--------------+--------+ |Total Costs | 2016.0| +--------------+--------+ |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
