Electricity Bill Generator Project in C++

C++ project on Electricity Bill Generator:

☝This project does not include file handling so it does not store the data gathered as input permanently. The data
stored gets destroyed as the program ends.

#include<iostream>

using namespace std;

class EBill

     {

       private:

        string name;

        protected:

        unsigned int acc;

       public:

        void input()

             {

              cout<<"\nEnter ur name::"; 

  cin>>name;

              cout<<"\nEnter ur account no::"; cin>>acc;

             }

        void display()

             {

             cout<<"\nUr name is::"<<name<<endl;

             cout<<"\nUr acc_no is::"<<acc<<endl;

             }

     };

class poor: public EBill

{

       private:

          unsigned int unit;

       public:

        void amountp()

         {    

  input();

          cout<<"\nEnter the amount of units consumed::";

          cin>>unit;

         }

        void displayp()

         {

         display();

        float k=(unit*4);

        float l=(float)15/100 ;

        float n=(float)k*l;

        float h=(k-n);

        cout<<"\nTotal bill in taka is::"<<h;

         }

         int searchp(unsigned int a)

         {

        if(a==acc)

         {

         displayp();

         return 1;

         }

         else return 0;

         }

};

class mid: public EBill

{

       private:

          float unit;

       public:

        void amountm()

         {

          input();

          cout<<"\nEnter the amount of electricity::";

          cin>>unit;

         }

        void displaym()

         {      display();

        float k=(unit*4);

        float l=(float)5/100 ;

        float n=(float)k*l;

        float h=(k-n);

        cout<<"\nTotal bill in taka is::"<<h;

         }

           int searchm(unsigned int b)

         {

        if(b==acc)

         {

         displaym();

         return 1;

         }

         else

         return 0;

         }

};

         class rich: public EBill

{

       private:

          float unit;

       public:

        void amountr()

         {    input();

          cout<<"\nEnter the amount of electricity::";

          cin>>unit;

         }

        void displayr()

         {      display();

        float k=(unit*4);

        cout<<"\nTotal bill in taka is::"<<k;

         }

           int searchr(unsigned int c)

         {

        if(c==acc)

         {

         displayr();

         return 1;

         }

         else return 0;

         }

};

        int main()

{

         float ac;

         int i,n,j,k,l,a;

        poor p;

        mid m;

        rich r;

    while(1)

   {

        cout<<"\nTHE PROJECT OF ELECTRIC BILL\n****************************";

        cout<<"\n\n\n1)input\n2)display\n3)search\n4)exit: "<<endl<<endl;

        char c;

        cout<<"Enter choice: ";

        cin>>n;

               switch(n)

               {

              case 1:

            /* cout<<"\nHow many input do u want ? \n";

              cin>>j;

              for(i=0;i<j;i++)

             {*/

           cout<<"\nGive p for poor,r for rich,m for mid class";

                cin>>c;

                 if(c=='p')

            p.amountp();

                 if(c=='m')

            m.amountm();

                 if(c=='r')

            r.amountr();

              break;

              case 2:

                if(c=='p')

              p.displayp();

                if(c=='m')

              m.displaym();

                if(c=='r')

              r.displayr();

              break;

              case 3:

                  cout<<"\nGive account no ";

                  cin>>ac;

                  if(c=='p')

                   {

                   p.searchp(ac);

                    if(a==1)

                    break;

                   }

                  if(c=='m')

                   {

                   m.searchm(ac);

                    if(a==1)

                    break;

                   }

                  if(c=='r')

                   {

                    r.searchr(ac);

                    if(a==1)

                    break;

                   }

                   break;

              case 4:

              break;

              default:

              cout<<"\nInvalid option\n";

              break;

               }

           if(n==4)

           break;

        }

       return 0;

}


Copy paste the code in your Compiler and see the code working.

Comments

  1. I m learning c++
    But i can easily understand ur code
    Osssm😄😄😄

    ReplyDelete

Post a Comment

Popular posts from this blog

Virtual function in c++

Multiple, Multilevel, Hybrid and Hierarchical inheritance

Practice problem classes and objects.