Labels

Thursday 25 June 2015

Fruitmall Management Program

#include<iostream> 
using namespace std; 
#include<string.h> 
#include<stdlib.h> 
 class mall{ 
        int front,rear; 
        struct item{ 
        int size; 
        char name[10]; 
        }st[10]; 
    public: 
        mall(); 
        void insert(char[],int); 
        void disp(int); 
        }; 

mall::mall(){ 
        cout<<"****************************Welcome**************************\n"; 
        cout<<"Have fun while shopping with fruits and Vegetables available\n"; 
        front=rear=-1; 
    } 


int main(){ 
        mall m; 
        int type,famt,vamt; 
        char ftype[10]; 
        char vtype[10]; 
        while(1){ 
           cout<<"We have following kind of varieties here sir.... Which One!\n"; 
        cout<<"1.Fruits\t\t2.Vegetables\t\t3.Exit\n"; 
        cin>>type; 
        switch(type){ 
            case 1: 
                cout<<"We have following types of Fruits available...What u prefer...How much(in KG)\n"; 
                cout<<"1.Apple\t2.Banana\t3.Mango\t4.Guava\n"; 
                cout<<"Enter ittem name"; 
                cin>>ftype>>famt; 
                m.insert(ftype,famt); 
                break; 

            case 2: 
                cout<<"We have following types of Vegetables available...What u prefer...How much(in KG)\n"; 
                    cout<<"1.Potato\t2.Tomato\t3.Brinjal\t4.Pea\n"; 
                cout<<"Enter vegetable name"; 
                cin>>vtype>>vamt; 
                m.insert(vtype,vamt); 
                break; 

            case 3: 
                exit(0); 
                break; 

            default: 
                cout<<"Invalid choice...Plz. try again"; 
                break; 
            } 
        } 

return 0; 
        } 
void mall::insert(char type[10],int amt){ 
    int t; 
    if(front==-1) 
        front++; 
    t=rear; 
    while(t>=0&&amt<st[t].size) 
    { 
          st[t+1].size=st[t].size; 
          strcpy(st[t+1].name,st[t].name); 
        t--; 
    } 
    st[t+1].size=amt; 
    strcpy(st[t+1].name,type); 
    rear=rear+1; 
    disp(rear); 


void mall:: disp(int size){ 

    int i; 
    cout<<"Your till now Collection is\n"; 
    for(i=0;i<=size;i++) 
        cout<<"\t\t"<<st[i].name<<"\t\t"<<st[i].size<<"\n";