Classes in C++

One of my examples for my students


Category: C++ Programming Tags: C++ Programming, VC++

/* 
 * File:   main.cpp
 * Author: ale
 *
 * Created on 4 ottobre 2013, 17.39
 */

#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

class numcomp
{
    double re;
    double im;
   public:
   numcomp(double r, double i)
       {
       re = r;
           im = i;
                  }

           double reale()
          {return re;};
          double immag()
          {return im;};
         
          double modulo()
          {
              double mq = re*re+im*im;
              double m = sqrt(mq);
              return m;
          };
         
          double fase()
          {
              double f = atan(im/re);
              return f;
          };
      
};

int main(int argc, char** argv) {
    numcomp z(2.2, 3.5);
   
    cout<<"Complex number Z:"<<z.reale()<<"+iota "<<z.immag()<<"\n";
    cout<<"ABS of Z is: "<<z.modulo()<<"  phase: "<<z.fase();
    return 0;
}

Like 1 Person
Published on 2 December 2013
alex

alex
Atricles: 2
Questions: 0
Given Best Solutions: 0 *

Reference:

Myself

Comments:

alex
It's nice to notice that C++ resembles so much Classic ASP and ASP.NET, in including libraries above all, It's parents of modern languages and technologies
Like 1 Person on 10 December 2013

You are not loggedin, please login or signup to add comments:

Existing User

Login via:

New User



x