Home > Back-end >  Economic living daily confused......
Economic living daily confused......

Time:09-22

To run the program as shown in figure 1 screen output and output file is shown in figure 2,
#include
#include
#include
using namespace std;

Typedef enum {the TEACHER, STUDENT, ONJOBPOSTGRADUATE} Role;
String role []={" the Teacher ", "Student", "OnJobPostGraduate"};
Typedef enum {MALE, FEMALE} Sex;
String sex []={" Male "and" Female "};
Typedef enum {ASSISTANT, LECTURER, APROFESSOR, PROFESSOR} Position;
String position []={" Assistatn ", "Lecturer" to "AProfessor", "Professor"};
Typedef enum {CS, EE, CE} Major;
A string of major []={" CS ", "EE", "CE"};
Typedef struct Identity {
String _name;
Sex _sex;//enum {MALE, FEMALE} Sex
Int _age;
Role _role;//enum {the TEACHER, STUDENT, ONJOBPOSTGRADUATE} Role
Int _number;
String _department;
} Id;

The class Account {
Private:
Id Id;
Public:
The Account (Id);
~ the Account (s);
Void setRole ();
/* * * * * * added a member function declaration/* * * * * *

/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
};
Account: Account (Id I) : Id (I) {}
Account: : ~ Account () {}
Void Account: : setRole () {
Cout & lt; <"Input role (0 - the Teacher/1 - Student/2 - OnJobPostGraduate) :";
int x;
Cin> x;
The switch (x) {
Case 0: id. _role=the TEACHER; break;
Case 1: id. _role=STUDENT; break;
Case 2: id. _role=ONJOBPOSTGRADUATE; break;
}
}
Void Account: : showId () {
Cout & lt; <"Name:" & lt; <"Sex:" & lt; <"The age:" & lt; <"Role:" & lt; <"Number:" & lt; <"Department:" & lt; }
Void Account: : writeToFile () {
Ofstream outFile (" res. TXT ");
OutFile & lt; <"Name:" & lt; <"Sex:" & lt; <"The age:" & lt; <"Role:" & lt; <"Number:" & lt; <"Department:" & lt; OutFile. Close ();
}

/* * * * * * added TeacherAccount class head * * * * * */

/* * * * * * * * * * * * * * * * * * * * * * * */
{
Private:
The Position pos.//enum {ASSISTANT, LECTURER, APROFESSOR, PROFESSOR} Position
Public:
TeacherAccount (Id, Position);
~ TeacherAccount ();
String& GetPosition ();
Void showPosition ();
/* * * * * * added a member function declaration/* * * * * *

/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
};
/* * * * * * define TeacherAccount constructor of a class * * * * * */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
TeacherAccount: : ~ TeacherAccount () {}
String& TeacherAccount: : getPosition () {
Return the position (pos),
}
Void TeacherAccount: : showPosition () {
Cout & lt; <"The position:" & lt; }
Void TeacherAccount: : showId () {
Account: : showId ();
ShowPosition ();
}

/* * * * * * added StudentAccount class head * * * * * */

/* * * * * * * * * * * * * * * * * * * * * * * */
{
Private:
Major maj.//enum {CS, EE, CE} Major
Public:
StudentAccount (Id, Major);
~ StudentAccount ();
String& GetMajor ();
Void showMajor ();
/* * * * * * added a member function declaration/* * * * * *

/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
};
/* * * * * * define StudentAccount constructor of a class * * * * * */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
StudentAccount: : ~ StudentAccount () {}
String& StudentAccount: : getMajor () {
The return of major (maj);
}
Void StudentAccount: : showMajor () {
Cout & lt; <"Major:" & lt; }
Void StudentAccount: : showId () {
Account: : showId ();
ShowMajor ();
}

/* * * * * * added OnJobPostgraduateAccount class head * * * * * */

/* * * * * * * * * * * * * * * * * * * * * * * */
{
Public:
OnJobPostgraduateAccount (Id, Position, Major);
~ OnJobPostgraduateAccount ();
/* * * * * * added a member function declaration/* * * * * *

/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
};
/* * * * * * define OnJobPostgraduateAccount constructor of a class * * * * * */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
OnJobPostgraduateAccount: : ~ OnJobPostgraduateAccount () {}
Void OnJobPostgraduateAccount: : showId () {
Account: : showId ();
ShowPosition ();
ShowMajor ();
}
Void OnJobPostgraduateAccount: : writeToFile () {
Account: : writeToFile ();
Ofstream outFile (" res. TXT ", ios_base: : app);
OutFile & lt; <"The position:" & lt; <"Major:" & lt; OutFile. Close ();
}

Int main () {
Id stud={" Meng Chao ", MALE, 18, STUDENT, 20190131, "Dep. Of Computer"};
Id TCH={" Zheng Xiao - hong ", FEMALE, 25, the TEACHER, 1000568, "Dep. Of Computer"};

StudentAccount s (stud, CS);
TeacherAccount t (TCH, LECTURER);
OnJobPostgraduateAccount g (TCH, LECTURER, EE);
G.s etRole ();//set the data members _role as OnJobPostgraduat

/* * * * * * defines a base class pointer variable pt Account, and initialized to null pointer * * * * * */
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related