- include<iostream.h>
- #include<string.h>
- #include<conio.h>
- class vegetable
- {
- public:
- char v[30];
- int vegcount;
- void getdata(char *s, int p)
- {
- strcpy(v,s);
- vegcount=p;
- }
- void display1(void)
- {
- cout<<"\n";
- cout<<v;
- cout<<"\t\t"<<vegcount;
- }
- };
- class fruits
- {
- public:
- char f[30];
- int fruitcount;
- void getdata(char *s, int p)
- {
- strcpy(f,s);
- fruitcount=p;
- }
- void display2(void)
- {
- cout<<"\n";
- cout<<f;
- cout<<"\t\t"<<fruitcount;
- }
- };
- void arrange( vegetable vobj[30], fruits fobj[30],int n)
- {
- int temp;
- char *s;
- int i,j;
- for(i=0; i<n-1;i++)
- {
- for(j=0;j<n-i-1;j++)
- {
- if(vobj[j].vegcount<vobj[j+1].vegcount)
- {
- temp=vobj[j].vegcount;
- strcpy(s,vobj[j].v);
- vobj[j].vegcount=vobj[j+1].vegcount;
- strcpy(vobj[j].v,vobj[j+1].v);
- vobj[j+1].vegcount=temp;
- strcpy(vobj[j+1].v,s);
- }
- }
- }
- for(i=0; i<n-1;i++)
- {
- for(j=0;j<n-i-1;j++)
- {
- if(fobj[j].fruitcount<fobj[j+1].fruitcount)
- {
- temp=fobj[j].fruitcount;
- strcpy(s, fobj[j].f);
- fobj[j].fruitcount=fobj[j+1].fruitcount;
- strcpy(fobj[j].f, fobj[j+1].f);
- fobj[j+1].fruitcount=temp;
- strcpy(fobj[j+1].f,s);
- }
- }
- }
- cout<<"\n Vegetables \t\t Fruits";
- cout<<"\n---------------";
- for(i=0;i<n;i++)
- {
- cout<<"\n";
- cout<<vobj[i].v<<"\t\t"<<fobj[i].f;
- }
- }
- void main()
- {
- vegetable veg[30];
- char *vname="";
- int vcount;
- fruits fruit[30];
- char *fname="";
- int fcount,i,n;
- void arrange(vegetable veg[30], fruits fruit[30], int n);
- clrscr();
- cout<<"\n \t\t Vegetable and Fruit Purchase Pattern";
- cout<<"\nHow many items?";
- cin>>n;
- cout<<"\n Enter Vegetable details\n";
- for(i=0;i<n;i++)
- {
- cout<<"\nItem :";
- cin>>vname;
- cout<<"\nPurchase Count";
- cin>>vcount;
- veg[i].getdata(vname,vcount);
- }
- cout<< "\n Enter Fruit details\n";
- for(i=0;i<n;i++)
- {
- cout<<"\nItem : ";
- cin>>fname;
- cout<<"\nPurchase Count";
- cin>>fcount;
- fruit[i].getdata(fname,fcount);
- }
- cout<<"\n Vegetable \tPurchase Count";
- cout<<"\n......................";
- for(i=0;i<n;i++)
- {
- veg[i].display1();
- }
- cout<<"\n\nFruit\t\tPurchase Count";
- cout<<"\n......................";
- for(i=0;i<n;i++)
- {
- fruit[i].display2();
- }
- cout<<"\n Arranging according to Purchase Pattern..";
- arrange(veg,fruit,n);
- getch();
- }
Thursday, 10 September 2015
first assignment
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment