LAB 05B - Pass by Reference

Concepts

To learn what it means to pass a variable by reference, as well as when to pass by reference.

Pass by Reference Practice

In this lab you will learn how to pass a variable into a function by reference. You'll create a restaurant simulator, and then be challenged into determining the difference between passing a variable's address as opposed to its contents.

To get started, create yourself an empty project and main.cpp file.

Instructions

In your restaurant simulator, you'll have a menu that consists of one food item and one drink item. Two items doesn't sound like much, but both are amazingly yummy so the restaurant is quite popular. Of course, as the restaurant owner, you want to ensure a customer's bill is updated properly for each food item purchased.

You can decide on the two menu items your restaurant serves, as well as set a reasonable price for each. You will also need two functions written for each item you sell, one for finding what the new bill total would be if a customer were to make a purchase, and one for actually altering your customer's bill.

When a customer walks into your restaurant, your program should be executed. The program should show the menu of your items as well as the prices for each. For example, your program might have:

----------------------------------------------------------
Welcome to the restaurant of CSM!
We offer the following items:
    [1] Veggie Hamburger:    4.99
    [2] Soft Drink:                  1.99
----------------------------------------------------------

Each time your customer asks for an item, you need to display the current bill, show what the bill would be after the purchase, and then ask if he/she would like to proceed with buying the item. An example output is as follows:

-------------------------------------------------------------------------
What would you like to order? (Press [0] to leave)
1

Your current tab is $6.98
If you were to buy a Veggie Hamburger, your tab would become $11.97
Would you like to purchase it? ([1] = yes, [2] = no)
1
You've successfully purchased a Veggie Hamburger!

What would you like to order? (Press [0] to leave)
2

Your current tab is $11.97
If you were to buy a Soft Drink, your tab would become $13.96
Would you like to purchase it? ([1] = yes, [2] = no)
1
-------------------------------------------------------------------------

For each transaction, two functions are called. One function that provides details on how much the bill would be if the order was placed and one function that modifies the bill. In your main function, have a guestBill variable that is initialized to zero and is passed into the two functions. You need to decide which function is passed by value and which function is passed by reference to ensure the bill is always accurate.

When the customer chooses to leave the restaurant, the bill should be printed one last time (to let the customer know how much is owed) followed by a kind farewell!