实验一
1. 实验内容
简易学生教师管理系统。
C++
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class People {
public:
string no;
string name;
};
class Student : public People {
public:
int age;
void set(string nono, string namename, int ageage);
void out(Student S);
};
class Teacher : public People {
public:
float salary;
string title;
void set(string nono, string namename,float salarysalary, string titletitle);
void out(Teacher T);
};
// 成员函数定义
void Student::set(string nono, string namename, int ageage){
no = nono;
name = namename;
age = ageage;
}
void Student::out(Student S) {
cout << "编号:" << S.no << endl;
cout << "姓名:" << S.name << endl;
cout << "年龄:" << S.age << endl;
cout << endl;
}
void Teacher::set(string nono, string namename, float salarysalary, string titletitle) {
no = nono;
name = namename;
salary = salarysalary;
title = titletitle;
}
void Teacher::out(Teacher T) {
cout << "编号:" << T.no << endl;
cout << "姓名:" << T.name << endl;
cout << "薪水:" << T.salary << endl;
cout << "职称:" << T.title << endl;
cout << endl;
}
struct StudentListNode
{
Student value;
StudentListNode* next;
//构造函数
StudentListNode(Student valuevalue, StudentListNode* nextnext = NULL)
{
value = valuevalue;
next = nextnext;
}
};
struct TeacherListNode
{
Teacher value;
TeacherListNode* next;
//构造函数
TeacherListNode(Teacher valuevalue, TeacherListNode* nextnext = NULL)
{
value = valuevalue;
next = nextnext;
}
};
void setteacher(TeacherListNode* TL) {
//cout << endl << endl;
cout << ">>创建教师信息" << endl;
Teacher T;
cout << ">>输入编号:";
cin >> T.no;
cout << ">>输入姓名:";
cin >> T.name;
cout << ">>输入薪水:";
cin >> T.salary;
cout << ">>输入职称:";
cin >> T.title;
TeacherListNode* TT = new TeacherListNode(T);
TeacherListNode* ptr = TL;
TeacherListNode* ptr2 = TL;
while (ptr != NULL) {
ptr2 = ptr;
ptr = ptr->next; //移动到下一个结点
}
ptr2->next = TT;
}
void setstudent(StudentListNode* SL) {
//cout << endl << endl;
cout << ">>创建学生信息" << endl;
Student S;
cout << ">>输入编号:";
cin >> S.no;
cout << ">>输入姓名:";
cin >> S.name;
cout << ">>输入年龄:";
cin >> S.age;
StudentListNode* SS = new StudentListNode(S);
StudentListNode* ptr = SL;
StudentListNode* ptr2 = SL;
while (ptr != NULL) {
ptr2 = ptr;
ptr = ptr->next; //移动到下一个结点
}
ptr2->next = SS;
}
void seeteacher(TeacherListNode* TL) {
TeacherListNode* ptr = TL;
ptr = ptr->next;
while (ptr != NULL) {
ptr->value.out(ptr->value);
ptr = ptr->next; //移动到下一个结点
}
}
void seestudent(StudentListNode* SL) {
StudentListNode* ptr = SL;
ptr = ptr->next;
while (ptr != NULL) {
ptr->value.out(ptr->value);
ptr = ptr->next; //移动到下一个结点
}
}
TeacherListNode* findteacher(TeacherListNode* TL,string ff,bool k) {//k==0 使用姓名
TeacherListNode* ptr =