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 11:00
When building customer relationships through email what should you not do? question 2 options: utilize proper grammar, spelling, and punctuation type in all capital letters use hyperlinks rather than attachments respond to all emails within 24 hours
Answers: 1
question
Computers and Technology, 23.06.2019 17:30
What are the most commonly found items in the trash according to the municipal solid waste report?
Answers: 1
question
Computers and Technology, 24.06.2019 14:00
When creating a field in a table, you must set the to determine what type of data the field can store. field property data type field type data property
Answers: 1
question
Computers and Technology, 25.06.2019 03:10
Write a program to convert a person's height in inches into centimetres #and their weight in stones into kilograms. (1 inch = 2.54 cm and 1 stone = 6.364 kg)
Answers: 1
You know the right answer?
C++. Hlp please! my last point((( Disassemble the program.
The main idea of ​​the template is...
Questions
question
Mathematics, 29.01.2020 00:52
question
Mathematics, 29.01.2020 00:52
Questions on the website: 13722367