Define a class for complex numbers. A complex number is a number of the form a + bi, where a and b are double type data and I is a number that represents the quantity √-1. Class name is Complex. Name the private member variables real and imaginary. Default constructor that initializes an object to 0 (that is, 0 + 0i) Constructor with two parameters Other functions (See next slide)

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

Use C++

#include<iostream>
using namespace std;
class Complex
{
public:
};
Complex(); // set both real and imaginary to e
Complex (double, double);
Complex addition (const Complex&);
Complex subtraction (const Complex&);
Complex multiplication (const Complex&);
private:
Complex.h
You should write Complex.cpp and main
code separately.
double getReal() { return real; }
double getImaginary() { return imaginary; }
void print();
double real;
double imaginary;
Sample outputs
CLASS
Enter real and imaginary number for el: 24
Enter real and imaginary number for cl: 39
c1 = 2 + 4i
c2 = 3 + 91
Sum
Subtraction
: 5+131
-1-51
Multiplication : -30 + 301
Enter real and imaginary number for cl: -27
Enter real and imaginary number for el: 3 10
c1 = -2 + Ti
c2 = 3 + 101
: 1+ 171
Sum
Subtraction
: -5 + -3i
Multiplication: -76 + 1i
Transcribed Image Text:#include<iostream> using namespace std; class Complex { public: }; Complex(); // set both real and imaginary to e Complex (double, double); Complex addition (const Complex&); Complex subtraction (const Complex&); Complex multiplication (const Complex&); private: Complex.h You should write Complex.cpp and main code separately. double getReal() { return real; } double getImaginary() { return imaginary; } void print(); double real; double imaginary; Sample outputs CLASS Enter real and imaginary number for el: 24 Enter real and imaginary number for cl: 39 c1 = 2 + 4i c2 = 3 + 91 Sum Subtraction : 5+131 -1-51 Multiplication : -30 + 301 Enter real and imaginary number for cl: -27 Enter real and imaginary number for el: 3 10 c1 = -2 + Ti c2 = 3 + 101 : 1+ 171 Sum Subtraction : -5 + -3i Multiplication: -76 + 1i
Define a class for complex numbers. A complex number is a number of
the form a + bi, where a and b are double type data and I is a number
that represents the quantity √-1.
Class name is Complex.
Name the private member variables real and imaginary.
Default constructor that initializes an object to 0 (that is, 0 + 0i)
Constructor with two parameters
Other functions (See next slide)
Transcribed Image Text:Define a class for complex numbers. A complex number is a number of the form a + bi, where a and b are double type data and I is a number that represents the quantity √-1. Class name is Complex. Name the private member variables real and imaginary. Default constructor that initializes an object to 0 (that is, 0 + 0i) Constructor with two parameters Other functions (See next slide)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Software Development
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT