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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

urgent Programming questions in C++

Reply to Message Icon

Name: Jay-Fu
Date: August 17, 2002 at 17:04:43 Pacific
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;

}




Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: urgent Programming questions in C++

Simple FTP program written in C. www.computing.net/answers/programming/simple-ftp-program-written-in-c-/7153.html

Simple design questions in C++ www.computing.net/answers/programming/simple-design-questions-in-c/4384.html

Programming Keyboard in C www.computing.net/answers/programming/programming-keyboard-in-c/2283.html