C++ Assignment: Shipping Crates and Storage Metrics

Thu Aug 14 2025
Updated: Fri Aug 15 2025
Facebook share linkTwitter/X share linkLinkedIn share linkReddit share linkReddit share link

Purpose:
Practice with input/output using <iomanip>, storing data in variables, and arithmetic in C++ with <cmath>.


Assignment

You are a software engineer for a transcontinental shipping company that ships crates across the ocean on large cargo ships. Your company needs you to write a program to figure out some metrics on both shipping crates that will be stored on the ships, and storage rooms that will store the crates. Specifically they need you to find the volume, surface area, and spatial diagonal length of the crates and storage rooms. They also need you to figure out how many crates can fit into the storage rooms.

Write a complete program that:

  1. Prompts the user to enter the dimensions of a shipping crate and reads in the dimensions and stores them into doubles. The dimensions you will need to get are:

    • Length of the storage shipping crate.
    • Width of the storage shipping crate.
    • Height of the storage shipping crate.
  2. Calculates the volume of the rectangular prism entered in (1). (See equation below)

  3. Calculates the surface area of the rectangular prism entered in (1). (See equation below)

  4. Calculates the diagonal of the rectangular prism entered in (1). (See equation below)

  5. Prompts the user to enter the dimensions of the storage space for shipping crates and reads in the dimensions and stores them into doubles. The dimensions you will need to get are:

    • Length of the storage space for the shipping crates.
    • Width of the storage space for the shipping crates.
    • Height of the storage space for the shipping crates.
  6. Calculates the volume of the rectangular prism entered in (5). (See equation below)

  7. Calculates the surface area of the rectangular prism entered in (5). (See equation below)

  8. Calculates the diagonal of the rectangular prism entered in (5). (See equation below)

  9. Finds out how many shipping crates can fit in the storage space. (See equation below)

  10. Outputs the answers from (2), (3), (4), (6), (7), (8), and (9) nicely using iomanip. See the Example Executions for example formatting.


Equations

Volume of a rectangular prism:

volume=whlvolume = w * h * l

Surface area of a rectangular prism:

surfaceArea=2(wl+hl+hw)surfaceArea = 2(w * l + h * l + h * w)

Space diagonal of a rectangular prism:

diagonal=(l2+w2+h2)diagonal = √(l^2 + w^2 + h^2)

How many shipping crates can fit in a storage space:

total=spaceL/crateLspaceW/crateWspaceH/crateHtotal = ⌊spaceL / crateL⌋ * ⌊spaceW / crateW⌋ * ⌊spaceH / crateH⌋

Example Program Interactions

An example of an interaction with your program is shown below, your output should match these examples exactly.

Example 1

Alexs-iMac:as3 alex$ g++ -Wall -pedantic as3.cpp Alexs-iMac:as3 alex$ ./a.out SHIPPING CRATE Enter length of the shipping crate 10 Enter width of the shipping crate 10 Enter height of the shipping crate 10 STORAGE SPACE Enter length of storage space 100 Enter width of storage space 100 Enter height of storage space 100 +-------+---------+--------+--------+------------+--------------+----------+ | TYPE | LENGTH | WIDTH | HEIGHT | VOLUME | SURFACE AREA | DIAGONAL | +-------+---------+--------+--------+------------+--------------+----------+ | Crate | 10.0 | 10.0 | 10.0 | 1000.0 | 600.0 | 17.3 | | Space | 100.0 | 100.0 | 100.0 | 1000000.0 | 60000.0 | 173.2 | +-------+---------+--------+--------+------------+--------------+----------+ 1000.0 crates can fit in the storage space.

Example 2

Alexs-iMac:as3 alex$ ./a.out SHIPPING CRATE Enter length of the shipping crate 7.7 Enter width of the shipping crate 2.4 Enter height of the shipping crate 4.3 STORAGE SPACE Enter length of storage space 90.5 Enter width of storage space 87.2 Enter height of storage space 40.44 +-------+---------+--------+--------+------------+--------------+----------+ | TYPE | LENGTH | WIDTH | HEIGHT | VOLUME | SURFACE AREA | DIAGONAL | +-------+---------+--------+--------+------------+--------------+----------+ | Crate | 7.7 | 2.4 | 4.3 | 79.5 | 123.8 | 9.1 | | Space | 90.5 | 87.2 | 40.4 | 319136.3 | 30155.6 | 132.0 | +-------+---------+--------+--------+------------+--------------+----------+ 3564.0 crates can fit in the storage space.

See CodeGrade for more examples.

Note: The line breaks after the inputs in the example output formatting above are the default ones C++’s cin and getline() automatically apply after reading an input from the user. CodeGrade supplies input in a different manner (Linux redirection) to programs so in CodeGrade's auto tests there will not be line breaks after the inputs.


Submission Instructions

  1. Save: Save your code as main.cpp. Do not ignore this step or save your file(s) with different names.

  2. Submit: Your program source code must be submitted via CodeGrade as a properly named .cpp file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.