C++ Assignment: Door to Door Salesman

Mon Jun 23 2025
Facebook share linkTwitter/X share linkLinkedIn share linkReddit share linkReddit share link

Introduction

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.

Task

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:

  1. Ask for the price of a bundle of doors, and read the price into a floating-point variable in main memory.

  2. Ask for the quantity of door bundles wanted, and read the price into an integer variable in main memory.

  3. Calculate the total amount of doors being purchased using the formula below, then save that value into an integer variable in main memory.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. Calculate the profit on a single door using the formula below, then save that value into a floating-point variable in main memory.

  9. Calculate the total profit for the purchase order using the formula below, then save that value into a floating-point variable in main memory.

  10. Output the values from the steps above in the format of the formatting example below.

Constants

Some constants should be used for this program:

BUNDLE_SIZE = 100 MARKUP = 0.75

Formulas

The formula to calculate the total number of doors being purchased is:

DOORST=BUNDLE_SIZEinput_bundle_qtyDOORS_T = BUNDLE\_SIZE * input\_bundle\_qty

The formula to calculate the cost of a single door is:

COSTS=input_bundle_cost/BUNDLE_SIZECOST_S = input\_bundle\_cost / BUNDLE\_SIZE

The formula to calculate total cost of the bundles of doors is:

COSTT=input_bundle_costinput_bundle_qtyCOST_T = input\_bundle\_cost * input\_bundle\_qty

The formula to calculate the sale price of a single door at a 75% markup is:

DOORSP=COSTS+COSTSMARKUPDOOR_{SP} = COST_S + COST_S * MARKUP

The formula to calculate the sale price of every door at a 75% markup is:

TOTALSP=DOORSPDOORSTTOTAL_{SP} = DOOR_{SP} * DOORS_T

The formula to calculate the profit on a single door is:

TOTALPSD=DOORSPCOSTSTOTAL_{PSD} = DOOR_{SP} - COST_S

The formula to calculate the total profit is:

TOTALP=TOTALPSDTOTAL_DOORSTOTAL_{P} = TOTAL_{PSD} * TOTAL\_DOORS

Example Output

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

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.