Project Layout
Project Layout
Should contain low-level memory management, input/output, and object- oriented design principles.
Users will interact with your application via a command line interface (CLI), rather than a graphical
interface.
Once implemented, users should be able to use the system to view a menu, create orders, add/remove
items from their order, and get a receipt for once they “checkout”.
The inheritance hierarchy of the application you must implement is shown above. You are provided
with a skeleton program called Takeaway.cpp, and a file containing food and drink items for sale in
menu.csv. You may edit the content of Takeaway.cpp, but the general structure should be left
unchanged. Do NOT edit menu.csv. You may need to implement additional functions to those
shown in order to produce a working implementation.
To get started, implement an Item class which stores the general information (name, calories,
price) about the food and drink items available to purchase. You should then implement the three
derived classes - Appetiser, MainCourse and Beverage. The Appetiser class contains two
attributes; shareable and twoForOne. The Beverage class also contains two attributes; abv and
volume. The MainCourse class has no additional attributes. You should consult the menu.csv file
to identify appropriate data types for each attribute.
Next is the ItemList abstract class, which provides an interface for storing and manipulating food and
drink items. Instances of the Item class should be stored by reference as a vector of pointers. The sole
member function toString should be pure virtual.
The derived Menu class should contain a function to ‘load’ a menu object from a file path. This
should be provided as an argument to the constructor (in your main code, this will be menu.csv).
Each row corresponds to a different item to be created and added to a vector of pointers. You should
ensure that the correct object type is created based on the character in the first column – ‘a’ is an
appetiser, ‘m’ is a main course, and ‘b’ is a beverage. Implement a toString function to display the
whole menu in attractive way, organised by item type.
The derived Order class should contain functions to add and remove items from an order based on
their numerical position in the respective item list (starting at one, rather than zero). Each time an item
is added or removed, inform the user of the result and recalculate the overall total of the items in their
order.
The calculateTotal function should consider the number of items in the order that are eligible for a
“2-4-1” discount, i.e., if a user adds two appetisers to their order where twoForOne == true, one of
them should be free of charge. You may assume that all such items are the same price.
Implement a toString function to display the items in the order, along with the total price and the
savings made. The printReceipt function should write the user’s order to a text file called
receipt.txt, using the output from the toString function. In the output, the total and savings
should be displayed in the following way:
The remaining program logic should be implemented in Takeaway.cpp, which should initialise a
Menu object from menu.csv and an (initially empty) Order object. You should modify the code to
accept input commands with the following syntax:
Upon checkout, give the user the option to either complete their order (output their receipt and
terminate gracefully) or go back and modify it
Final features:
- Allow users to add and remove multiple items at once, e.g., add 2 5 7
- Modify the calculateTotal function so that 2-4-1 discounts cause only the cheapest eligible
item(s) to be free.
- Add commands to sort the menu by item price in ascending/or descending order, using some
combination of operator overloading/functional programming in your implementation
-
Takeaway.cpp
#define _CRT_SECURE_NO_WARNINGS
#include "Menu.h"
#include "Order.h"
#include "Item.h"
#include <iostream>
#include <vector>
#include <cstring>
int main()
{
string userCommand;
vector <string> parameters;
char* token;
token = strtok(cstr, " ");
if (command.compare("menu") == 0) {
cout << menu.toString();
}
else if (command.compare("add") == 0)
{
Item* choice; // you need to instantiate this using
the menu object!
order.add(choice);
}
else if (command.compare("checkout") == 0)
{
}
else if (command.compare("help") == 0)
{
parameters.clear();
Menu.csv
a,Nachos,4.99,600,y,n,,
a,Buffalo wings,3.99,450,n,y,,
a,Garlic bread,3.99,500,n,y,,
m,Burger,9.99,950,,,,
m,Mac & cheese,7.99,850,,,,
m,Fish & chips,8.99,1000,,,,
m,Chicken tikka masala,6.99,700,,,,
b,Lager,3.5,200,,,568,4.5
b,White wine,4,150,,,175,11.5
b,Red wine,4,170,,,175,12.5
b,Coke,2.5,140,,,330,0
b,Water,1.5,0,,,330,0