63 203
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #47987 in C++ for zinkarocks

Question #47987
Problem statement
ANZ call centre receives hundreds of calls per day and they want an efficient way to
handle all the receiving calls. The clear directive from customer service department is to
give fair chance to each customer on first come first serve basis.

Requirements
To solve the above problem you will need a queue data structure to keep all the receiving
calls. Recall queue uses First In First Out (FIFO) principle. Customer service consultants
can take a caller at a time from the queue and the queue is open for other callers. A caller
must leave a name and message and hang up the phone so that a consultant could attend to
him/her when the caller gets his/her chance from the queue.
It is clear from the given description that you would need to have queue of callers where
for each caller you must store the phone number, name and message attributes. Assume
the capacity of the queue cannot be more than 10.
Expert's answer
#include <stdlib.h>
#include <iostream>  
#include <stdio.h>
#include <cstdlib> 
#include <string>
using namespace std;
 
class queue 
{
private:
struct queue_ob
{
string name;
   string message;
   string phoneNumber;
queue_ob *addr;
};
 
queue_ob *head; 
queue_ob *tail; 
int size; 
 

public:
queue(string s1, string s2, string s3)
{
head=new(queue_ob); 
tail=head; 
head->name = s1;
head->message = s2;
head->phoneNumber = s3;
head->addr=0; 
size=1; 
}
int stack_size()
{
return size;
}
 
void push(string s1, string s2, string s3)
{
if (size < 10)
{
size++;
   queue_ob *temp=new(queue_ob); 
   temp->addr=0; 
   head->name = s1;
        head->message = s2;
   head->phoneNumber = s3;
   tail->addr=temp; 
   tail=temp;
}
else
{
cout<<"The queue size is exceeded"<<endl; system("pause");
}
}
 
void pop(string *s1, string *s2, string *s3)  
{
if(size == 0)
{
cout<<"Queue is clear- remove nothing!"<<endl;
return;
}
 
queue_ob *temp=head; 
*s1=head->name; 
*s2=head->message;
*s3=head->phoneNumber;
head=head->addr; 
delete temp;  
size--; 
}
 
void peek(string *s1, string *s2, string *s3)
{
if(size == 0) 
{
cout<<"Queue is clear!"<<endl;
return;
}
*s1=head->name; 
*s2=head->message;
*s3=head->phoneNumber;
}
 
};
int main()
{
string name;
string message;
string phoneNumber;
int temp;
cout<<"Enter the name of first caller : ";
cin>>name;
cout<<"Enter the message of fisrt caller : ";
cin>>message;
cout<<"Enter the phone number of first caller";
cin>>phoneNumber;
queue a(name, message, phoneNumber);
do
{
system("cls");
cout<<"1. Add caller to queue"<<endl;
cout<<"2. Get the last caller  of the queue"<<endl;
cout<<"3. Current size of the queue"<<endl;
cout<<"4. Close the program"<<endl;
cin>>temp;
switch(temp)
{
case 1: 
{
cout<<"Enter the name  : ";
               cin>>name;
               cout<<"Enter the message  : ";
               cin>>message;
               cout<<"Enter the phone number :";
               cin>>phoneNumber;
a.push(name, message, phoneNumber);
} break;
case 2:
{
a.pop(&name, &message, &phoneNumber);
cout<<"Last Caller"<<endl;
cout<<"Name         : "<<name<<endl;
cout<<"Message      : "<<message<<endl;
cout<<"Phone number : "<<phoneNumber<<endl;
system("pause");
} break;
case 3:
{
cout<<"Size of queue : "<<a.stack_size()<<endl;
system("pause");
} break;
case 4: break;
default: cout<<"Wrond input!!!"<<endl; system("pause"); break;

}
} while (temp != 4);
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions