C专业课程设计程序
#include #include using std::cout; using std::endl; class Course{ public: Course():name(0),next(0){} Course(char n[]); ~Course(){delete[] name;} void setName(char n[]); void setNextCourse(Course* c); char *getName(){return name;} Course* getNext(){return next;} private: char* name; Course* next; }; Course::Course(char n[]){ name=new char[strlen(n)+1]; strcpy(this->name,n); } void Course::setName(char n[]){ delete[] name; this->name=new char[strlen(n)+1]; strcpy(this->name,n); } void Course::setNextCourse(Course* c){ this->next=c; } class Person{ public: Person():id(0),name(0),courses(0){} Person(char i[],char n[]); ~Person(); void setID(char i[]); void setName(char n[]); char *getID(){return id;} char *getName(){return name;} void addCourses(Course* c); virtual void display(); protected: char* id; char* name; Course* courses; }; Person::Person(char i[],char n[]){ this->id=new char[strlen(i)+1]; strcpy(this->id,i); this->name=new char[strlen(n)+1]; strcpy(this->name,n); } void Person::setID(char i[]){ delete[] id; this->id=new char[strlen(i)+1]; strcpy(this->id,i); } Person::~Person(){ Course* c; while(courses!=0){ c=courses->getNext(); delete courses; courses=c; } delete[] id; delete[] name; } void Person::setName(char n[]){ delete[] name; this->name=new char[strlen(n)+1]; strcpy(this->name,n); } void Person::display(){ coutgetNext(); } t->setNextCourse(c); } } class Teacher:public Person{ public: Teacher():Person(),position(0){} Teacher(char id[],char name[],char position[]); Teacher(const Teacher ~Teacher(); void display(); void setPosition(char p[]); char *getPosition(){return position;} private: char* position; }; Teacher::Teacher(char i[], char n[], char p[]):Person(i,n){ position=new char[strlen(position)+1]; strcpy(this->position,p); } Teacher::Teacher(const Teacher strcpy(this->id,t.id); this->name=new char[strlen(t.name)+1]; strcpy(this->name,t.name); this->position=new char[strlen(t.position)+1]; strcpy(this->position,t.position); } Teacher::~Teacher(){ delete[] position; } void Teacher::display(){ cout<<“ID: “<