Home > Back-end >  Human Person as base class public derived class Student and Teacher's class, the Teacher, the m
Human Person as base class public derived class Student and Teacher's class, the Teacher, the m

Time:04-04

The Person class structure elucidation:
The Person class data members include:
Id (1) private data members: no (char [20] type), name and the name (char [20] type),
The Person class member functions include:
(1) there are arguments constructor Person (char *, char *) and copy constructor Person (const Person & amp;) , there are arguments Constructor parameter defaults to an empty string or 0 (when parameter to NULL to deal with it as an empty string), output information "Person Constructor run", the copy Constructor output information "Person CopyConstructor run"
(2) the Destructor, the Destructor output information "Person Destructor run"
(3) members of the public function: void setNo (char *) and char * getNo () returns and set the id no. (when the parameter is NULL to deal with it as an empty string)
(4) members of the public function: void elegantly-named setName (char *) and char * getName () returns respectively and the name of the set name (when parameter to NULL to deal with it as an empty string)
Const (5) public member functions to void the show () is used to display the basic information of the people, the display format for:
No=id number, Name of Name=
The Student class structure description:
Public students derived class Student human Person as base class, Student class structure that is as follows:
Student class data members include:
(1) private data members: id no inherited from the Person class, name the name inherited from the Person class,
(2) the private data members: student id sNo (char [10])
(3) the private data members: class className (char [20])
(4) private data members: performance score (double)
Student class member functions include:
(1) there are arguments constructor Student (char *, char *, char *, char *, double) and copy constructor Student (const Student & amp;) , there are arguments Constructor parameter defaults to an empty string or 0.0 (when parameter to NULL to deal with it as an empty string), output information "Student Constructor run", the copy Constructor output information "Student CopyConstructor run"
(2) the Destructor, the Destructor output information "Student Destructor"
(3) members of the public function: void setSNo (char *) and char * getSNo () returns and set the student id sNo (when parameter to NULL to deal with it as an empty string)
(4) members of the public function: void setClassName (char *) and char * getClassName () returns the className and setting up the class respectively (when parameter to NULL to deal with it as an empty string)
(5) members of the public function: void setScore (double) and double getScore () returns and set performance score (0.0) when the default parameters as
Const 6 public member functions to void the show () is used to display the basic information of the students, display format is:
No=id number, Name of Name=
SNo=student number, the ClassName=class, Score=achievement
Among them, round up integer,
The Teacher class structure elucidation:
Public derived teachers in class the Teacher is the human Person as base class, the Teacher class structure that is as follows:
The Teacher class data members include:
(1) private data members: id no inherited from the Person class, name the name inherited from the Person class,
(2) the private data members: gonghaowu tNo (char [10])
(3) the private data members: department class departmentName (char [20])
(4) private data members: pay wages (double)
The Teacher class member functions include:
(1) there are arguments constructor the Teacher (char *, char *, char *, char *, double) and copy constructor the Teacher (const the Teacher & amp;) , there are arguments Constructor parameter defaults to an empty string or 0.0 (when parameter to NULL to deal with it as an empty string), output information, "the Teacher Constructor run", the copy Constructor output information, "the Teacher CopyConstructor run"
(2) the Destructor, the Destructor output information, "the Teacher Destructor run"
(3) members of the public function: void setTNo (char *) and char * getTNo () returns and set respectively gonghaowu tNo (when parameter to NULL to deal with it as an empty string)
(4) members of the public function: void setDepartmentName (char *) and char * getDepartmentName departmentName () returns and set up department (when parameter to NULL to deal with it as an empty string)
(5) members of the public function: void setWages (double) and double getWages set () returns and pay wages (0.0) when the default parameters as
Const 6 public member functions to void the show () is used to display the teacher's basic information, display format is:
No=id number, Name of Name=
TNo=work number, DepartmentName=departments, pay Wages=
Among them, the wage rounded integer,

The referee sample testing program:
#include
using namespace std;
//the Person class
The class Person {
Protected:
Char no [20]. Id//
Char name [20].//name
Public:
The Person (char * str1=0, char * str2=0).//a parameter structure
The Person (const Person & amp; P);//copy structure
To the Person ();//destructors
Void the show () the const;//display the Person
Void setNo STR (char *);//set the id number
Void elegantly-named setName (char * STR);//set name
Char * getNo ();//to get id number
Char * getName ();//get name
};
//a parameter structure
Person: the Person (char * str1, char * str2) {
int i;
i=0;
If (str1!=0)
While (str1 [I]!='\ 0') {
No [I]=str1 [I];
i++;
}
No [I]='\ 0';
i=0;
If (str2!=0)
While (str2 [I]!='\ 0') {
The name [I]=str2 [I];
i++;
}
The name [I]='\ 0';
Cout<& lt;" The Person Constructor run "& lt; }
//copy structure
Person: the Person (const Person & amp; P) {
int i=0;
While (p.n o [I]!='\ 0') {
No [I]=p.n o [I];
i++;
}
No [I]='\ 0';
i=0;
While (p.n ame [I]!='\ 0') {
The name [I]=p.n ame [I];
i++;
}
The name [I]='\ 0';
Cout<& lt;" The Person CopyConstructor run "& lt; }
//destructors
Person: : ~ Person () {
Cout<& lt;" The Person Destructor run "& lt; }
//show Person
Void Person: : show () const {
Cout<& lt;" No="& lt; Char s2 [20]="doublebest";
Char s3 [19]="20181234";
Char s4 [20]="1801" iron;
Double value=https://bbs.csdn.net/topics/60.67;
Student stu1 (s1, s2, s3, s4, value);
Stu1. The show ();
Student stu2=stu1;
Cin. Getline (s3, 10, '\ n');
Cin. Getline (s4, 20, '\ n');
Cin> The value;
Stu2. SetSNo (s3);
Stu2. SetClassName (s4);
Stu2. The show ();
The Teacher t1 (s1, s2, s3, s4, value);
T1. The show ();
The Teacher t2=t1;
T2. SetTNo (s3);
T2. SetDepartmentName (s3);
T2. The show ();
return 0;
}
Input the sample:
20181234
Iron 1801
45.45
The output sample:
The Person Constructor run
Student Constructor run
No=130502190001010332, Name=doublebest
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related