All About C++

Get Pure Concepts of C++

Monday, 6 June 2016

C++ car parking management system

This is C++ car parking management system. The statement of car parking management system is:
There are three floors in a building and every floor has capacity of ten cars to park.one floor is for Civic, one for Accord and one for City. Whenever a car system should ask either it is civic, Accord or City and it should be park on its floor if there exists room.

#include<iostream>
using namespace std;
enum{M=10};
class park
{private:
int capacity[M];int front,rear,g;
public:
            park()
            {front=rear=-1;g=0;}
            void inpark()
            {if(rear==M-1)

Sunday, 5 June 2016

How to make copy constructor in C++,with code example

In copy constructor, we copy a constructor to another object. When we have to make a constructor with same values of attributes which another constructor have, then we use copy constructor technique.
I give an example code in C++ to understand copy constructor concept.

#include<iostream>
using namespace std;
class distancee
{ private:
int feet;

How to concatenate two or more strings of different objects in C++ with example code

In concatenation, we concatenate two or more strings together. Concatenation syntax in C++ is:
strcat(str1,str2);
Here:
str1 and str2 are two strings which are concatenated and the result is stored in left side’s string which is in above case is str1,so here result will be stored in str1.
Example Code:
In this example code strings which belong to two different objects are concatenated.

#include<iostream>
using namespace std;
#include<string>

Toll Plaza management system

                                                     This project is on toll plaza management, whenever any vehicle will pass the toll plaza, it has to pay tax. This system tell us that there are how many vehicles which have paid and how many such vehicles which don’t paid toll plaza tax.

#include<iostream>
using namespace std;
char a;
char b;
char c;
class sir
{
private:  
                unsigned int cars;
                unsigned int amount;
public:
                void az()
                {start:
                                cout<<"car payed amount or not press y/n"<<endl;
                cin>>b;
                if(b=='y')
                {cars=0;
                amount=0;
                asd:
                                cars=cars+1;
                                amount=amount+50;
                                cout<<"no. of cars is     "<<cars<<endl<<"total amount is    "<<amount<<endl;
                                cout<<"if car payed amount then press y otherwise n"<<endl;
                                cin>>a;
                                if(a=='y')
                                {goto asd;}
                }
                else
                {}
ab:
                cars=cars+1;
                cout<<"total cars are "<<cars<<endl<<"total amount is  "<<amount<<endl;
                cout<<"next car payed amount or not press y/n"<<endl;
                cin>>c;
                if(c=='y')
                {goto asd;}
                else
                {goto ab;}
                }
};
void main()
{
                sir yes;
                yes.az();
                cout<<endl;
                system("pause");
}




Saturday, 4 June 2016

C++ projects list

Bank management project 

bank management project in C++,very easy to understand code

This is C++ project on bank account management
All basic functions to manage bank account are added using class named by ‘bank’

#include<iostream>
    #include<stdio.h>
    #include<conio.h>
using namespace std;
class bank
    {
     private:
     int ac_no,account;
     float balance;
     char name[20];
     public:
     void open();
     void deposite(int i);
     void withdraw(int p);
     void search(int b);
     void display();  };
    void bank::open()
{ cout<<"ENTER YOUR NAME :  ";
         cin>>name;
         cout<<"ENTER YOUR ACCOUNT NUMBER :  ";
         cin>>account;
         cout<<"ENTER THE AMOUNT OF MONEY : BDT  ";
         cin>>balance;
     }
          void bank::deposite(int j)

    {  int bnc;
          if(account==j)
       {
        cout<<"ENTER THE AMOUNT OF MONEY : BDT ";
        cin>>bnc;
        balance=balance+bnc;
        cout<<"\n\n\tJOB HAS DONE WELL !!! \n";
       }  }
    void bank::withdraw(int k)
    {   int blnc,p;
      if(account==k)
      {
        cout<<"YOUR CURRENT ACCOUNT BALANCE IS BDT "<<balance<<"\n"<<"THE AMOUNT OF MONEY YOU WANT TO WITHDRAW IS BDT ";
        cin>>blnc;
           p=balance-blnc;
           { if(p<0)
              cout<<"SORRY !!! THERE IS NOT ENOUGH MONEY IN YOUR ACCOUNT\n";
            else if(p>=0)
              {
                cout<<"\n\tYOUR REQUEST TO WITHDRAW MONEY HAS DONE\n\n";
                balance=p;
              }    }   }  }
    void bank::display(void)
    {    cout<<"\n\nNAME : "<<name<<"\n\nACCOUNT NO. "<<account<<"\n\nBALANCE : BDT "<<balance<<"\n\n";
    }



    void bank::search(int m)

    {

     if(account==m)
       {
         cout<<"\n\n*******Account Holder's INFO*******";
         cout<<"\n\nNAME : "<<name<<"\n\nACCOUNT NO. "<<account<<"\n\nBALANCE : BDT "<<balance<<"\n\n";
         cout<<"\n***************************************\n\n";
       }

    }

       void main()
       {
      int i,j,k,m,l,y=0;
         bank b[20];
        int index;
          do
        {
    cout<<"\a\nPRESS 1 TO OPEN ACCOUNT\n\n"<<"PRESS 2 TO DEPOSITE AMOUNT\n\n"<<"PRESS 3 TO WITHDRAW MONEY \n\n"<<"PRESS 4 TO DISPLAY \n\n"<<"PRESS 5 TO SEARCH \n\n"<<"PRESS 6 TO EXIT \n\n\t\n";
    cout<<"Your option......";

    cin>>index;
               switch(index)
            {
               case 1:
                 cout<<"\nHOW MANY ACCOUNT YOU WANT TO OPEN?\n"; //opening account
                 cin>>y;
                  for(i=0;i<y;i++)
                b[i].open();
               break;
              case 2:
                 cout<<"\nENTER YOUR ACCOUNT NO. ";             //deposite amount
                 cin>>j;
                 for(i=0;i<y;i++)
                  {
                    b[i].deposite(j);
                  }
              break;
              case 3:
                cout<<"\nENTER YOUR ACCOUNT NO. ";              //withdraw money
                cin>>k;
                for(i=0;i<y;i++)
                   {
                   b[i].withdraw(k);
                   }
                break;

              case 4:
                for(i=0;i<y;i++)
                  {                                             //display option
                  b[i].display();
                  }
                break;
              case 5:
                cout<<"\nENTER YOUR ACCOUNT NO. ";              //search option
                cin>>m;
                 for(i=0;i<y;i++)
                {
                b[i].search(m);
                }
                 break;
             case 6:
             break;

                default:cout<<"\nYOU HAVE PRESSED THE WRONG KEY. PLEASE TRY AGAIN. \n\n\n";
                break;
                                                   }}
                while(index!=6);
                                                                system("pause");}


How to pass objects as parameters in the function with code example

We can pass objects as parameter in the functions.to use objects as parameter, we just pass the object’s name as in the case of array.
Let a1 and a2 are two objects and “add” is a function name then we will pass these objects as parameters as
add(a1,a2);
When we make function to pass objects as parameter then the data types of function attribute must be the name of that class in which we are making that function.
I explain this concepts using a complete code example
This code add, subtract and multiply two objects values

#include<iostream>
#include<math.h>
using namespace std;
class complex
{
private:
            float real;
            float imaginary;
public:
            complex():real(0),imaginary(0)
            {}
complex(float re,float im):real(re),imaginary(im)
{}
void add(complex a,complex b)
{float z;
            float x,y,k;
            z=a.real+b.real;
            x=-(a.imaginary);
            y=-(b.imaginary);
            k=sqrt(x)+sqrt(y);
            cout<<endl<<"addition is  "<<z<<"+"<<k<<"i"<<endl;
}
void subtruct(complex s,complex w)
{float z;
            float x,y,k;
            z=s.real-w.real;
            x=-(s.imaginary);
            y=-(w.imaginary);
            k=sqrt(x)-sqrt(y);
            cout<<endl<<"subtrucrtion is  this"<<endl<<z;
if(k>=0)
{cout<<"+"<<k<<"i"<<endl;}
else
{cout<<"-"<<k<<"i"<<endl;}}
void product(complex f1,complex f2)
{float z;
            float x,y,k,o,t,r1,r2;
            z=f1.real*f2.real;
            x=-(f1.imaginary);
                        y=-(f2.imaginary);
                        k=(f1.real)*(sqrt(y));
                        o=(f2.real)*(f1.imaginary);
                        t=x*y;
                        r1=z+t;
                        r2=k+o;
                        cout<<endl<<"production is this   "<<r1;
                        if(r2>=0)
                        {
                                    cout<<"+"<<r2<<endl;}
                        else
                        {cout<<"-"<<r2<<endl;}}
void getdata()
{
cout<<"enter real and imaginary  ";
            cin>>real>>imaginary;}
};
void main()
{
             complex i(12.2,-25.3);
            complex e1,e2,e3,e4;
            e1.getdata();
            e2.add(i,e1);
            e3.subtruct(i,e1);
            e4.product(i,e1);
             system("pause");}

Here:
void add(complex a,complex b);
void subtruct(complex s,complex w);
void product(complex f1,complex f2);

These are the function declaration method to use objects as parameters and here complex is the name of class in which these functions are made.

And
            e2.add(i,e1);
            e3.subtruct(i,e1);
            e4.product(i,e1);
Here functions are called in which objects are passed as parameters;
Here i, e1, e2 and e3 are objects names.