#include<iostream.h>
#include<conio.h>
clas queue
{
int *a,r,f,n;
public:
void head();
void add();
void del();
void view();
};
void queue::head()
{
r=0;
f=0;
cout<<"implementation of queue using pointers"<<endl;
cout<<"**************************************"<<endl;
cout<<"1.add"<<endl;
cout<<"2.del"<<endl;
cout<<"3.view"<<endl;
cout<<"4.exit"<<endl;
cout<<"enter the value of n:";
cin>>n;
}
void queue::add()
{
if(r>=n)
{
cout<<"queue is full"<<endl;
}
else
{
cout<<"enter the num:";
cin>>*(a+r);
r++;
}
}
void queue::del()
{
if(r==f)
{
cout<<"queue is empty"<<endl;
}
else
{
cout<<"deleted element is"<<*(a+(f))<<endl;
f++;
}
}
void queue::view()
{
cout<<"the result is:"<<endl;
for(int j=f;j<;j++)
{
cout<<*(a+j)<<endl;
}
}
void main()
{
int a;
queue *q;
clrscr();
q->head();
do
{
cout<<"enter your choice:";
cin>>a;
switch(a)
{
case 1:
q->add();
break;
case 2:
q->del();
break;
case 3:
q->view();
break;
case 4:
cout<<"exit";
break;
}
}
while(a!=4);
getch();
}
Output:
1.add
2.del
3.view
4.exit
enter the value of n:2
enter your choice:1
enter the num:10
enter your coice:1
enter the num:20
enter your choice:1
queue is full
enter your choice:3
the result is:
10
20
enter your choice:2
deleted element is10
enter your choice:2
deleted element is 20
enter your choice:2
queue is empty
enter your choice:4
exit
#include<conio.h>
clas queue
{
int *a,r,f,n;
public:
void head();
void add();
void del();
void view();
};
void queue::head()
{
r=0;
f=0;
cout<<"implementation of queue using pointers"<<endl;
cout<<"**************************************"<<endl;
cout<<"1.add"<<endl;
cout<<"2.del"<<endl;
cout<<"3.view"<<endl;
cout<<"4.exit"<<endl;
cout<<"enter the value of n:";
cin>>n;
}
void queue::add()
{
if(r>=n)
{
cout<<"queue is full"<<endl;
}
else
{
cout<<"enter the num:";
cin>>*(a+r);
r++;
}
}
void queue::del()
{
if(r==f)
{
cout<<"queue is empty"<<endl;
}
else
{
cout<<"deleted element is"<<*(a+(f))<<endl;
f++;
}
}
void queue::view()
{
cout<<"the result is:"<<endl;
for(int j=f;j<;j++)
{
cout<<*(a+j)<<endl;
}
}
void main()
{
int a;
queue *q;
clrscr();
q->head();
do
{
cout<<"enter your choice:";
cin>>a;
switch(a)
{
case 1:
q->add();
break;
case 2:
q->del();
break;
case 3:
q->view();
break;
case 4:
cout<<"exit";
break;
}
}
while(a!=4);
getch();
}
Output:
1.add
2.del
3.view
4.exit
enter the value of n:2
enter your choice:1
enter the num:10
enter your coice:1
enter the num:20
enter your choice:1
queue is full
enter your choice:3
the result is:
10
20
enter your choice:2
deleted element is10
enter your choice:2
deleted element is 20
enter your choice:2
queue is empty
enter your choice:4
exit
33: illegal structure operation
ReplyDeleteCin>>*(a+r);
for(int j=f;j<;j++)
ReplyDeletein this j< and no number is given
class defined as 'clas'
ReplyDeleteSo many errors
ReplyDelete