Sdut object-oriented Programming 12 (operator overloading)

Source: Internet
Author: User
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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.