Talha Ulfat Lodhi BSE183085: Practice Task 7.3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Talha Ulfat Lodhi

BSE183085

Practice task 7.3:

#include<iostream>
#include<string>
using namespace std;

class Customer
{
public:

void set_name(string a)
{
name = a;
}
void set_id(int a)
{
id = a;
}
void set_bill(int a)
{
bill = a;
}

string get_name()
{
return name;
}
int get_id()
{
return id;
}
int get_bill()
{
return bill;
}

private:
string name;
int id, bill;
};

class Queue
{
public:
Queue(int s)
{
size = s;
customers = new Customer[size];
rear = 0, front = 0;
}
~Queue()
{
delete[] customers;
}

void enqueue(Customer a)
{
if (full() == 1)
{
cout << "Queue is Full...\n\n";
}
else
{
int temp;
string temp1;
temp1 = a.get_name();
customers[rear].set_name(temp1);
temp = a.get_id();
customers[rear].set_id(temp);
temp = a.get_bill();
customers[rear].set_bill(temp);
rear++;
}
}
void dequeue()
{
if (empty() == 1)
{
cout << "Queue is Empty...\n\n";
}
else
{

int temp;
string temp1;
cout << "Customer Checkedout: " << customers[front].get_name() <<
endl << endl;
for (int i = 0; i < (rear - 1); i++)
{
temp1 = customers[i + 1].get_name();
customers[i].set_name(temp1);
temp = customers[i + 1].get_id();
customers[i].set_id(temp);
temp = customers[i + 1].get_bill();
customers[i].set_bill(temp);
}
count++;
rear--;
}
}

bool full()
{
return(rear == size);
}
bool empty()
{
return(rear == front);
}

void served()
{
if (count == 0)
cout << "No customers served yet...";
else
cout << "Customers Served: " << count;
}
void time_left()
{

if (empty() == 1)
cout << "No customers left to be served...";
else
cout << "Time required to serve the remaining customers: " << (rear
* 5) << " minutes approximately";
}

private:
Customer* customers;
int size, rear, front, count = 0;
};

void working()
{
string test;
int temp;
char ask;
Customer c;
cout << "Enter total capacity for customers: ";
cin >> temp;
Queue customers(temp);
do
{
system("cls");
cout << "1...Add Customer\n2...Checkout Customer\n3...Customers served
already\n4...Time required to serve all the remaining customers\n5...Quit\n\nEnter your
desired extension: ";
cin >> temp;
switch (temp)
{
case 1:
{
system("cls");
if (!customers.full())
{
cout << "Enter Name: ";
cin.ignore();
getline(cin, test);
c.set_name(test);
cout << "Enter Customer id: ";
cin >> temp;
c.set_id(temp);
cout << "Enter billing amount: ";
cin >> temp;
c.set_bill(temp);
customers.enqueue(c);
}
else
cout << "Queue is full...\n\n";

break;
}
case 2:
{
system("cls");
customers.dequeue();
break;
}
case 3:
{
system("cls");
customers.served();
break;
}
case 4:
{
system("cls");
customers.time_left();
break;
}
case 5:
{
_exit(1);
}
}
cout << "\n\nDo you want to continue?(y/n)\n";
cin >> ask;
} while (ask == 'y' || ask == 'Y');
}
void main()
{
working();
}

You might also like