#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);
}
Comments
Leave a comment