Monday, 17 October 2011

DEPARTMENTAL STORE BILLING SYSTEM


PROGRAM:
//DEPARTMENTAL STORE BILLING SYSTEM
#include<iostream.h>
#include<conio.h>
#include<string.h>
class store                                //defining class for total stock in store
{
            int id,qt,pr,tot;                         //initializing the variables
            char prname[50];                     //private data members
            public:
                        void getdata(int i)                             
                        {
                        cout<<"\nEnter id for product "<<i+1<<"\t";        //getting product id
                        cin>>id;
                        cout<<"\nEnter name for product "<<i+1<<"\t";  //getting product name
                        cin>>prname;
                        cout<<"\nEnter quantity of product "<<i+1<<"\t";  //getting total quantity
                        cin>>qt;
                        cout<<"\nEnter price for product "<<i+1<<"\t";    //getting total price
                        cin>>pr;
                        }
                        void disp()                       //display function definition
                        {
                                    cout<<"\n"<<id<<"\t"<<prname<<"\t"<<qt<<"\t\t"<<pr<<"\n";
                        }
            friend class admin;                //making admin & customer class as a friend to this class
            friend class customer;


}s[10];                                 //object creation
class admin                          //declaring administrator class
{
            public:
            int ch,a,qty,id1,b,prn;                                      //declaring its data members
            char c[50];
            public:
            void modify(short int n)                       //definition for modify function
            {
                        do  
                        {
                        cout<<"1.ID NUMBER\t2.PRODUCT NAME\t3.QUANTITY\t4.PRICE\n5.EXIT\n";
                        cin>>a;                                                            //implementing menu driven manner
                        switch (a)
                        {
                                    case 1:
                                    {
                                    cout<<"\nEnter product's serial number:\t:"; //getting product details
                                    cin>>b;
                                    cout<<"\nEnter new id number:\t:";
                                    cin>>id1;
                                    s[b].id=id1;                        //overwriting new id on previous id
                                    break;
                                    }
                                   


case 2:
                                    {
                                    cout<<"\nEnter product's serial number:\t:";  //getting product details
                                    cin>>b;
                                    cout<<"\nENTER NEW PRODUCT NAME\t:t";
                                    cin>>c;
                                    strcpy(s[b].prname,c);            //overwriting old name by new name
                                    break;
                                    }
                                    case 3:
                                    {
                                    cout<<"\nEnter product's serial number:\t:";   //getting product details
                                    cin>>b;
                                    cout<<"\nEnter quantity of "<<s[b].prname<<"\t:";
                                    cin>>qty;        
                                    s[b].qt=qty;    //overwriting old quantity by new quantity
                                    break;
                                    }
                                    case 4:
                                    {
                                    cout<<"\nEnter product's serial number:\t:"; //getting product details
                                    cin>>b;
                                    cout<<"\nEnter the price of "<<s[b].prname<<"\t:";
                                    cin>>prn;
                                    s[b].pr=prn;                        //overwriting old price by new price
                                    break;
                                    }
                        }
                        }while(a<5);
            for(int k=0;k<n;k++)
            {
            s[k].disp();                //invoking display function
            }
            }

}ad;
class customer                 //defining customer class
{
            int cus1,tot,j;                
            char cus[50],a[5];             //declaring varirables               
            public:
            void purchase(short int n)              //definition for purchase function
            {
               do
               {
               cout<<"\nEnter product's name";       //getting product name
               cin>>cus;
               for(j=0;j<n;j++)
               {
                        if(strcmp(cus,s[j].prname)==0)             //checking every product available
                        {
                           cout<<"\nEnter the total quantity you wish to buy\t:";
                           cin>>cus1;
                           if(s[j].qt>=cus1)
                           {
                                   
tot=cus1*s[j].pr;                //calculating total amount
                                    s[j].qt=s[j].qt-cus1;
                                    cout<<"\nTOTAL COST FOR "<<cus1<<" "<<s[j].prname<<" = "<<tot;
                           }
                           else
                           {
                           cout<<"\nSorry only "<<s[j].qt<<" pieces of "<<s[j].prname<<" are available\n";
                           }
                        }
                        else
                        {
                                    cout<<"\nINVALID PRODUCT NAME\n";
                        }
                        }
                        cout<<"\nDo you wish to leave \n";
                        cin>>a;
               }while(strcmp(a,"yes")!=0);
                         for(int k=0;k<n;k++)
                        {
                        s[k].disp();                               //invoking display function
                        }
            }
}c;
void main()
{
             short int i,n,ch;                       //declaring varirables
             char pass[10],cl[10];
             strcpy(pass,"skcet");
             clrscr();
             cout<<"$$$$$$$$ SKCET DEPARTMENTAL STORE $$$$$$$$$";
             cout<<"\nEnter the total number of products\t:\t";     //getting total no. of products in the store
             cin>>n;
             for(i=0;i<n;i++)
             {
                        s[i].getdata(i);                            //calling getdata function obj by obj using loop
             }
             cout<<"ID NO\tNAME\tQUANTITY\tPRICE\n";
             for(i=0;i<n;i++)
             {
                        s[i].disp();        //calling getdata function obj by obj using loop
             }
             do
             {
             cout<<"\n1.OWNER\n2.CUSTOMER\n";
             cin>>ch;
             switch (ch)
             {
                        case 1:
                        {
                        cout<<"\nENTER PASSWORD\n";
                        cin>>pass;
                        if(strcmp(pass,"skcet")==0)    //checking administrator password
                        {
                        ad.modify(n);          //calling modify function
                        }
                        break;
                        }
                        case 2:
                        {
                        c.purchase(n);          //calling purchase function
                        break;
                        }
             }
                        cout<<"\nDO YOU WISH TO CLOSE STORE";
                        cin>>cl;
                        }while(strcmp(cl,"YES")!=0);
             cout<<"ID NO\tNAME\tQUANTITY\tPRICE\n";

             for(i=0;i<n;i++)
             {
                        s[i].disp();                   //calling  display function obj by obj using loop

             }
             getch();
}


OUTPUT:
$$$$$$$$ SKCET DEPARTMENTAL STORE $$$$$$$$$
Enter the total number of products      :       3
Enter id for product 1  100
Enter name for product 1        PEN
Enter quantity of product 1     15
Enter price for product 1       10
Enter id for product 2  101
Enter name for product 2        PENCIL
Enter quantity of product 2     10
Enter price for product 2       5
Enter id for product 3  102
Enter name for product 3        SCALE
Enter quantity of product 3     20
ID NO   NAME    QUANTITY        PRICE
100     PEN     15              10
101     PENCIL  10              5
102     SCALE   20              8
1.OWNER
2.CUSTOMER
1
ENTER PASSWORD
SKCET
DO YOU WISH TO CLOSE STORENO
1.OWNER
2.CUSTOMER
1
ENTER PASSWORD
skcet
1.ID NUMBER     2.PRODUCT NAME  3.QUANTITY      4.PRICE
5.EXIT
1
Enter product's serial number:  :0
Enter new id number:    :200
1.ID NUMBER     2.PRODUCT NAME  3.QUANTITY      4.PRICE
5.EXIT
2
Enter product's serial number:  :1
ENTER NEW PRODUCT NAME  :tink
1.ID NUMBER     2.PRODUCT NAME  3.QUANTITY      4.PRICE
5.EXIT
3
Enter product's serial number:  :2
Enter quantity of SCALE :10
1.ID NUMBER     2.PRODUCT NAME  3.QUANTITY      4.PRICE
5.EXIT
4
Enter product's serial number:  :2
Enter the price of SCALE:12
1.ID NUMBER     2.PRODUCT NAME  3.QUANTITY      4.PRICE
5.EXIT
5


200     PEN     15              10
101     ink     10              5
102     SCALE   10              12
DO YOU WISH TO CLOSE STOREno
1.OWNER
2.CUSTOMER
2
Enter product's namerubber
INVALID PRODUCT NAME
Do you wish to leave to leave
NO
Enter product's namePEN
Enter the total quantity you wish to buy        :40
Sorry only 15 pieces of PEN are available
INVALID PRODUCT NAME
Do you wish to leave
NO
Enter product's namePEN
Enter the total quantity you wish to buy        :5
TOTAL COST FOR 5 PEN = 50
Do you wish to leave
yes
200     PEN     10              10
101     ink     10              5
102     SCALE   10              12


DO YOU WISH TO CLOSE STOREYES
ID NO   NAME    QUANTITY        PRICE
200     PEN     10              10
101     ink     10              5
102     SCALE   10              12

No comments:

Post a Comment