C++ Assignment: Nails For Sale!

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

  1. Ask for the price of bulk crates of nails, and read the price into a floating-point variable in main memory.

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

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

  4. Calculate how many boxes of 100 can be made using the formula below, then save that value into an integer variable in main memory.

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

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

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

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

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

  10. Calculate the profit on a box of nails using the formula below, then save that value into a floating-point variable in main memory.

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

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

Constants

Some constants should be used for this program:

  1. BULK_CRATE_SIZE = 10000

  2. BOX_SIZE = 100

  3. MARKUP = 1.6

Formulas

The formula to calculate the total amount of nails purchased is:

TOTALN=BULK_CRATE_SIZEinput_bulk_crate_qtyTOTAL_N = BULK\_CRATE\_SIZE * input\_bulk\_crate\_qty

The formula to calculate the total amount of boxes that can be made is:

TOTALB=TOTALN/BOX_SIZETOTAL_B = TOTAL_N / BOX\_SIZE

The formula to calculate the cost of a single nail from the distributor is:

COSTSN=input_bulk_crate_cost/BULK_CRATE_SIZECOST_{SN} = input\_bulk\_crate\_cost / BULK\_CRATE\_SIZE

The formula to calculate the price a single nail will be sold for is:

SALE_PRICESN=COSTSNMARKUPSALE\_PRICE_{SN} = COST_{SN} * MARKUP

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

PROFITSN=SALE_PRICESNCOSTSNPROFIT_{SN} = SALE\_PRICE_{SN} - COST_{SN}

The formula to calculate the cost of a box of nails from the distributor is:

COSTB=COSTSNBOX_SIZECOST_B = COST_{SN} * BOX\_SIZE

The formula to calculate the price a single nail will be sold for is:

SALE_PRICEB=SALE_PRICESNBOX_SIZESALE\_PRICE_{B} = SALE\_PRICE_{SN} * BOX\_SIZE

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

PROFITB=SALE_PRICEBCOSTBPROFIT_B = SALE\_PRICE_{B} - COST_B

The formula to calculate the total profit for the purchase order is:

PROFITT=PROFITBTOTALBPROFIT_T = PROFIT_B * TOTAL_B

Example Output

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.

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.