A constructor with no arguments (or parameters) is called the default constructor. If no such constructor is defined in a class, then the compiler supplies a default constructor at the time of creation of an object of the class. The syntax for default constructor is

class_name() { }
(e.g) complex() { x=0; y=0;}

Program:

#include<iostream>
#include<conio.h>
usage namespace std;

class complex
{
          int real;
          int imaginary;
     public:
          complex()
          {
              real=0;
              imaginary=0;
          }
     void getcomplex()
     {
          cout<<"\n enter a complex no:";
          cin>> real;
          cin>> imaginary;
     }
     void putcomplex(complex c1, complex c2)
     {
          cout<<"\n the sum of two complex numbers is ";
        cout<<c1.real+c2.real<<"+"<<c1.imaginary+c2.imaginary<<"i";
     }
};
void main()
{
     complex c1,c2;
     putcomplex(c1,c2);
     c1.getcomplex();
     c2.getcomplex()
     putcomplex(c1,c2);

}
Posted by Unknown On 23:54 No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *