教师电脑系统设计方案,优秀的教学系统设计案例
#include <iostream>
#include <cstring>
using namespace std;
typedef struct TEACHER {
char num[10];
char name[20];
char sex[5];
char prof[20];
char dept[50];
struct TEACHER *next;
} *teacher;
teacher CreatLink(int n) { // 创建具有n个结点的链表
teacher p,q,head;
head = p = new TEACHER;
for(int i = 0; i < n; ++i) {
q = new TEACHER;
cout << "第" << i + 1 << "个教师的编号 : ";
cin >> q->num;
cout << "第" << i + 1 << "个教师的姓名 : ";
cin >> q->name;
cout << "第" << i + 1 << "个教师的性别 : ";
cin >> q->sex;
cout << "第" << i + 1 << "个教师的职称 : ";
cin >> q->prof;
cout << "第" << i + 1 << "个教师所在的院系 : ";
cin >> q->dept;
p->next = q;
p = q;
}
p->next = NULL;
return head;
}
void PrintLink(teacher head) { // 打印输出链表内容
teacher p = head->next;
while(p!= NULL) {
cout << "编号 : " << p->num << "\t";
cout << "姓名 : " << p->name << "\t";
cout << "性别 : " << p->sex << "\t";
cout << "职称 : " << p->prof << "\t";
cout << "院系 : " << p->dept << endl;
p = p->next;
}
}
int Order(char *s) {
char *title[4] = {"教授","副教授","讲师","助教"};
for(int i = 0; i < 4; ++i)
if(strcmp(s,title[i]) == 0) return i;
return 127;
}
void SortProf(teacher head) { // 按职称排序
teacher p,s,pt;
p = head;
s = p->next;
while(p->next != NULL) {
while(s->next != NULL) {
if(Order(p->next->prof) > Order(s->next->prof)) {
pt = p->next;
p->next = s->next;
s->next = p->next->next;
p->next->next = pt;
}
else s = s->next;
}
p = p->next;
s = p->next;
}
}
void freeheap(teacher head) { // 释放动态内存
teacher p,q;
p = head;
q = p->next;
while(q != NULL) {
p = q;
q = p->next;
free(p);
}
free(head);
}
int CountDeptProf(teacher head,char *dept,char *prof) { // 统计指定院系的具有prof职称的人数
teacher p = head->next;
int count = 0;
while(p != NULL) {
if((strcmp(p->dept,dept) == 0) && (strcmp(p->prof,prof) == 0))
++count;
p = p->next;
}
return count;
}
int CountLink(teacher head) { // 统计总人数
int count = 0;
teacher p = head->next;
while(p != NULL) {
++count;
p = p->next;
}
return count;
}
int main() {
teacher head = CreatLink(5);
cout << "共有教师 : " << CountLink(head) << "名。" << endl;
PrintLink(head);
cout << "排序后 :\n";
SortProf(head);
PrintLink(head);
freeheap(head);
return 0;
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。