0

Data Structures (CS301) Assignment # 02 Semester Spring 2021

Data Structures (CS301) Assignment # 02

Problem Statement:

Due to the Coronavirus pandemic Government has asked all the major grocery stores to serve the customers as soon as possible so that the gathering of the people may be avoided. In this regard all the grocery stores have decided that there will be two queues for the customers at each grocery store. One queue is the express queue and second is the normal queue. Express queue will have the customers which have bought 5 or less than 5  grocery items. Similarly normal queue will have the customers with grocery items greater than 5. These queues will help the customer to choose the  line according to their grocery shopping requirements and they will have to wait in their queue accordingly. The idea is to develop a C++ program that could serve the purpose of FIFO (first come first served)for both express and normal service queues so that each customer may select queue according to his/her shopping requirements. The program must have the features to:
·         Record the information of the customer (name, shopping information etc.) and identify the type of customer so that he/she may select express queue or normal queue)
·         Simulate both express and normal queues i.e., count the number of customers and the serving time of each customer in each queue.
The program must have the following functional features:
1.        Record information of each customer that would be the customer name, customer id, number of grocery items purchased.
2.        Send each customer to either express queue or normal queue based on the number  of grocery items customer has purchased.
3.        Keep the count of customers in each queue. Whenever a customer enters or exits a queue display the total number of customers in that queue
4.        Print the information of the customers of both the queues.
Furthermore: You need to consider following necessary steps while developing the solution.
·         Use linked list to make queue of customers. Here CustomerNode class will be used in place of Node class.
·         Create a single CustomerQueue class to handle both express and normal queues customers. Use addCustomer(enqueue), removeCustomer(dequeue) and methods for smooth operations of queue.
·         Collect all information of customers like
o   Customer Name, Customer ID, Number of grocery items purchased,
·         After getting required information of customer, check the number of grocery items customer has purchased and then put him in the respective queue.
Whenever a customer enters into a queue print the message “Customer entered in express/normal queue” and also print the total number of customers in that queue. Use removeCustomer() method to remove customer one by one and display the information of that customer along with the remaining customers count of each queue.

CODE :

#include<iostream>
#include<string>

using namespace std;

class CustomerNode{
	public:
		int cid = 0;
		string cname = "";
		int pitem = 0;
		CustomerNode *next;
};


class CustomerQueue{
	public:
		CustomerNode *front, *rear;
		CustomerQueue(){
			front = rear = NULL;
		}
		
		void addCustomeer(int,string,int);
		void removeCustomer(char,int);
		void display(CustomerNode*,string,int);
};

void CustomerQueue::addCustomeer(int id,string name,int item){
	CustomerNode *newNode = new CustomerNode;
	
	newNode -> cid = id;
	newNode -> cname = name;
	newNode -> pitem = item;
	newNode-> next = NULL;
	
	if(front == NULL){
		front = rear = newNode;
		rear -> next = NULL;
	}else{
		while(rear->next != NULL){
			rear = rear ->next;
		}
		rear ->next = newNode;
		rear = newNode;
	}
}


void CustomerQueue::removeCustomer(char q,int count){
	CustomerNode *temp = front;
	string queue;
	if(front == NULL){
		rear = NULL;
		if(q == 'n'){
			queue = "Normal";
		}else{
			queue = "Express";
		}
		cout<<"----"<<queue<<" Queue Customer Information----"<<endl;
		cout<<queue<<"Queue is empty"<<endl;
	}else{
		
		if(q == 'n'){
			queue = "Normal";
		}else{
			queue = "Express";
		}
		cout<<"----"<<queue<<" Queue Customer Information----"<<endl;
		display(temp,queue,count);
		delete(temp);
	}
	
}


void CustomerQueue::display(CustomerNode* temp,string queue,int count){
	temp = front;
	while(temp!=NULL){
		cout<<"Customer ID = "<<temp->cid<<endl;
		cout<<"Customer Name = "<<temp->pitem<<endl;
		cout<<"Total Customer in "<<queue<<" Queue = "<<--count<<endl;
		temp=temp->next;
	}
	
}

int main(){
	CustomerQueue express,normal;
	int id = 0,item = 0,exp_count = 0,nor_count = 0;
	string name;
	bool check = true;
	char choice,exp = 'e',nor='n';
	
	while(check){
		cout<<"---Enter Customer Information---"<<endl;
		cout<<"Custometr  ID = ";
		cin>>id;
		cout<<"Custometr  Name = ";
		cin>>name;
		cout<<"Item Purchesed = ";
		cin>>item;
		if(item <= 5){
			cout<<"---------- Customer Entered in Express Queue ----------"<<endl;
			express.addCustomeer(id,name,item);
			exp_count++;
			cout<<"Total Number of Customer in Express Queue = "<<exp_count<<endl;
			
		}else{
			cout<<"------ Customer Entered in Normal Queue ---"<<endl;
			express.addCustomeer(id,name,item);
			nor_count++;
			cout<<"Total Number of Customer in Normal Queue = "<<nor_count<<endl;
		}
		
		
		cout<<"\nDo you want to enter another Customer Y for yes or N for no : ";
		cin>>choice;
		if(choice == 'n' || choice == 'N'){
			express.removeCustomer(exp,exp_count);
			normal.removeCustomer(nor,nor_count);
			check = false;
		}
	}
	
	return 0;
}

shaad

Leave a Reply

Your email address will not be published. Required fields are marked *