Saturday, 9 August 2014

DSPS: Shopping mall

//============================================================================
// Name        : queue.cpp
// Author      : Parashar
// Version     : Final
// Copyright   : Do not try this at home
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<string.h>
using namespace std;
#define size 5
class fruit
{
public:
    char name[10];
    int count;
    int price;
};
class vegetables
{
public:
    char name[10];
    int count;
    int price;
};
class QUEUE
{
    fruit F[size];
    vegetables V[size];
    int ffront,frear,vfront,vrear;
public:
    QUEUE();
    void finsert();
    void fdisplay();
    int fqfull();
    int fqempty();
    void vinsert();
    void vdisplay();
    int vqfull();
    int vqempty();
};
QUEUE::QUEUE()
{
    ffront=frear=vfront=vrear=-1;
}
int QUEUE::fqfull()
{
    if(frear>=size-1)
        return 1;
    else
        return 0;
}
int QUEUE::vqfull()
{
    if(vrear>=size-1)
        return 1;
    else
        return 0;
}
int QUEUE::fqempty()
{
    if(ffront==-1||ffront>frear)
        return 1;
    else
        return 0;
}
int QUEUE::vqempty()
{
    if(vfront==-1||vfront>vrear)
        return 1;
    else
        return 0;
}
void QUEUE::finsert()
{
    int cnt;
    char frt[10];
    int price;
    int j=frear;
    if(ffront==-1)
    {
        ffront++;
    }
    cout<<"enter the fruit name"<<endl;
    cin>>frt;
    cout<<"enter the number of "<<frt<<" to be purchased"<<endl;
    cin>>cnt;
    cout<<"enter the price"<<endl;
    cin>>price;

  while(j>=0 && strcmp(F[j].name,frt)>0)
   {
   F[j+1].count=F[j].count;
   strcpy(F[j+1].name,F[j].name);
   F[j+1].price=F[j].price;
   j--;
   }
 F[j+1].count=cnt;
 strcpy(F[j+1].name,frt);
 F[j+1].price=price;
 frear++;
 cout<<"fruits added to the cart"<<endl<<endl;
}
void QUEUE::vinsert()
{
    int cnt;
    char veg[10];
    int price;
    int j=vrear;
    if(vfront==-1)
    {
        vfront++;
    }
    cout<<"enter the vegetable name"<<endl;
    cin>>veg;
    cout<<"enter the number of "<<veg<<" to be purchased"<<endl;
    cin>>cnt;
    cout<<"enter the price"<<endl;
    cin>>price;

  while(j>=0 && cnt>(V[j].count
          ))
   {
   V[j+1].count=V[j].count;
   strcpy(V[j+1].name,V[j].name);
   V[j+1].price=V[j].price;
   j--;
   }
 V[j+1].count=cnt;
 strcpy(V[j+1].name,veg);
 V[j+1].price=price;
 vrear++;
 cout<<"vegetables added to the cart"<<endl<<endl;
}
void QUEUE::fdisplay()
{
 cout<<"The Purchase order is as below:"<<endl<<endl;
 cout<<"Count Fruit"<<endl;
 cout<<"----------------"<<endl;
 for (int i=ffront;i<=frear;i++)
  {
  cout<<" "<<F[i].count<<"   "<<F[i].name<<endl;
  }
  cout<<endl;
}
void QUEUE::vdisplay()
{
 cout<<"The Purchase order is as below:"<<endl<<endl;
 cout<<"Count vegetables"<<endl;
 cout<<"----------------"<<endl;
 for (int i=vfront;i<=vrear;i++)
  {
  cout<<" "<<V[i].count<<"   "<<V[i].name<<endl;
  }
  cout<<endl;
}

int main()
{
    QUEUE g;
 int ch;
 do

   {
   cout<<"Fruit an vegetable Market"<<endl;
   cout<<"-------------------------"<<endl;
   cout<<"1.Add Fruit to shopping cart"<<endl;
   cout<<"2.Display fruit purchase order "<<endl;
   cout<<"3.Add Vegetable to shopping cart"<<endl;
   cout<<"4.Display vegetable purchase order "<<endl;
   cout<<"5.Exit"<<endl;
   cout<<"-------------------------"<<endl;
   cout<<"Enter your choice = ";
   cin>>ch;
   switch(ch)
      {
      case 1 :  if(g.fqfull())
           cout<<"no more fruits can be added"<<endl<<endl;
        else
           {
           g.finsert();
           }
        break;

      case 2 :  if(g.fqempty())
          cout<<"Nothing is purchased"<<endl<<endl;
        else
        {
          g.fdisplay();
        }
        break;

      case 3 :  if(g.vqfull())
                cout<<"cart is full"<<endl<<endl;
                  else
                {
                g.vinsert();
                }
                break;

      case 4 :  if(g.vqempty())
               cout<<"Nothing is purchased"<<endl<<endl;
             else
             {
               g.vdisplay();
             }
             break;
      }

   }while(ch<5);
cout<<"Thank you for shopping........Visit again"<<endl;
return 0;
}

/*
 OUTPUT:
Fruit an vegetable Market
-------------------------
1.Add Fruit to shopping cart
2.Display fruit purchase order
3.Add Vegetable to shopping cart
4.Display vegetable purchase order
5.Exit
-------------------------
Enter your choice = 1
enter the fruit name
apple
enter the number of apple to be purchased
6
enter the price
120
fruits added to the cart

Fruit an vegetable Market
-------------------------
1.Add Fruit to shopping cart
2.Display fruit purchase order
3.Add Vegetable to shopping cart
4.Display vegetable purchase order
5.Exit
-------------------------
Enter your choice = 3
enter the vegetable name
potato
enter the number of potato to be purchased
24
enter the price
100
vegetables added to the cart

Fruit an vegetable Market
-------------------------
1.Add Fruit to shopping cart
2.Display fruit purchase order
3.Add Vegetable to shopping cart
4.Display vegetable purchase order
5.Exit
-------------------------
Enter your choice = 2
The Purchase order is as below:

Count Fruit
----------------
 6   apple

Fruit an vegetable Market
-------------------------
1.Add Fruit to shopping cart
2.Display fruit purchase order
3.Add Vegetable to shopping cart
4.Display vegetable purchase order
5.Exit
-------------------------
Enter your choice = 4
The Purchase order is as below:

Count vegetables
----------------
 24   potato

Fruit an vegetable Market
-------------------------
1.Add Fruit to shopping cart
2.Display fruit purchase order
3.Add Vegetable to shopping cart
4.Display vegetable purchase order
5.Exit
-------------------------
Enter your choice = 5
Thank you for shopping........Visit again

 */

No comments:

Post a Comment