subject

C++. Hlp please! my last point((( Disassemble the program.
The main idea of ​​the template is to separate data and function (algorithm) and customize each of them separately, if necessary.

#include
using namespace std;

template
class Complex {
private:
T r, m; // x = Re + Im*i
public:
Complex(T nr = 0, T nm = 0) : r(nr), m(nm) { }
Complex operator+= (const Complex & c);
};

template
Complex Complex ::operator+= (const Complex & c) {

r += c. r;
m += c. m;
return *this;
}

template
Complex operator+ (const Complex & c1, const Complex & c2) {
Complex x = c1;
return x += c2;
}

int main(){

Complex<> a(0, 0), b(2, 2), c(7, -5);

Complex<> r1 = a + b + c;

Complex<> r2 = a;
r2 += b;
r2 += c;

return 0;
}

Exercise 1.1.
Try to create complex numbers based on the described template with real and imaginary parts represented by floating point numbers (float, double) and symbols (char).
Make any necessary changes to the implementation of the addition operators. Concatenation must occur when symbols are used.

Exercise 1.2.
Overload the input and output operations via the >> and << streams for the template.

Please note that the syntax for creating templates is quite flexible:
template class class_template_name {...};
After declaring a template, you can declare a class using this template:
class_template_name

Exercise 1.3.
Convert the template so that the data types r and m are different. And adapt the methods and functions developed in the program for this case.

Exercise 1.4.
Modify the program so that one of the template settings is the implementation of the operation for comparing complex numbers.
Those. so that you can choose not only data types, but also the logic for comparing two complex numbers.
Больше информации об этом исходном тексте

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:00
Write a program which asks you to enter a name in the form of first middle initial last. so you might enter for example samuel p. clemens. use getline to read in the string because it contains spaces. also, apparently the shift key on your keyboard doesn’t work, because you enter it all lower case. pass the string to a function which uses .find to locate the letters which need to be upper case and use toupper to convert those characters to uppercase. the revised string should then be returned to main in the form last, first mi where it will be displayed.
Answers: 1
question
Computers and Technology, 22.06.2019 14:00
What are procedures that keep a data base current
Answers: 1
question
Computers and Technology, 22.06.2019 20:40
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
Which statistical function in a spreadsheet you to see how far each number varies, on average, from the average value of the list?
Answers: 2
You know the right answer?
C++. Hlp please! my last point((( Disassemble the program.
The main idea of ​​the template is...
Questions
question
Computers and Technology, 02.12.2021 02:50
question
Mathematics, 02.12.2021 02:50
question
Spanish, 02.12.2021 02:50
question
Biology, 02.12.2021 02:50
question
Mathematics, 02.12.2021 02:50
question
Mathematics, 02.12.2021 02:50
Questions on the website: 13722362