Prerequisites for this project:

  • Be able to implement functions containing preconditions and postconditions
  • Completely understand the Supermarket Pricing Case Study in Chapter 5
  • Read sections 5.4 and 5.5 on testing and debugging

Using the Supermarket Case Study in chapter 5 as a model, write a program for a company that sells various products. This program will be a application that displays a summary of an order.

The program must ask the user for the number of products ordered, the number of products in stock, the price of the product, and whether there are special service charges. The basic Service charges for all products is $10.00 per product. If there are special service charges, the program should ask the user for the special service charges per product.

Refer to the test run in the below screenshot. Your output must look exactly the same as the output in the test run.

You will need to decide, based on the function definitions that follow, whether any parameters will be value or reference parameters. Only use reference parameters when necessary. Declare variables as necessary.

DO NOT USE GLOBAL VARIABLES. THE USE OF GLOBAL VARIABLES IN YOUR PROJECT WILL HAVE A SEVERE NEGATIVE IMPACT ON YOUR GRADE IN THIS PROJECT.

Your program must have the following 6 functions.

Important - All 6 functions must be void functions with the correct number and type of parameters. Your program must execute as long as the user wishes to enter another product

1. inputNumProductsOrdered - this function will validate the number of products ordered

  • do not accept values less than 1

2. inputNumProductsInStock - this function will validate the number of products in stock

  • do not accept values less than 0

3. inputProductPrice - this function will validate the product price

  • do not accept values less than 0

4. inputSpecialServiceCharge - this function will validate the special service charges

  • do not accept values less than 0

5. getProductInfo - Using the above functions, this function will ask the user for:

  • the number of products ordered
  • the number of products in stock
  • the price of the product
  • whether there are special service charges. The program should ask if there are special service charges and if there are, ask for the special service charges per product.

6. showProduct - this function will display:

  • the number of products ready to ship from current stock
  • the number of products on backorder if the number ordered is greater than what is in stock
  • subtotal of the portion ready to ship (number of products ready to ship times 100.00)
  • total service charges on the portion ready to ship
  • total of the order ready to ship

You must thoroughly document all functions that you create. In addition, all functions must contain preconditions and postconditions.

Test your program using the data in the sample dialog that follows. Your Test Run should look exactly like the one on the next page.

Don't forget to copy your output to the bottom of your .cpp file.

You must also include a separate document describing your approach to completing this project. Your document should include at least 3 or 4 paragraphs and should address:

  • Steps you took to understand and define the problem
  • Your analysis of the problem
  • How you went about designing the algorithms for your functions
  • Things that you considered when writing your code
  • Testing stratagies you may have used
    • Did you test each function separately?
    • Did you use stubs?
    • What debugging techniques did you use?

Test Run

How many products were ordered? 8
How many products are in stock? 10
What is the product's price? 100
Are special service charges required? (y or n): n

Order Summary
==================

Products ordered: 8
Ready to ship: 8

Subtotal: $ 800.00
Service Charges: $ 80.00
Total Due: $ 880.00

Do you wish to do another order? Y

How many products were ordered? 15
How many products are in stock? 10
What is the product's price? 100
Are special service charges required? (y or n): y
Enter the amount of any special charges: 5

Order Summary
==================

Products ordered: 15
Ready to ship: 10
On backorder: 5

Subtotal: $ 1000.00
Service Charges: $ 150.00
Total Due: $ 1150.00

Do you wish to do another order? Y

How many products were ordered? -2
The number of products ordered must be one or more. Please re-enter.
How many products were ordered? 2
How many products are in stock? 0
What is the product's price? 100
Are special service charges required? (y or n): y
Enter the amount of any special charges: -5
Special service charges must be zero or more. Please re-enter
Enter the amount of any special charges: 5

Order Summary
==================

Products ordered: 2
Ready to ship: 0
On backorder: 2

Subtotal: $ 0.00
Service Charges: $ 0.00
Total Due: $ 0.00

Do you wish to do another order? n

Supermarket Pricing

//Determines the retail price of an item according to
//the pricing policies of the Quick-Shop supermarket chain.
#include < iostream>

const double LOW_MARKUP = 0.05; //5%
const double HIGH_MARKUP = 0.10; //10%
const int THRESHOLD = 7; // Use HIGH_MARKUP if not expected
//to sell in 7 days or less.

void introduction();
//Postcondition: Description of program is written on the screen.

void getInput(double& cost, int& turnover);
//Precondition: User is ready to enter values correctly.
//Postcondition: The value of cost has been set to the
//wholesale cost of one tiem. The value of turnover has been
//set to the expected number of days until the item is sold.

double price(double cost, int turnover);
//Precondition: cost is the wholesale of one item.
//turnover is the expected number of days until sale of the item.
//Returns the retail price of the item.

void giveOutput(double cost, int turnover, double price);
//Precondition: cost is the wholesale cost of one item; turnover is the
//expected tie until sale of the item; price is the retail price of the item.
//Postcondition: The values of cost, turnover, and price have been
//written to the screen.

int main()
{
double wholesaleCost, retailPrice;
int shelfTime;
introduction();
getInput(wholesaleCost, shelfTime);
retailPrice = price(wholesaleCost, shelfTime);
giveOutput(wholesale, shelfTime, retailPrice);
return 0;
}

//Uses iostream;
void indtroduction()
{
using namespace std;
cout << "This program determines the retail price for\n"
<< "an item at a Quick-Shop supermarket store.\n";
}

//Uses iostream:
void getInput(double& cost, int& turnover)
{
using namespace std;
cout << "Enter the wholesale cost of item: $";
cin >> cost;
cout << "Enter the expected number of days until sold: ";
cin >> turnover;
}

//Uses iostream:
void giveOutput(double cost, int turnover, double price)
{
using namespace std;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "Wholesale cost = $" << cost << endl
<< "Expected time until sold = "
<< turnover << " days" << endl
<< "Retail price = $" << price << endl;
}

//Uses defined constants LOW_MARKUP, HIGH_MARKUP, and THRESHOLD:
double price(double cost, int turnover)
{
if(turnover <= THRESHOLD)
return (cost + (LOW_MARKUP * cost));
else
return (cost + (HIGH_MARKUP * cost));
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.