The 12th Week "C + + Language Foundation" procedure fill in the blanks--Multiple inheritance

Source: Internet
Author: User

Problem Description:

Please fill in the appropriate content at the horizontal line of the program below to make the program complete, and the output of the program is:
Zhang San, aged 42, director of technical services
Senior engineer, majoring in marine engineering design.
#include <iostream> #include <cstring>using namespace Std;class person{char* name;      name int age;   Age Public:person () {} void SetName (char na[]) {name=new _________________;    (1) strcpy (Name,na);    } void Setage (int a) {age=a;    } char* GetName () {return name;    } int Getage () {return age;     }};class Leader: _________________ person//(2) {char *job;     Title Char *DEP;      Department Public:leader () {} void Setjob (char jb[]) {job=new _________________;    (3) strcpy (Job, JB);      } void Setdep (char dp[]) {dep=new _________________;    (4) strcpy (DEP, DP);    } char *getjob () {return job;    } char *getdep () {return DEP;     }};class Engineer: _________________ person//(5) {char *major;      Professional char *prof;   Title Public:engineer () {} void Setmajor (char maj []) {     Major=new _________________;    (6) strcpy (MAJOR,MAJ);         } void Setprof (char pf[]) {prof=new _________________;    (7) strcpy (prof, PF);    } char*getmajor () {return major;    } char*getprof () {return prof;            }};class Chairman: _________________ {};    (8) int main () {Chairman C;    C.setname ("Zhang San");    C.setage (42);    C.setjob ("director");    C.SETDEP ("Technical Office");    C.setmajor ("turbine design");    C.setprof ("senior Engineer"); cout <<c.getname () << "," <<c.getage () << "years old, as" &LT;&LT;C.GETDEP () <<c.getjob () <<    Endl cout <<c.getprof () << ", engaged in" << c.getmajor () << "professional" << ".    "<< Endl; return 0;}
  Code:
#include <iostream> #include <cstring>using namespace Std;class person{char* name;      name int age;   Age Public:person () {} void SetName (char na[]) {name=new char[strlen (NA) +1];    (1) strcpy (Name,na);    } void Setage (int a) {age=a;    } char* GetName () {return name;    } int Getage () {return age;     }};class leader:virtual Public person//(2) {char *job;     Title Char *DEP;      Department Public:leader () {} void Setjob (char jb[]) {job=new char[strlen (JB) +1];    (3) strcpy (Job, JB);      } void Setdep (char dp[]) {dep=new char [strlen (DP) +1];    (4) strcpy (DEP, DP);    } char *getjob () {return job;    } char *getdep () {return DEP;     }};class engineer:virtual Public person//(5) {char *major;      Professional char *prof;       Title Public:engineer () {} void Setmajor (char maj []) { Major=new Char[strlen (maj) +1];    (6) strcpy (MAJOR,MAJ);         } void Setprof (char pf[]) {prof=new Char[strlen (PF) +1];    (7) strcpy (prof, PF);    } char*getmajor () {return major;    } char*getprof () {return prof;            }};class chairman:public leader,public Engineer {};    (8) int main () {Chairman C;    C.setname ("Zhang San");    C.setage (42);    C.setjob ("director");    C.SETDEP ("Technical Office");    C.setmajor ("turbine design");    C.setprof ("senior Engineer"); cout <<c.getname () << "," <<c.getage () << "years old, as" &LT;&LT;C.GETDEP () <<c.getjob () <<    Endl cout <<c.getprof () << ", engaged in" << c.getmajor () << "professional" << ".    "<< Endl; return 0;}


Operation Result:

The 12th Week "C + + Language Foundation" procedure fill in the blanks--Multiple inheritance

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.