Assignment 3
Assignment 3
#include<string>
using namespace std;
int total_table = 1;
//class defination
class Table {
int table_no;
int capacity;
int free;
int busy;
bool occupied;
bool clean;
public:
//default costructor
Table() {
table_no = total_table++;
capacity = 4;
free = capacity;
clean = true;
busy = 0;
occupied = false;
}
//parametrized costructor
Table(int Cap) {
if (Cap <= 4) {
capacity = 4;
}
else
capacity = 8;
table_no = total_table++;
free = capacity;
clean = true;
busy = 0;
occupied = false;
}
//a fuction to assign table to group of friends
void assign_table(int friends) {
busy = friends;
free = capacity - busy;
occupied = true;
}
//lunch function
void lunch() {
cout << "\nEnjoy your lunch" << endl<<endl;
clean = false;
}
//clean function
void Clean() {
clean = true;
cout << "Table no "<<table_no<<" is cleaned" << endl;
}
//To Empty Table
void Empty() {
free = capacity;
busy = 0;
occupied = false;
};
//occupy function
bool OccupyTable(Table T[], int friends) {
static int group = 1;
char choice;
bool error = 0;
bool found = 0;
cout << "\nFinding Table for group no " << group++ << " :\n";
for (int i = 0; i < 5; i++) {
if (!T[i].get_Occupied()) {
if (T[i].get_clean() && T[i].get_Capacity() >= friends) {
cout << "Table found" << endl
<< "Table Details: " << endl
<< "Table no: " << i + 1 << endl
<< "Seating Capacity: " << T[i].get_Capacity() << endl;
cout << endl;
char lunch;
cout << "Do you want to have lunch (Y/y for Yes and N/n for No): ";
cin >> lunch;
if (lunch == 'Y' || lunch == 'y') {
T[i].lunch();
}
found = 1;
T[i].assign_table(friends);
break;
}
else if (!T[i].get_clean()) {
do {
cout << "Table found\nTable is not cleaned\nPress 1 to clean
the Table \nPress 2 to find another one: ";
cin >> choice;
switch (choice) {
case '1':
T[i].Clean();
cout << "Table Details: " << endl
<< "Table no: " << i + 1
<< "Seating Capacity: " << T[i].get_Capacity() << endl;
char lunch;
cout << "Do you want to have lunch (Y/y for Yes and N/n for
No): ";
cin >> lunch;
if (lunch == 'Y' || lunch == 'y') {
T[i].lunch();
}
found = 1;
T[i].assign_table(friends);
error = 0;
break;
case '2':
cout << "Finding another table\n";
error = 0;
default:
cout << "Invalid Entery\n" << endl;
error = 1;
}
} while (error);
if (found)
break;
}
}
}
if (!found) {
cout << "All Tables Full\n";
return 0;
}
return 1;
}
//Empty Function
void Empty(Table T) {
T.Empty();
cout << "Table is Free";
}
//Main function
int main() {
Table T[5] = { 4,4,4,8,8 };
OccupyTable(T, 4);
OccupyTable(T, 6);
T[0].Clean();
T[3].Empty();
return 0;
}