A Vegetable and Fruit Mall wants to organize its vegetables and fruit products in a combination of purchase pattern of customers. Solve the problem by suggesting appropriate data structures. Design necessary class.

#include"iostream"
using namespace std;
#define MAX 5

int t1 = 0, t2 = 0;

class fruit
{
   private:
char name[20];
float unitprice;
float wt;
float totalprice;

public:
void read();
void disp();
};

void fruit :: read()
{
cout<<"\nEnter Fruit Name:";
cin>>name;
cout<<"\nEnter Fruit Unit Price:";
cin>>unitprice;
cout<<"\nEnter Fruit Weight:";
cin>>wt;

totalprice = unitprice * wt;
cout<<"\nTotal Price"<<totalprice;

t1 = t1 + totalprice;
}

void fruit :: disp()
{
cout<<"\nFruit Name:"<<name;
cout<<"\nUnit Price: Rs."<<unitprice<<" per kg";
cout<<"\nWeight:"<<wt<<" Kg";
cout<<"\nTotal Price: Rs. "<<totalprice;
}

class vegetable
{
private:
char name[20];
float unitprice;
float wt;
float totalprice;

public:
void read();
void disp();
};

void vegetable :: read()
{
cout<<"\nEnter Vegetable Name:";
cin>>name;
cout<<"\nEnter Vegetable Unit Price:";
cin>>unitprice;
cout<<"\nEnter Vegetable Weight:";
cin>>wt;

totalprice = unitprice * wt;
cout<<"\nTotal Price"<<totalprice;
t2 = t2 + totalprice;
}
void vegetable :: disp()
{
cout<<"\nFruit Name:"<<name;
cout<<"\nUnit Price: Rs. "<<unitprice<<" per kg";
cout<<"\nWeight:"<<wt<<" Kg";
cout<<"\nTotal Price: Rs. "<<totalprice;
}

int main()
{
fruit f[MAX];
vegetable v[MAX];
int rear1=0,front1=0,rear2=0,front2=0,i,ch,ch1;

//clrscr();
cout<<"\nMenu\n1.Fruit Only\n2.Vegetable Only\n3.Both\nEnter CH:";
cin>>ch;

switch(ch)
{
case 1: do
{
if(rear1 != MAX)
{
f[rear1].read();
rear1++;
cout<<"\nDo u want to Purchase More(y=1/n=0):";
cin>>ch1;

}
else
{
cout<<"\nSorry U cant Purchase";
ch1 = 0;
}

}
while(ch1 == 1);

for(i=front1;i<rear1;i++)
{
       f[i].disp();
}

cout<<"\nBilling Amount: Rs "<<t1;
break;
case 2: do
{
if(rear2 != MAX)
{
v[rear2].read();
rear2++;
cout<<"\nDo u want to Purchase More(y=1/n=0):";
cin>>ch1;

}
else
{
cout<<"\nSorry U cant Purchase";
ch1 = 0;
}


}
while(ch1 == 1);

for(i=front2;i<rear2;i++)
{
      v[i].disp();
}

cout<<"\nBilling Amount: Rs "<<t2;
break;
case 3: rear1 = 0;
front1 = 0;
rear2 = 0;
front2 = 0;
do
{
if(rear1 != MAX)
{
f[rear1].read();
rear1++;
cout<<"\nDo u want to Purchase More(y=1/n=0):";
cin>>ch1;

}
else
{
cout<<"\nSorry U cant Purchase";
ch1 = 0;
}
}
while(ch1 == 1);

for(i=front1;i<rear1;i++)
{
      f[i].disp();
}

cout<<"\nBilling Amount: Rs "<<t1;
do
{
if(rear2 != MAX)
{
v[rear2].read();
rear2++;
cout<<"\nDo u want to Purchase More(y=1/n=0):";
cin>>ch1;

}
else
{
cout<<"\nSorry U cant Purchase";
}
ch1 = 0;

}
while(ch1 == 1);

for(i=front2;i<rear2;i++)
{
      v[i].disp();
}

cout<<"\nBilling Amount: Rs "<<t2;

cout<<"\nTotal Billing Amount: Rs \n "<<t1+t2;
break;
default:cout<<"\nThnks";



}
return 0;
}

 ************************************************************************************

                           OUTPUT OF PROGRAM

                       Menu
              1.Fruit Only
              2.Vegetable Only
              3.Both
Enter CH:3

Enter Fruit Name:Apple

Enter Fruit Unit Price:40

Enter Fruit Weight:3

Total Price120
Do u want to Purchase More(y=1/n=0):0

Fruit Name:Apple
Unit Price: Rs.40 per kg
Weight:3 Kg
Total Price: Rs. 120
Billing Amount: Rs 120
Enter Vegetable Name:Carrot

Enter Vegetable Unit Price:15

Enter Vegetable Weight:5

Total Price75
Do u want to Purchase More(y=1/n=0):0

Fruit Name:Carrot
Unit Price: Rs. 15 per kg
Weight:5 Kg
Total Price: Rs. 75
Billing Amount: Rs 75
Total Billing Amount: Rs
 195


Comments