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" <<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" <<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