QUESTION 5: void FUNCTIONS WITH DIFFERENT TYPES AND NUMBERS OF PARAMETERS
Poppy is the manager of VeryVeryNiceCakes home industry that specialises in cakes. She gives two quotations to
every customer that places an order: one for delivering and the other for pick-up by the customer. The quotations
also depend on the sort of cake and the number of cakes. You have to write a C++ program to help Poppy with this.
The program is developed in three steps. You have to submit printouts for 5c only.
Question 5a: Two reference parameters
Write a void function inputAndValidate where the detail of one order are input and validated. The function
should have two reference parameters, namely a parameter storing the sort of cake and a parameter storing the
number of cakes. The sort has to be one of the following: chocolate, carrot, custard, fruit or coffee.
This parameter is thus of type string. The second parameter is of type int.
The first parameter has to be validated by using a do..while loop: the program should keep on displaying a
prompting message until the user enters one of chocolate, carrot, custard, fruit or coffee.
We give the main function below. Test your program to make sure that it works correctly but do not submit any
printouts.
// Assignment 2 Question 5a
#include
#include
using namespace std;
/
/ The required function inputAndValidate should be inserted here.
i
nt main( )
{
string sort;
int number;
inputAndValidate(sort, number);
cout << number << " " << sort << " cake(s). " << endl;
return 0;
}
Question 5b: Two value parameters and two reference parameters
The amounts are calculated as follows:
R80 for one fruit cake and R35 per cake for the other sorts of cake,
R100 delivery fee for the complete order if fewer than 10 cakes are ordered,
R8 per cake delivery fee if 10 or more cakes are ordered.
Now write a void function calculateAmounts that calculates two amounts – one amount that is due if the
client should pick up the order at the shop and another amount that is due if the order should be delivered. This
function has two value parameters supplying the sort of cake and the number of cakes to the function. Furthermore,
there are two reference parameters, namely the two amounts that should be calculated and be available to the main
function.
We give the main function below. You will see that we declare several global constants. You should use them in the
function that you write. Test your program but do not submit any printouts.
// Assignment 2 Question 5b
#include
#include
using namespace std;
c
onst int BASIC_PRICE = 35;
const int FRUIT_PRICE = 80;
const int DELIVER_1 = 100;
const int DELIVER_2 = 8;
/
/ The required functions inputAndValidate and calculateAmounts
// should be inserted here.
i
nt main( )
{
string sort;
int number, amountSelf, amountDeliver;
inputAndValidate(sort, number);
calculateAmounts(sort, number, amountSelf, amountDeliver);
cout << “If customer picks up the order: R ”
<< amountSelf << endl;
cout << “If order should be delivered: R ”
<< amountDeliver << endl;
return 0;
}
Question 5c: Final version
Declare another global constant NR_ORDERS and assign the value 7 to it. Now write a new main function
containing a for loop going from 1 to NR_ORDERS. The two functions written in 5a and 5b should be called inside
the loop and the two amounts should be displayed every time.
Run your program on the data below and submit printouts of the program and output.
chocolate
11
fruit
1
custart
custard
8
carrot
10
coffee
6
coffee
2
chocolate
9
