NAME:
ROLL
NO:
CLASS:SE
COMP
INPUT:
#include<iostream>
#include<string.h>
using
namespace std;
class
node
{
char name[20];
int PS;
node *next;
node *head;
public:
node *insertion();
void display(node *head);
void display(node *head1,node *head2);
};
class
veg:public node
{
node *head1;
public:
veg()
{
head1=NULL;
}
};
class
fruit:public node
{
node *head2;
public:
fruit()
{
head2=NULL;
}
};
node*
node::insertion()
{
node *p,*q,*r,*head=NULL;
int n;
cout<<"\nenter how many
items:";
cin>>n;
for(int i=0;i<n;i++)
{
p=new node;
cout<<"\nEnter name:";
cin>>p->name;
cout<<"\n Enter the purchase
sale:";
cin>>p->PS;
p->next=NULL;
if(head==NULL || p->PS > head->PS)
{
p->next=head;
head=p;
}
else
{
q=head;
while(q->next!=NULL && q->next
->PS > p->PS)
q=q->next;
p->next=q->next;
q->next=p;
}
}
return
head;
}
void
node::display(node *head)
{
node *p;
cout<<"\n Name\t\t Purchase
Sale";
for(p=head;p!=NULL;p=p->next)
{
cout<<"\n"<<p->name<<"\t\t"<<p->PS;
}
}
void
node::display(node *head1,node *head2)
{
node *p,*q;
cout<<"\n Vegetable Name\tFruit
Name";
for(p=head1,q=head2;p!=NULL &&
q!=NULL;p=p->next,q=q->next)
{
cout<<"\n"<<p->name<<"\t\t"<<q->name;
}
}
int
main()
{
node *head1,*head2;
veg v;
fruit f;
int ch,c;
do
{
cout<<"\n1.Insertion\n2.Display\n3.exit";
cout<<"\n Enter a choice:";
cin>>ch;
switch(ch)
{
case 1:do
{
cout<<"\n1.vegetable\n2.fruit\n3.exit";
cout<<"\nenter a
choice:";
cin>>c;
switch(c)
{
case 1:head1=v.insertion();
break;
case 2:head2=f.insertion();
break;
case 3:break;
default:cout<<"\nInvalid
choice";
}
}while(c!=3);
break;
case 2:do
{
cout<<"\n1.vegetable\n2.fruit\n3.exit";
cout<<"Enter a
choice:";
cin>>c;
switch(c)
{
case 1:v.display(head1);
break;
case 2:f.display(head2);
break;
case 3:v.display(head1,head2);
break;
default:cout<<"\nInvalid
choice";
}}while(c!=3);
break;
case 3:break;
default:cout<<"\nInvalid
choice";
}}while(ch!=3);
return 0;
}
********************************************
OUTPUT:
1.Insertion
2.Display
3.exit
Enter a choice:1
1.vegetable
2.fruit
3.exit
enter a
choice:1
enter how
many items:3
Enter
name:tomato
Enter the purchase sale:20
Enter
name:potato
Enter the purchase sale:30
Enter
name:onion
Enter the purchase sale:10
1.vegetable
2.fruit
3.exit
enter a
choice:2
enter how
many items:3
Enter
name:grapes
Enter the purchase sale:50
Enter
name:cherry
Enter the purchase sale:60
Enter
name:papaya
Enter the purchase sale:40
1.vegetable
2.fruit
3.exit
enter a
choice:3
1.Insertion
2.Display
3.exit
Enter a choice:2
1.vegetable
2.fruit
3.exitEnter
a choice:1
Name
Purchase Sale
potato 30
tomato 20
onion 10
1.vegetable
2.fruit
3.exitEnter
a choice:2
Name
Purchase Sale
cherry 60
grapes 50
papaya 40
1.vegetable
2.fruit
3.exitEnter
a choice:3
Vegetable Name Fruit
Name
potato cherry
tomato grapes
onion papaya
1.Insertion
2.Display
3.exit
Enter a choice:3
No comments:
Post a Comment