I need help getting started on this c++ assignment: using code:blocks: COMSC 48
ID: 3640511 • Letter: I
Question
I need help getting started on this c++ assignment:using code:blocks:
COMSC 48 -- Assignment 4
A complex number is one which takes the form: A + Bi (where i is a symbol, not an unknown). 'A' is called the 'real part' and 'B' is the 'imaginary part'. Complex number are used in higher mathematics, and can be added, subtracted, multiplied, output, compared, and negated, among other things. Please see the following website for further details: http://en.wikipedia.org/wiki/Complex_number
The following class Complex provides a way for a program to work with complex numbers.
Complex Number Class
The following UML diagram describes members of this class:
Complex
- real : int // real part
- imag : int // imaginary part
+ Complex( ) // 0 + 0i
+ Complex (re : int) // A + 0i
+ Complex (re : int, im : int) // A + Bi
+ operator + (right : const Complex&) : Complex //overloaded plus
+ operator - (right : const Complex&) : Complex //overloaded minus
+ operator * (right : const Complex&) : Complex //overloaded multiply
+ operator - () : Complex //overloaded unary minus
+ operator == (right : const Complex&) : bool //overloaded equals
+ &operator << (out : ostream&, right : const Complex&) : ostream //overloaded
//extraction operator
The constructors, +, -, - (unary), == and << are all overloaded so that you can do arithmetic, comparisons and output the objects.
COMMENTING A CLASS: Be sure that your class and all of your code is well commented.
Start your main program by using this code:
int main()
{
Complex first;
Complex second(-4);
Complex third(1,-2);
Complex fourth(-1,2);
Complex fifth(3,0);
Complex sixth(0,3);
Complex seventh(5,3);
Complex eighth(6,10);
Complex ninth(7,4);
Complex tenth(-14,8);
cout << endl;
if (third == fourth)
cout << "The complex numbers are equal." << endl;
else
cout << "They complex numbers are not equal." << endl;
if (first == first)
cout << "The complex numbers are equal." << endl;
else
cout << "They complex numbers are not equal." << endl;
if (first == third + fourth)
cout << "The complex numbers are equal." << endl;
else
cout << "They complex numbers are not equal." << endl;
/*
Then add the code necessary to match the solutions output. Do not create any new objects. Use must use the objects above and the operators defined by the Complex class to produce all of the output.
*/
return 0;
}
Explanation / Answer
Here ya go, in one part: #include using namespace std; class Complex { public: friend ostream& operatorRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.