"C + + program" constructor

Source: Internet
Author: User
#include <iostream> #include <string>using namespace std;class person{string name;    bool gender;    int age;    Person *lover;public:person (const char *n= "nameless", bool g=true); void growup (int years);    void Show ();}; Person::P Erson (const char *n,bool g/*=true*/) {name=n;gender=g;age=0;lover=null;} void person::growup (int years) {age+=years;} void Person::show () {cout<< "Hello everyone, I am" << (gender?) Handsome ":" Beauty ") <<name<<", this year "<<age<<" years old. "<<endl;} int main () {Person A ("hibiscus", false); Person B ("Yong-ho", true); Person C ("two Dog"); Person D; Person e (); a.growup (b.growup); A.show (); B.show (); c.growup (5); C.show ();d. Growup (+);d. Show (); E (). Show (); Person E () {string Name;bool gender;int age;cout<< "Please enter name, gender and age";cin>>name>>gender>>age; Person input (NAME.C_STR (), gender); the//C_STR () function returns a pointer to the regular C string with the same contents as this string string. Input.growup (age); return input;}

"C + + program" constructor

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.