Programming starts with three essentials—talking to the computer (input/output), remembering values (variables), and doing math (arithmetic). In this assignment you’ll read data, compute results, and report them clearly—the same pattern behind route estimators, budget calculators, sensor dashboards, and game stats.
These skills matter after college, too: back-end services parse requests and compute responses, data workflows turn messy numbers into decisions, and embedded/IoT code reads sensors and acts. Clear variable names, correct units/precision, and tidy output aren’t “just for class”—they’re professional habits.
In this assignment you will create a program for a traveling door to door door salesperson. The salesperson wants to sell doors at a 75% markup by the piece. When the salesperson purchases from their distributor they have to buy doors in bulk bundles of 100 (much too many for one person to buy at once). Whenever the salesperson orders more doors the quantity of bundles needed and bundle price fluctuates. For this assignment, write a program that can help the door to door door salesperson calculate how much they will need to charge per door. In order to have a fully functional program for the salesperson the program must:
Ask for the price of a bundle of doors, and read the price into a floating-point variable in main memory.
Ask for the quantity of door bundles wanted, and read the price into an integer variable in main memory.
Calculate the total amount of doors being purchased using the formula below, then save that value into an integer variable in main memory.
Calculate the cost of a single door from the distributor using the formula below, then save that value into a floating-point variable in main memory.
Calculate the total cost of the quantity wanted of bundles of doors input using the formula below, then save that value into a floating-point variable in main memory.
Calculate the sale price of a single door to the consumer at a 75% markup using the formula below, then save that value into a floating-point variable in main memory.
Calculate the sale price of all of the doors to the consumer at a 75% markup using the formula below, then save that value into a floating-point variable in main memory.
Calculate the profit on a single door 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:
BUNDLE_SIZE
= 100
MARKUP
= 0.75
The formula to calculate the total number of doors being purchased is:
The formula to calculate the cost of a single door is:
The formula to calculate total cost of the bundles of doors is:
The formula to calculate the sale price of a single door at a 75% markup is:
The formula to calculate the sale price of every door at a 75% markup is:
The formula to calculate the profit on a single door is:
The formula to calculate the total profit is:
An example of an interaction with your program is shown below. Your output must match this output exactly.
alex-imac24@alex as1 % g++ main.cpp alex-imac24@alex as1 % ./a.out How many door bundles are needed? 3 How much does each bundle cost? $1000.00 Bundle Quantity: 3 Bundle Cost: $1000 Total Doors Purchased: 300 Single Door Cost: $10 Total Cost: $3000 Single Door Sale Price: $17.5 Total Sale Price: $5250 Single Door Profit: $7.5 Total Profit: $2250
See CodeGrade for more examples.
Note: The line breaks after the inputs in the example output formatting above are the ones placed into the terminal by the user hitting enter
on their keyboard to input. CodeGrade does not enter values with a keyboard, but rather supplies input via 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.