1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
//Test Code
#include <iostream>
using namespace std;
// The required function inputAndValidate should be inserted here.
void inputAndValidate(string & descriptionP, int & shelfStayP, float & wholesalePriceP)
{
cin >> descriptionP >> shelfStayP;
do
{
cin >> wholesalePriceP;
}
while (wholesalePriceP <= 0);
}
void determinePrices(int shelfStayP, float wholesalePriceP,float & cashPriceP, float & creditPriceP)
{
if (shelfStayP <= 7)
cashPriceP = 1.1 * wholesalePriceP;
else cashPriceP = 1.15 * wholesalePriceP;
creditPriceP = 1.02 * cashPriceP;
}
void updateDifference(float cashPriceP, float creditPriceP, float totalOfDifferencesP)
{
totalOfDifferencesP = creditPriceP - cashPriceP;
}
// The required function totalOfDifferences must be inserted here
int main( )
{
string description;
int shelfStay;
float wholesalePrice, cashPrice, creditPrice, totalOfDifferences;
// initialise total
totalOfDifferences = 0;
inputAndValidate(description, shelfStay, wholesalePrice);
determinePrices(shelfStay, wholesalePrice, cashPrice, creditPrice);
updateDifference (cashPrice, creditPrice, totalOfDifferences);
cout.setf(ios::fixed);
cout.precision(2);
cout << description << " is expected to stay on the shelf for " << shelfStay << " days and has a wholesale price of R" << wholesalePrice << endl;
cout << " The cash price for " << description << " is R" << cashPrice << " and the wholesale price is R" << wholesalePrice << endl;
cout << "The total of the differences between the cash and credit" << " prices is now R " << totalOfDifferences << endl;
return 0;
}
| |