Skip to content

Instantly share code, notes, and snippets.

@Geal
Last active February 9, 2018 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geal/016ee9653a93ad467aac6d383460a1ad to your computer and use it in GitHub Desktop.
Save Geal/016ee9653a93ad467aac6d383460a1ad to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;
class Service {
vector<string> menu;
unsigned int places;
unsigned int available_places;
vector<int> commandes;
public:
Service();
void show_menu();
void show_choice(int item);
bool check_item(int item);
bool take_available_places(unsigned int nb_clients);
void take_order(int item);
void present_plates();
void payment();
int nb_orders();
int next_order();
};
Service::Service() {
places = 10;
available_places = 10;
menu.push_back("bolognaise");
menu.push_back("cuisses de grenouille");
menu.push_back("omelette");
menu.push_back("tacos");
menu.push_back("nems");
}
void Service::show_menu() {
cout << endl << "Voici le menu:" << endl;
for(int i = 0; i < menu.size(); i++) {
cout << i << " - " << menu[i] << endl;
}
}
void Service::show_choice(int item) {
cout << "vous avez choisi: " << menu[item] << endl;
}
bool Service::check_item(int item) {
return item >= 0 && item < menu.size();
}
bool Service::take_available_places(unsigned int nb_clients) {
assert(available_places <= places);
if((nb_clients > 0) &&
(nb_clients <= available_places)) {
available_places = available_places - nb_clients;
return true;
} else {
return false;
}
}
void Service::take_order(int item) {
commandes.push_back(item);
}
int Service::nb_orders() {
return commandes.size();
}
int Service::next_order() {
int item = commandes.back();
commandes.pop_back();
return item;
}
void Service::present_plates() {
}
void Service::payment() {
}
class Kitchen {
vector<int> orders;
Service& waiter;
public:
Kitchen(Service& service);
void receive_orders();
void prepare_orders();
void notify();
};
Kitchen::Kitchen(Service& s) : waiter(s) {
}
void Kitchen::receive_orders(){
for(int i = 0; i < waiter.nb_orders(); i++) {
orders.push_back(waiter.next_order());
}
}
void Kitchen::prepare_orders(){}
void Kitchen::notify(){}
int main() {
Service waiter;
Kitchen kitchen(waiter);
while(true) {
// service part
cout << "Bonjour!" << endl;
cout << "Combien êtes-vous?" << endl;
int nb_clients;
cin >> nb_clients;
if ( !waiter.take_available_places(nb_clients) ) {
cout << endl << "il n'y a plus de place" << endl;
} else {
cout << endl << "asseyez-vous svp" << endl;
waiter.show_menu();
int i = 0;
while (i < nb_clients) {
cout << "Client " << i << ", que désirez-vous?" << endl;
int item = -1;
while( !waiter.check_item(item) ) {
cin >> item;
if( !waiter.check_item(item) ) {
cout << " cet élément n'existe pas" << endl;
}
}
waiter.show_choice(item);
waiter.take_order(item);
i = i + 1;
}
}
// kitchen part
kitchen.receive_orders();
kitchen.prepare_orders();
kitchen.notify();
waiter.present_plates();
waiter.payment();
}
}
@antosox
Copy link

antosox commented Feb 9, 2018

woaw
j'adore ce restaurant *****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment