Cafeteria system is an important part of any institute. The university wants to automate the
cafeteria system you can help by identifying different classes along with their relationships.
University café has different customers (Employees, Students) that visit it for buying different
kinds of food. We want to make the system online so when a customer wants something he should
order it through a server. Whenever a customer comes to café he/she orders the food from specific
category. When a user wants to order something menu is displayed showing different food corners
(FastFood, ProperMeal, Beverages). After the order is placed generate bill for the user according
to the order he has placed. Identify the classes their relationship and function prototype of each
class
#include <iostream>
#include <vector>
#define EXIT -10
#define MENU_CHOISE -13
#define PRINT_BILL -14
#define ERROR -11
#define STUDENT 101
#define EMPLOYEE 102
class Meal
{
public:
Meal();
~Meal();
const std::string& get_name()
{
return name;
}
const double& get_cost()
{
return cost;
}
void set_name(const std::string & name)
{
this->name = name;
}
void set_cost(const double& cost)
{
this->cost = cost;
}
void input_meal()
{
std::cout << "Enter meal name : ";
std::cin >> name;
std::cout << "Enter meal cost : ";
std::cin >> cost;
}
void output_meal()
{
std::cout << "Name : " << name << " , Cost : " << cost << std::endl;
}
private:
std::string name;
double cost;
};
Meal::Meal()
{
name = "";
cost = 0;
}
Meal::~Meal()
{
}
class Category
{
public:
Category();
~Category();
void set_name(const std::string& name)
{
this->name = name;
}
const std::string& get_name()
{
return name;
}
void add_meal( Meal& meal)
{
meals.push_back(meal);
}
void add_meal(const std::string& name , const double & cost)
{
Meal meal ;
meal.set_cost(cost);
meal.set_name(name);
meals.push_back(meal);
}
void output_category()
{
for (int i = 0; i < meals.size(); i++)
{
std::cout << i + 1 << "."; meals[i].output_meal();
}
}
const int& get_size()
{
return meals.size();
}
std::vector<Meal> get_meals()
{
return meals;
}
private:
std::string name;
std::vector<Meal> meals;
};
Category::Category()
{
name = "";
}
Category::~Category()
{
}
class Menu
{
public:
Menu();
~Menu();
void add_category(const Category & category)
{
menu.push_back(category);
}
int get_meal(Meal *& meal_res)
{
while (1)
{
std::cout << "Select category : \n";
int i = 0;
for (i = 0; i < menu.size(); i++)
{
std::cout << "\t" << i + 1 << "." << menu[i].get_name() << std::endl;
}
i++;
std::cout << i << ".Print bill\n";
i++;
std::cout << i << "." << "Exit\n";
std::cout << "Enter digit : ";
int res = ERROR;
std::cin >> res;
if (res == i)
{
return EXIT;
}
if (res == i-1)
{
return PRINT_BILL;
}
else if (!((res >= 1 && res <= menu.size())))
{
std::cout << "Bad value\n";
system("pause");
exit(0);
}
//
system("cls");
menu[res - 1].output_category();
int last_choise = res - 1;
int tmp = menu[res - 1].get_size() + 1;
std::cout << tmp << "." << "Back\n";
std::cout << "Enter digit : ";
res = ERROR;
std::cin >> res;
if (res == tmp)
{
system("cls");
continue;
}
else if (!((res >= 1 && res <= menu[last_choise].get_size())))
{
std::cout << "Bad value\n";
system("pause");
exit(0);
}
meal_res = new Meal;
*meal_res = menu[last_choise].get_meals()[res-1];
return MENU_CHOISE;
}
}
private:
std::vector<Category> menu;
};
Menu::Menu()
{
menu.resize(3);
menu[0].set_name("FastFood");
menu[0].add_meal("Sandwich", 10);
menu[0].add_meal("Hot dog", 13);
menu[0].add_meal("Ice cream", 4);
menu[0].add_meal("Hamburger", 15);
menu[1].set_name("Proper Meal");
menu[1].add_meal("Pesto Chicken, Rice & Broccoli", 20);
menu[1].add_meal("Salmon Stir-Fry", 30);
menu[2].set_name("Beverages");
menu[2].add_meal("Water", 2);
menu[2].add_meal("Milk", 3);
menu[2].add_meal("Beer", 5);
menu[2].add_meal("Wine", 10);
}
Menu::~Menu()
{
}
//
class Person
{
public:
Person();
~Person();
void set_name(const std::string name)
{
this->name = name;
}
const std::string& get_name()
{
return name;
}
virtual void output_information()
{
std::cout << "Name : " << name << std::endl;
}
private:
std::string name;
};
Person::Person()
{
}
Person::~Person()
{
}
class Student : public Person
{
public:
Student();
~Student();
virtual void output_information()
{
std::cout << "Student name : " << get_name() << std::endl;
}
private:
};
Student::Student()
{
}
Student::~Student()
{
}
class Employee : public Person
{
public:
Employee();
~Employee();
private:
virtual void output_information()
{
std::cout << "Employee name : " << get_name() << std::endl;
}
};
Employee::Employee()
{
}
Employee::~Employee()
{
}
class Bill
{
public:
Bill();
~Bill();
void add_meal(const Meal& meal)
{
meals.push_back(meal);
}
void set_person(Person*& person )
{
this->person = person;
}
void print_bill()
{
std::cout << "BILL :\n\n";
person->output_information();
double value = 0;
for (int i = 0; i < meals.size(); i++)
{
meals[i].output_meal();
value += meals[i].get_cost();
}
std::cout << "\n\tPrice : " << value << std::endl;
}
private:
Person* person;
std::vector<Meal> meals;
};
Bill::Bill()
{
person = nullptr;
}
Bill::~Bill()
{
}
int main()
{
Person* person = nullptr;
std::string answer="";
std::cout << "Are u student or employee (E or S) : ";
std::cin >> answer;
Bill bill;
if (answer == "S")
{
person = new Student();
}
else if (answer == "E")
{
person = new Employee();
}
system("cls");
std::cout << "Enter your name : ";
std::cin >> answer;
system("cls");
person->set_name(answer);
Menu menu;
bill.set_person(person);
Meal *meal = nullptr;
while (1)
{
system("cls");
int ev = ERROR;
ev = menu.get_meal(meal);
if (ev == PRINT_BILL)
{
bill.print_bill();
system("pause");
exit(0);
}
else if (ev == MENU_CHOISE)
{
bill.add_meal(*meal);
}
else if (ev == EXIT)
{
system("pause");
exit(0);
}
else if (ev == ERROR)
{
system("pause");
exit(0);
}
}
system("pause");
return 0;
}
Comments
Leave a comment