COSC1436 – fa LAB7 TILLE: User-defined Functions with reference parameters – Coffee

COSC1436 – fa LAB7

TILLE:

User-defined Functions with reference parameters – Coffee Shop

TIME TO COMPLETE

2 Weeks for class 16 weeks – 1 Week for class 8 weeks

LAB7 – PART1 REQUIREMENT

Use the word document to write the answers of the following questions:

QUESTION 1:

Suppose we have the following small program:

#include

using namespace std;

//prototype of user-defined function with reference parameters

void find (int& a, int& b, int c);

int main ()

{

int a, b, c;

a = 1;

b = 2;

c = 3;

//call function find

find (a, b, c);

cout << "first call: " << a << ", " << b << ", " << c << endl;

//call function find

find (a, b, c);

cout << "second call: " << a << ", " << b << ", " << c << endl;

//call function find

find (a, b, c);

cout << "third call: " << a << ", " << b << ", " << c << endl;

system(“pause”);

return 0;

}

//User defined function with reference parameters

void find(int& a, int& b, int c)

{

c = a + b;

b = c – 2;

a = c + 4;

}

QUESTION 2:

Consider the following function::

#include

#include

using namespace std;

//function with default parameter

void defaultParameterFunction(char ch=’A’, float fvar=10.21, int ivar=25) {

cout << "ch = " << ch << " fvar = " << fvar << " ivar= " << ivar << endl;

}

Which of the following 5 function calls is correct? If it is correct, what is the output?

int main() {

//1.

defaultParameterFunction(‘F’, 11.45, 11);

//2.

defaultParameterFunction(‘A’, 14.36);

//3.

defaultParameterFunction();

//4.

defaultParameterFunction(‘L’);

//5.

DefaultParameterFunction(“L”, 10.29, 42);

system(“pause”);

return 0;

}

HOW TO DO PART 2

Remember to do the lab with the following:

*If you need help about the C++ syntax to write the code, read the instruction in the folder “Skills Required”

*From now and on yourLastName will be changed to your last name

*Change James Smith to your full name

*write the file name as the first comment line at the top of program

*After running your program, take the picture of the output window as below from your program with your name on and paste the picture at the bottom of the document having pseudo-code to turn in

Step1:

Read the requirement; write in English the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab7_pseudoCode_yourLastName

(store pseudo-code and output pictures of both part 1 and part 2)

Step2:

Start Virtual Studio C++, create the project write the project name

For Part 2: FA2021_LAB7PART2_yourLastName

For Part 2: FA2021_CoffeeShopApplication_yourLastName.cpp

After adding the cpp file, you have an empty window coming up, type the following template of a C++ program in:

//File name should be written here as comment line

#include

using namespace std;

int main()

{

//add the code here below this line

…..

system(“pause”); //This will pause the output to read

return 0;

}

Step3:

Then follow the step by step in the pseudo-code, type the C++ code in after the line “//add the code here below this line”

Step4:

Compile and run the program

Step5:

Debug if there are any errors until compile successfully

LAB 7 – PART2 REQUIREMENT

Provide a C++ application to allow a Coffee Shop to do the following tasks. After finishing one task, redisplay the menu to allow users to select other tasks until users select EXIT to terminate the program.

FA2021_CoffeeShopApplication_Smith.cpp

SALE COFFEE – JAMES SMITH

Today 10/15/21

———————————————————————-

1.Sale coffee

2.Report total number of cups sold in the day

3.Report total amount of coffee in OZ sold in the day

4.Report total money sold in the day

0.EXIT

You must have 4 user-defined functions to perform 4 tasks and apply reference parameters in at least one user-defined function

When select 1, display the list of cup sizes and the price as below; then ask users to select a size and enter the number of cups.

FA2021_CoffeeShopApplication_Smith.cpp

SELECT CUP SIZE – JAMES SMITH

Today 10/15/21

—————————————

1.Small ( 8oz) – \$1.79

2.Medium (12oz) – \$2.59

3.Large (16oz) – \$3.99

0.DONE

-Display message and read number of cups on each selected cup size, then redisplay the menu of SELECT CUP SIZE to allow users to select other sizes until users select DONE

-Display the receipt with all requested cups of coffee in the following format:

Output as below:

FA2021_CoffeeShopApplication_Smith.cpp

SALE RECEIPT – JAMES SMITH

Today 10/15/21

——————————————-

SIZE NUMBER MONEY

SMALL (\$1.79) 2 3.58

MEDIUM (\$2.59) 1 2.59

LARGE (\$3.99) 1 3.99

——————————————-

Subtotal: 10.16

Tax (8.25%): 0.84

Total: 11.00

The output picture is:

TASK 2: Report total number of cups sold in the day

Display the total number of cups sold during the day in the different sizes in the following format:

Output as below:

FA2021_CoffeeShopApplication_Smith.cpp

REPORT NUMBER OF CUPS – JAMES SMITH

Today 10/15/21

——————————————

SMALL SIZE ( 8oz) 348 cups

MEDIUM SIZE (12oz) 224 cups

LARGE SIZE (16oz) 325 cups

TASK 3: Report total amount of coffee in OZ sold in the day

Calculate and Display the total coffee in oz sold during the day in different size in the following format:

Output as below:

FA2021_CoffeeShopApplication_Smith.cpp

REPORT COFFEE SOLD IN OZ DURING THE DAY – JAMES SMITH

Today 10/15/21

—————————————————–

SIZE NUMBER OF CUP COFFEE AMOUNT

SMALL ( 8oz): 348 2784

MEDIUM (12oz): 334 4008

LARGE (16oz): 325 5200

—————————————————–

TOTAL: 11992

TASK 4: Report total money sold in the day:

Calculate and Display the total money sold during the day in the following format:

Output as below:

FA2021_CoffeeShopApplication_Smith.cpp

REPORT MONEY SOLD DURING THE DAY – JAMES SMITH

Today 01/15/21

———————————————————–

SIZE UNIT PRICE NUMBER CUP AMOUNT MONEY

SMALL 1.79 348 622.92

MEDIUM 2.59 334 865.06

LARGE 3.99 325 879.55

———————————————————–

SUM: 2784.73

TAX: 229.74

TOTAL: 3014.47

HOW TO TURN IN THE LAB

You turn in the following files:

File: Pseudo-code and output pictures (part2)

FA2021_CoffeeShopApplication_yourLastName.cpp (part2)

FA2021_LAB7PART2_yourLastName.exe (part2)

IF YOU GET ANY PROBLEM TO SUBMIT FILE .class, YOU CAN SUBMIT ALL PROJECT INTO ONE FILE .zip or .rar

ITEMS

SCORES

TURN IN LAB ON TIME

3

Part1:

Question1

3

Question2

5

Part2:

Name of the files and submit all requested files

1

Pseudo-code – output pictures

1

1

Generate current day correct

1

Switch or IF statement to manage the selected tasks

1

User defined functions with reference parameters TASK1

2

3

2

Display the result as required format

3

Compile success with all requirement

3

Comment – file name as a comment line at the top of file

1

Total

30 points

Instructor: Liem Le – COSC1436 1