Thursday, 5 September 2013

1st prac Veg_&_Fruits

#include <iostream>
#include<string.h>
#define MAX 30
using namespace std;
class veg
{
public:
string v;
int vcount;
void getveg(string s,int p)
{
v=s;
vcount=p;
}
void display_veg(void)
{
cout<<"\n";
cout<<v;
cout<<"\t\t"<<vcount;
}
};
 class fruit
 {
 public:
string f;
int fcount;
void getfruit(string s,int p)
{
f=s;
fcount=p;

}
void display_fruit(void)
{
cout<<"\n";
cout<<f;
cout<<"\t\t"<<fcount;
}
 };

 void arrange(veg *vobj[MAX],fruit *fobj[MAX],int n)
 {
int temp;
string s;
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(vobj[i]->vcount<vobj[j+1]->vcount)
{
temp=vobj[i]->vcount;
s=vobj[j]->v;
vobj[j]->vcount=vobj[j+1]->vcount;
vobj[i]->v=vobj[j+1]->v;
vobj[j+1]->vcount=temp;
vobj[j+1]->v=s;

}
}
}
 for(i=0;i<n-1;i++)
  {
  for(j=0;j<n-i-1;j++)
  {
  if(fobj[i]->fcount<fobj[j+1]->fcount)
  {
  temp=fobj[i]->fcount;
  s=fobj[j]->f;
  fobj[j]->fcount=fobj[j+1]->fcount;
  fobj[i]->f=fobj[j+1]->f;
  fobj[j+1]->fcount=temp;
  fobj[j+1]->f=s;
  }
  }
  }
cout<<"\n veg \t\t fruit";
cout<<"\n------------------";
for(i=0;i<n;i++)
{
cout<<"\n";
cout<<vobj[i]->v<<"\t\t"<<fobj[i]->f;
}
}

 int main()
{
veg *vobj[MAX];
string vname="";
int vcount;
fruit *fobj[MAX];
string fname="";
int fcount,i,n;

void arrange(veg *vobj[MAX],fruit *fobj[MAX], int n);

cout<<"\n \t\t\t VEGETABLE AND FRUIT PURCHASE PATTERN";
cout<<"\n how many items?";
cin>>n;
cout<<"\n ENTRE THE VEGETABLE DETAILS \n";
for(i=0;i<n;i++)
{
cout<<"veg name:";
cin>>vname;
cout<<"Total purchase count:";
cin>>vcount;
vobj[i]=new veg;
vobj[i]->getveg(vname,vcount);
}
cout<<"\n Entre fruit details\n";
for(i=0;i<n;i++)
{
cout<<"fruit name:";
cin>>fname;
cout<<"Total purchase count:";
cin>>fcount;
fobj[i]=new fruit;
fobj[i]->getfruit(fname,fcount);
}
cout<<"\n vegetable \t purchase count";
cout<<"\n-----------------------------------------------------";
for(i=0;i<n;i++)
{
vobj[i]->display_veg();

}
cout<<"\n fruit \t\t\t purchase count";
cout<<"\n -----------------------------------------------------";
for(i=0;i<n;i++)
{
fobj[i]-> display_fruit();
}
      cout<<"\n\n arranging according to purchase pattern ---------";
      arrange(vobj,fobj,n);
      return 0;
}

No comments:

Post a Comment