This problem set will introduce you to input/output, variables, and arithmetic in C++. In this problem set, you will read values into variables from the command line, use arithmetic to calculate values, and output the calculated values and read in values to the command line. Be sure to read this problem set thoroughly, especially the sections of Collaboration and the Hand-in Procedure.
In this assignment you will create a program for a traveling nail salesperson. The salesperson wants to sell nails at a 60% markup, in boxes of 100. When the salesperson purchases from their distributor they have to buy nails in bulk crates of 10,000 nails (much too many for one person to buy at once), of which the quantity needed and price fluctuates. For this assignment, write this program. In order to have a fully functional program for the salesperson the program must:
Ask for the price of bulk crates of nails, and read the price into a floating-point variable in main memory.
Ask for the quantity of bulk crates wanted, and read the price into an integer variable in main memory.
Calculate the total amount of nails being purchased using the formula below, then save that value into an integer variable in main memory.
Calculate how many boxes of 100 can be made using the formula below, then save that value into an integer variable in main memory.
Calculate the cost of a single nail from the distributor using the formula below, then save that value into a floating-point variable in main memory.
Calculate the cost of a single nail to the consumer at a 60% markup using the formula below, then save that value into a floating-point variable in main memory.
Calculate the profit on a single nail using the formula below, then save that value into a floating-point variable in main memory.
Calculate the cost of a box of nails from the distributor using the formula below, then save that value into a floating-point variable in main memory.
Calculate the cost of a box of nails to the consumer at a 60% markup using the formula below, then save that value into a floating-point variable in main memory.
Calculate the profit on a box of nails using the formula below, then save that value into a floating-point variable in main memory.
Calculate the total profit for the purchase order using the formula below, then save that value into a floating-point variable in main memory.
Output the values from the steps above in the format of the formatting example below.
Some constants should be used for this program:
BULK_CRATE_SIZE
= 10000
BOX_SIZE
= 100
MARKUP
= 1.6
The formula to calculate the total amount of nails purchased is:
The formula to calculate the total amount of boxes that can be made is:
The formula to calculate the cost of a single nail from the distributor is:
The formula to calculate the price a single nail will be sold for is:
The formula to calculate the profit on a single nail is:
The formula to calculate the cost of a box of nails from the distributor is:
The formula to calculate the price a single nail will be sold for is:
The formula to calculate the profit on a single nail is:
The formula to calculate the total profit for the purchase order is:
Input/Output should be displayed the following manner (matching the output exactly):
Enter today's bulk crate price: 500 Enter the quantity of bulk crates wanted: 10 Total quantity to order: 100000 Number of boxes of 100: 1000 Single nail cost: 0.05 Single nail sale price: 0.08 Single nail profit: 0.03 Box cost: 5 Box sale price: 8 Box profit: 3 Total profit: 3000
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.
main.cpp
. Do not ignore this step or save your file(s) with different names..cpp
file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.