C++. Hlp please! my last point(((
Disassemble the program.
The main idea of the template is...
Computers and Technology, 07.07.2021 14:00, kruzyoungblood8
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.
Больше информации об этом исходном тексте
Answers: 2
Computers and Technology, 21.06.2019 17:30, staz13wiggins
How many pairs of chromosomes do human body cells contain?
Answers: 2
Computers and Technology, 25.06.2019 04:50, mlinares776
Your program should prompt the user for the dimensions of the two squares matrices, making sure that the user input is greater than or equal to 4.[ yes, an example would be a4x4matrix]2.if the above is not met, prompt the user for a new value.3.now generate random integernumbers to fill both matrices.4.display these two matrices on the screen.5.multiply the two matrices and display the result on the scre
Answers: 2
English, 10.09.2020 02:01
Social Studies, 10.09.2020 02:01
Social Studies, 10.09.2020 02:01
History, 10.09.2020 02:01
Physics, 10.09.2020 02:01
Social Studies, 10.09.2020 02:01
Mathematics, 10.09.2020 02:01
Social Studies, 10.09.2020 02:01