Friday, 3 January 2014

Operator overloading

The ability to create new meaning to an existing operator is called operator overloading.Various operators involved in operator overloading are:

  • Mathematical operators like +,-,*,/,% 
  • Relational operators like <,>,<=,>=,!=
  • Logical operators like &&,||,!
  • Access operator  like [,],->
  • Assignment operator  =
  • Stream I/O operator <<,>>
Operators that can't be overloaded:
  1. Scope resolution operator
  2. Sizeof operator
  3. Conditional operator
  4. Dereference operator
Syntax for operator overloading:

Return_type class_name :: operator operator_to_be_overloaded(argument list)

Example: void sample::operator ++()
{
         //statement;
}

Operator overloading can be classified into two types:

  • Unary operator overloading
  • Binary operator overloading
Program for Unary operator overloading:
#include<iostream.h> 
          #include<conio.h>
         class sample
         {
              private:
                        int val1,val2;
              public:
                       sample(int x,int y);
                       void operator ++();
                       void operator ++ (int x);
                       void display();
         };
        sample::sample(int x,int y)
        {
              val1=x;
              val2=y;
        }
        void sample::operator ++()
        {
             val1++;
            val2++;
         }
         void sample::operator ++(int x)
        {
             val1++;
             val2++;
        }
        void sample::display()
       {
            cout<<"\n value1"<<val1;
            cout<<"\nvalue2"<<val2;
        }
        void main()
        {
            sample s(10,20);
            cout<<"\nbefore overloading";
            s.display();
           ++s;
           cout<<"after overloading prefix form";
           s.display();
          s++;
          cout<<"after overloading postfix form";
          s.display();
      }

Destructor

Destructor:

Destructor is a special function used to remove the memory allocated by an constructor to an object.It gets executed ,when the object gets deleted.

Syntax:

~Class_name()
{
        //body of destructor
}

Example:
~sample()
{
    delete v;
}

Program to illustrate the use of destructor:

#include<iostream.h>
#include<conio.h>
class sample()
{
   private:
         int a;
   public:
         sample()
         {
                     i=1;
                     cout<<"Object<<i<<created"
                     i++;
         }
          ~sample()
         {
                  cout<<"object gets deleted";
                  i--;
          }
};
void main()
{
      sample s;
      getch(0;
}
    

How to start and save a cpp program

A normal cpp program can  be written in either turbo c or c++ editor.To download Turbo c or c++ editor click the link below

Download turbo c++

To create a new file in c++ editor, Click on file->new.
To open a file click on file->open or press F3.

To save a cpp file click on file->save or press F2.A cpp file must be saved with the extension .cpp

Example: sample.cpp.

Thursday, 19 December 2013

Mini project ideas

Here, I'm going to share some mini project ideas under different platforms or frameworks.

ASP.NET MINI PROJECTS:

Online shopping website
Hotel/restaurent  food order systems
Payroll system
Digital document management system
E-blogs
Expert system data entry
Fetching host system name and IP address
Car rental website code


VB.NET MINI PROJECTS:
Financial management system
Greatest shutdown manager
LAN messenger
Cricket project
Notepad clone
Multiple company payroll system
ATM management system
Appointments calendar
Data transfer system

JAVA MINI PROJECTS:
Scrabble game source code
Facebook like chat application project
Bank account monitoring
Airline booking system
Students website code
Puzzle games

C/C++ MINI PROJECTS:
Wireless patient pulse rate and temperature system
Simple search engine using c or c++
Student report card system
Snake and ladder games
Result management

Free recharge

Many online sites have been giving free recharges.To earn free recharge, click the link below and to that site and register and earn free recharge by playing quiz,sending SMS, and referring your friends.The minimum payout is RS.10

Ultoo
Way2sms
Pickzup
ypox
Amulyam
Spice2mail

Wednesday, 18 December 2013

Oops with c+

Constructors:
       Constructors are the special functions that has the same name as that of class.They are used to initialize the class objects.When an object is created,the constructor function begins to be executed.
There is no need to call the function.

Syntax:
class_name()
         {
         
               //Body of constructor
          }


Types of constructors:
  • Default constructors
  • Parameterised constructor
  •  Copy constructor
Default constructor:

The constructor which doesn't have any arguments is called as default constructor.
Example:

sample()
{

}
Parameterised constructor:

The constructor which has arguments is called as parameterised constructor.A call to such a constructor can be done by creating objects with some values.

Example:

sample(int x,int y)
{


}

Copy constructor:
  A copy  constructor can be identified by ampersand symbol.

Syntax:
Class_name(class_name &obj)
{
       //body of constructor
}
Example:
sample(sample &s)
{

         //Body of constructor
}

Sample program to illustrate different types of constructors:

#include<iostream.h>
#include<conio.h>
class sample
{
     private:
          int a,b;
     public:
            /*Default constructor*/
             sample()
             {
                 a=0;
                 b=0;
              }
              /*Parameterised constructor*/
              sample(int x,int y)
              {
                     a=x;
                     b=y;
              }

};
void main()
{
    sample s(10,20);
    int c;
   c=a+b;
   cout<<"The addition is"<<c;
   getch();
}

Sample output:
The addition is 30


 
 




Monday, 16 December 2013

Oops with c++

Functions:

Functions are generally the building blocks of a program.The starting point to any function is the main.A normal function can have three parts namely
  • Declaration section
  • Definition section 
  • Calling section
General syntax:
   <data_type><function_name><arguments>
Example:
  void fun() 
 Declaration section:

            Declaration section of a function is optional.(i.e)The user can declare the function in a class and define it in outside the class, or the user can directly define the function inside the class itself.

Example:
class sample
           {
                   private:
                        int num;
                   public:
                    /* Declaration part*/
                           void getdata();
                           void showdata();
           } 
Definition section:

A function can be defined either inside or outside the class.when a function declared inside a class, it must defined using a scope resolution operator.This operator reveals the scope of a variable or a function.

Example 1:

class sample
          {
                   private:
                           int age;
                   public:
                          void getdata()
                          {
                                cout<<"enter age":
                                cin>>data;
                            }
                            void showdata()
                             {
                                    cout<<"AGE:"<<age;
                              }
               };
Example 2:
                class sample
                {
                        private:
                                   int age;
                        public:
                               /*Declaring the function*/
                                void getdata();
                                void showdata();
                 };
                 /*Defining the function outside the class*/
                void sample::getdata()
                {
                      cout<<"enter age";
                      cin>>age;
                 }
                void sample::showdata()
                {
                    cout<<"age:"<<age;
                 }        
Calling functions:
When the function declared and defined,it must be called in main function,otherwise the function will not be executed.
Example:
 class sample
                {
                        private:
                                   int age;
                        public:
                               /*Declaring the function*/
                                void getdata();
                                void showdata();
                 };
                 /*Defining the function outside the class*/
                void sample::getdata()
                {
                      cout<<"enter age";
                      cin>>age;
                 }
                void sample::showdata()
                {
                    cout<<"age:"<<age;
                 }        
                           void main()
                           {
                                  /*object declaration*/
                                  sample s;
                                  /*calling function*/
                                   s.getdata();
                                   s.showdata();
                            }
Various types of functions:
  • Passing nothing and returning nothing 
  •  Passing parameters and returning nothing
  • Passing parameters and returning something
Parameters are something that is given inside the brackets.parameters are the channel through which data flows  from call statement to function and vice versa.
Passing nothing and returning nothing:
      
         #include<iostream.h>
         #include<conio.h>
          class sample
           {
                        private:
                                   int age;
                        public:
                               /*Declaring the function*/
                                void getdata();
                                void showdata();
      };

      /*Defining the function outside the class*/
       void sample::getdata()
       {
                      cout<<"enter age";
                      cin>>age;
        }
         void sample::showdata()
         {
                    cout<<"age:"<<age;
          }        
                   void main()
                   {
                        /*object declaration*/
                          sample s;
                          /*calling function*/
                           s.getdata();
                            s.showdata();
             } 
Passing parameters and returning nothing:
      
#include<iostream.h>
#include<conio.h>
void sum(int x,int y) //Passing parameters
{
        int z;
        z=x+y;
        cout<"Addition is"<<z;
}
void main()
{
    int a,b;
    cout<<"enter two numbers";
    cin>>a,b;
    sum(a,b); //calling functions
}

Sample output:
enter two numbers
2 4
Addition is 6

Passing parameters and returning something:

#include<iostream.h>
#include<conio.h>
int sum(int a, int b) //passing parameters
{
     int c=a+b;
     return c;
}
void main()
{
    int a,b,c;
    int sum(int,int);
    cout<<"Enter two numbers";
    cin>>a>>b;
    c=sum(a,b); //calling function
    cout<<C;
}

Sample output:
Enter two numbers
4 6
10