Sort vegetable and fruit according to customer value

#include<iostream>
#include<stdlib.h>
#include<string.h>

using namespace std;

#define MAX 50

//Vegetables class
class vegetables
{
public:
char V[MAX];
int Vpurchase_count;
void getdata1(char s[],int p)
{

strcpy(V,s);
Vpurchase_count=p;
}
void display1(void)
{
cout<<"\n";
cout<<V;
cout<<"\t\t"<<Vpurchase_count;
}
};

//Fruits class
class fruits
{
public:
char F[MAX];
int Fpurchase_count;
void getdata2(char s[],int p)
{
strcpy(F,s);
Fpurchase_count=p;
}
void display2(void)
{
cout<<"\n";
cout<<F;
cout<<"\t\t"<<Fpurchase_count;
}
};



void Arrange(vegetables *Vobj,fruits *Fobj, int n)
{
int temp;
char s[40];
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(Vobj[j].Vpurchase_count<Vobj[j+1].Vpurchase_count)
{
temp=Vobj[j].Vpurchase_count;
strcpy(s,Vobj[j].V);

Vobj[j].Vpurchase_count=Vobj[j+1].Vpurchase_count;
strcpy(Vobj[j].V,Vobj[j+1].V);

Vobj[j+1].Vpurchase_count=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].Fpurchase_count<Fobj[j+1].Fpurchase_count)
        {
temp=Fobj[j].Fpurchase_count;
strcpy(s,Fobj[j].F);

Fobj[j].Fpurchase_count=Fobj[j+1].Fpurchase_count;
strcpy(Fobj[j].F,Fobj[j+1].F);

Fobj[j+1].Fpurchase_count=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;
}
}
int main()

{
 vegetables* Vobj=new  vegetables[MAX];
 char Vname[30];
 int Vcount;
 fruits *Fobj= new fruits[MAX];
 char Fname[40];
 int Fcount, i, j, n;
// void Arrange(vegetables *Vobj[MAX],fruits *Fobj[MAX], int n);
 cout<<"\n\t\t\t VEGETABLES AND FRUIT PURCHASE PATTERN";
 cout<<"\n How many Vegetables items:";
 cin>>n;
 cout<<"\n enter vegetables details \n";
 cout<<"\n..................................";
 for(i=0;i<n;i++)
 {
   cout<<"\nItem Name:";
   cin>>Vname;
   cout<<"purchase count(in Kg):";
   cin>>Vcount;
  // Vobj[i]=new vegetables;
   Vobj[i].getdata1(Vname,Vcount);
 }

cout<<"\n How many fruit items:";
cin>>n;
cout<<"\n Enter Fruit details\n";
cout<<"\n............................";
 for(i=0;i<n;i++)
 {
   cout<<"\nItem Name:";
   cin>>Fname;
   cout<<"purchase count(in kg):";
   cin>>Fcount;
  // Fobj[i]=new fruits;
   Fobj[i].getdata2(Fname,Fcount);
 }
cout<<"\n Vegetables\tpurchase count";
cout<<"\n..................................";
for(i=0;i<n;i++)
{
Vobj[i].display1();
}

cout<<"\n fruits\tpurchase count";
cout<<"\n...................................";
for(i=0;i<n;i++)
{
Fobj[i].display2();
}

cout<<"\n\nArranging according to purchase pattern..";
cout<<"\n...............................................";
Arrange(Vobj,Fobj,n);
return 0;
}
SHARE
    Blogger Comment
    Facebook Comment