"C + +" implements a plural class

Source: Internet
Author: User

Implement a plural class (complex)//requirements: 1: Implement several constructors with no parameter/with parameters/with default parameters. 2: Implement copy construction/destructor. #include <iostream>using namespace std;//with parameter constructor class Complex{private:double _real;double _image;public:void print (); complex (double _r, double _i); ~complex ();}; Complex::complex (double _r, double _i) {_real = _r;_image = _i;cout<< "The parameterless constructor" &LT;&LT;ENDL;} /* Constructors without parameters class Complex{private:double _real;double _image;public:void print (); complex (); ~complex ();}; Complex::complex () {_real = 0;_image = 0;cout<< "With no arguments constructor" &LT;&LT;ENDL;} *//* constructor with default parameters class Complex{private:double _real;double _image;public:void print (); complex (Double _real = 0,double _ Image = 0); ~complex ();}; Complex::complex (double _r, double _i) {_real = _r;_image = _i;cout<< "with the default constructor" <<endl;} *//* copy Construction class complex{private:double _real;double _image;public:void print () complex (double _r, double _i) {_real = _r;_ Image = _i;} Complex (complex const & comple); ~complex ();}; Complex::complex (complex const & comple) {_real = Comple._real;_image = comple._image;cout<< "Copy Structure" <<endl;} */complex::~complex () {cout << "destructor" << Endl;} void complex::p rint () {cout << "plural is:" << _real << "+" <<_image << "i" << Endl;} int main () {Double A, b;//double a;cout << "Please enter two number:"; Cin >> a >> b;//cin >> A;//complex Comp (a); COM Plex Comp (A, b);//complex comp (1, 2);//complex Comp;//complex COMP1 (comp); Comp.print ();//comp1.print (); return 0;}







"C + +" implements a plural class

Related Article

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.