class example 1 in c++

#include<iostream.h>
#include<conio.h>
class complex
{
  float x,y;
  public:
    complex() { }
    complex(float a) {x=y=a;}
    complex(float real,float imag)
    {x=real;y=imag;}
    void show()
    {
    cout<<x<<"+j"<<y;
    }
    void sum(complex,complex);
};
void complex::sum(complex c1,complex c2)
{
    x = c1.x + c2.x;
    y = c1.y + c2.y;
}
void main()
{
clrscr();
complex A(8.7,2.5);
complex B(2.6);
complex C;
clrscr();
C.sum(A,B);
C.show();
getch();
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|