object-oriented programming 12 (operator overloading)
Time
limit:1000ms Memory limit:65536k A
problem description deals with the addition of a complex number to a double, and the result is stored in a double variable d1, outputting the D1 value. Define the complex (plural) class and include the overloaded type conversion operator in the member function: operator double () {return real;}
Enter input for two lines:
Line 1th is the real and imaginary part of a complex number, separated by a space.
Line 2nd is a real number. The
output output is one row, the sum of the real part and the real number of the complex number, and 1 digits after the decimal point.
Sample Input
2.3 5.4
3.4
Sample output
5.7
Source
#include <iostream>
using namespace std;
Class Plura
{
private:
double R;
Double i;
Public:
Plura (Double A, double b): R (a), I (b) {}
double operator + (double & A)
{
double b;
B = R + A;
return b;
}
;
int main ()
{
Double A, B, C;
Cin >> a >> b >> c;
Plura p (a,b);
c = p + C;
cout << c << Endl;
return 0;
}