CS301 Data Structures Assignment 2 Solution Fall 2013

Suppose there is a large busy cosmetic store. In store, for billing, there are four counters with four tellers (who
deal payment etc). A customer comes to the store and collects the things he/she wants to purchase and go to one
of the counters to pay for purchase. If there are already people in front of counters, customer has to stand in the
queue. A customer generally selects the shortest queue (with respect to the number of people in queue). The
selection can become wrong if one of the people in the queue has a huge buying list. But if we know the
estimated time of each customer in the queue, selection can become efficient. The system can become efficient, if
we tell a new person which one is the shortest queue with respect to time taken by the people waiting in the

Considering the above scenario, write a C++ program which asks a user to enter the estimated time to process
the bill. The program will tell the user, in which queue he/she can stand with respect to the total time of all the

persons already in the queues. At the end of the day the system will display the total number of customers deal
by every Teller and which Teller has deal maximum number of customers.
Solution Guidelines: 
1) To pay the bills, Customer must have to stand in the queue. The length of the queue can vary so you have
to implement queue as linked list.
2) Create a class named Customer (Node class); this class should create a node (customer) in the queue.
This class should define two private data members, time and Next pointer. A constructor, getter and setter
functions for each data member should also be defined in this class.
3) Create another class named Teller (List class); to create a queue for each teller, this class should define
three variables, Front pointer, Rear pointer and counter. The class should also define the following

Constructor(): Default constructor of the class.
Destructor(): Destructor to destroy the memory gained by the use of new operator.
AddCustomer(): This method should enter the new customer at the rear.
TotalCustomer(): This method should return the total number of customers in a queue.
TotalTime(): This method should return the total time of customers standing in said queue.

4) In main() method of the program, create four objects of the class Teller which will act like four
counters at store. These objects should be able to perform all the required functionalities mentioned in the
question statement.
5) You can add more variables and functions to obtain the given functionalities according to your need.


#include <iostream>
#include <cstdlib>
using namespace std;
class customer{
		int time;
		customer *next;
			time = 0;
			next = NULL;
		int get();
		void set(int time);
		void setnext(customer *next);
		customer *getnext();

	int customer::get(){
		return time;

	void customer::set(int time){
		this->time = time;

	void customer::setnext(customer *next){
		this->next = next;

	customer* customer::getnext(){
		return next;

class teller{

		customer *front;
		customer *rear;
		int counter;
		int timer;

			rear = new customer();
			front = rear;
			counter = 0;

		void addcustomer(){	
			customer *newcustomer = new customer();
			rear = newcustomer;
			counter = counter + 1;	
			timer = timer + 2;

		int totalcustomer(){
			return counter;

		int totaltime(){
			return timer;


int main(){

	teller T1, T2, T3, T4;

	char x;

	while(x != 'n'){ 
		int time;
		cout << "Enter duration of your transaction: ";
		cin  >> time;

		short a,b,c,d;
		a = T1.totaltime();
		b = T2.totaltime();
		c = T3.totaltime();
		d = T4.totaltime();

		int min;
		min = a;
		if(b < min)min = b;
		if(c < min)min = c;
		if(d < min)min = d;

		if(a == min && b!= min) {
			cout << "You can stand in queue 1" << endl;
			if(b == min && a != min) {
			cout << "You can stand in queue 2" << endl;

			if(c == min && b != min){
			 cout << "You can stand in queue 3" << endl;

			if(d == min && c != min) {
			cout << "You can stand in queue 4" << endl;

		cout << "Do you want to Buy Another Ticket(y/n) ";
		cin >> x;


	cout << "\n\nNumber of Customers Deal By Every Teller " << endl;
	cout << "T1\t" << T1.totalcustomer() << endl;
	cout << "T2\t" << T2.totalcustomer() << endl;
	cout << "T3\t" << T3.totalcustomer() << endl;
	cout << "T4\t" << T4.totalcustomer() << "\n\n";

	short maxi = T1.totalcustomer();
			if(T2.totalcustomer() > maxi) 
				maxi = T2.totalcustomer();
			if(T3.totalcustomer() > maxi)
				maxi = T3.totalcustomer();
			if(T4.totalcustomer() > maxi)
				maxi = T4.totalcustomer();

		if(maxi == T1.totalcustomer()){
			cout << "Teller 1 Deal Maximum Customer of the day " << endl;

		if(maxi == T2.totalcustomer()){
			cout << "Teller 2 Deal Maximum Customer of the day " << endl;

				if(maxi == T3.totalcustomer()){
			cout << "Teller 3 Deal Maximum Customer of the day " << endl;

				if(maxi == T4.totalcustomer()){
			cout << "Teller 4 Deal Maximum Customer of the day " << endl;

		cout << endl;