Powered by Blogger.

Tuesday, February 5, 2013

add complex numbers

/*q.N 3.Write a program to add complex numbers of two different classes using friend class */
#include<iostream.h>
#include<conio.h>

class mula;
class aalu;
class gajar
{
      private:
              float realp,imagp;
              public:
                     void getdata();
                     //void show();
                     friend class mula;
                     };
                    
      void gajar::getdata()
      {
           cout<<"\nFor First Class \n";
           cout<<"\nEnter Real Part : ";
           cin>>realp;
           cout<<"\nEnter Imaginary Part : ";
           cin>>imagp;
           }
          
class aalu
      {
            private:
                    float realp,imagp;
                    public:
                           void getdata();
                           //void show();
                           friend class mula;
                           };
                    
      void aalu::getdata()
      {
           cout<<"\nFor Second Class \n";
           cout<<"\nEnter Real Part : ";
           cin>>realp;
           cout<<"\nEnter Imaginary Part : ";
           cin>>imagp;
           }
          
class mula
{
      private:
              float realp,imagp;
              public:
                     void add(gajar &g1,aalu &a1);
                     void display();
                     };
                    
             
      void mula::add(gajar &g1,aalu &a1)
      {
           realp=g1.realp+a1.realp;
           imagp=g1.imagp+a1.imagp;
           }
          
      void mula::display()
      {
           cout<<"\n*****************************\n";
           cout<<"\nThe Added Values Are : \n";
           cout<<"\n"<<realp<<" + i"<<imagp<<endl;
           }
          

int main()
{
    mula m;
    aalu a;
    gajar g;
   
    a.getdata();
    g.getdata();
    m.add(g,a);
    m.display();
    getch();
    return 0;
}
          
          
     
                    

0 comments:

Post a Comment