| | |
Trouble writing code for arithmetic calculations of complex numbers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
paste your code inside code tags instead of attaching the sourcefiles. M
Makes it a lot easier for everyone to see what you're talking about.
And posting your assignment verbatim doesn't help either (but at least you're honest stating it's a school assignment
).
Now for a bit of help to get you started.
I've yesterday for fun and training (I've been more or less out of C++ for years, starting to get pretty rusty) created a class that does addition and subtraction of complex numbers.
The rest you can easily think up to do yourself, they work similarly.
I'll not post the full implementation (which is pretty trivial) nor the test application (which is even more trivial), but the headerfile giving all function prototypes.
That should give you enough hints to get started implementing the system yourself.
you can of course include far more functionality than this, but this should be a good start.
Makes it a lot easier for everyone to see what you're talking about.
And posting your assignment verbatim doesn't help either (but at least you're honest stating it's a school assignment
).Now for a bit of help to get you started.
I've yesterday for fun and training (I've been more or less out of C++ for years, starting to get pretty rusty) created a class that does addition and subtraction of complex numbers.
The rest you can easily think up to do yourself, they work similarly.
I'll not post the full implementation (which is pretty trivial) nor the test application (which is even more trivial), but the headerfile giving all function prototypes.
That should give you enough hints to get started implementing the system yourself.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; class complexNumber { private: float real; // real part float imag; // imaginary part public: complexNumber(); complexNumber(float rPart, float iPart); ~complexNumber(); // for form's sake, not really needed complexNumber operator+(const complexNumber& c); // addition, so you can call 'c = a + b' where a,b, and c are complexNum objects complexNumber operator-(const complexNumber& c); // same for subtraction friend ostream& operator<<(ostream& s, const complexNumber& c); // so you can do for example 'cout << a' where a is a complexNumber object };
you can of course include far more functionality than this, but this should be a good start.
>they are required to have different argument lists
Or constness for member functions. The following introduces no ambiguity yet the return types and argument lists for the overloaded function are identical:
Or constness for member functions. The following introduces no ambiguity yet the return types and argument lists for the overloaded function are identical:
C++ Syntax (Toggle Plain Text)
#include <iostream> using std::cout; using std::endl; class test { public: void f() { cout<<"f()"<<endl; } void f() const { cout<<"f() const"<<endl; } }; int main() { test t; const test s; t.f(); // Will print f() s.f(); // Will print f() const }
I'm here to prove you wrong.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Editing a file
- Next Thread: bit of help with please :)
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






