Computing.Net > Forums > Programming > urgent Programming questions in C++

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

urgent Programming questions in C++

Reply to Message Icon

Original Message
Name: Jay-Fu
Date: August 17, 2002 at 17:04:43 Pacific
Subject: urgent Programming questions in C++
Comment:

I have to design, implement, and test a complex number class that represents the real and imaginary parts as double-precision values(data type double) and provides at least the following operatios:

1. Constructors for explicit as well as default initialization. The default initial value should be (0,0 0,0).
2. Arithmetic operations that add, subtract, multiple, and divide two complex numbers. These should be implemented as value-returning functions, each returning a class object.
3. A complex absolute value operation.
4. Two observer operations, “RealPart and ImagPart”, That return the real and imaginary parts of a complex number.

I am a newbee with c++, and don't know if I'm coding it in the right direction. CAN ANYONE HELP: HERE IS MY CODE:

//MAIN.CPP//
#include
#include"Complex.h"

using namespace std;


int main()
{


//Instantiate 4 Complex objects using parameter constructor//

Complex a(2,3);
Complex b(-8,10);

Complex result;

// Checks to see if values are present//

cout

using namespace std;


class Complex
{

public:

//constructors//
Complex(); //default constructor
Complex(double a, double b);
Complex(double value);
Complex(const Complex& a);


//Get and set Methods//

double getValue() const;
double setValue(double value);

~Complex();


//Math Methods//


//Add objects of type complex and return the result//

Complex add(const Complex& a);

//Subtract objects of type complex and return the result//

Complex subtract(const Complex& a);

//Multiply with objects of type complex and return the result//

Complex multiply(const Complex& a);

//Division with objects of type complex and return the result//

Complex divide(const Complex& a);

private:

double myReal;
double myIm;

};
#endif


//Complex.cpp//

#include"Complex.h"

//Default Constructor//

Complex::Complex(double a ,double b)
{
myReal=a;
myIm=b;
}


//Constructors with parameter//

Complex::Complex(double value) //Conversion Constructor//
{
myReal=value;
myIm=value;
}


//Copy Constructor//

Complex::Complex(const Complex& a)
{
myReal=a.getValue();
myIm=a.getValue();
}

//Destructor//

Complex::~Complex()
{
}


//GetValue//


double Complex::getValue() const
{
return myReal;
return myIm;
}

//SetValue//

double Complex::setValue(double value)
{
myReal=value;
myIm=value;
}

//Operations//


Complex Complex::add(const Complex& a)
{

Complex result;
result.setValue(myReal+a.getValue());

return result;

}



Report Offensive Message For Removal








Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software