
#include<string.h> //包含字符串函数处理头文件
#include<stdlib.h> //包含动态存储与释放函数头文件
#include<iostream> // system
#define TEALEN sizeof(teanode) //教师信息结构体长度
#define LEN sizeof(Lnode) //链表节点长度
#define MAX 10
int SAME[MAX]
typedef struct teanode
{
char name[10]/银悉搜/教师姓名
int lesson //授课工作量
int exper//实验工作量
int cdesign //课程设计工作量
int gdesign //毕业设计工作量
int total//总工作量
int pos //排序位置
}teanode,*linknode//教师信息结构体
typedef struct Lnode
{
char no[20] //教师编号
linknode info //节点信息详细指针指向教师信息结构体
struct Lnode *prior,*next //双向链表指针域
}Lnode,*linklist//链表节点
void newLnode()
void initlist()
void prin()
void initlist(linklist *T)
{
*T=(linklist)malloc(LEN)
(*T)->info=(linknode)malloc(TEALEN)//为头结点申请空间
(*T)->prior=*T//设置头结点的前驱指针
(*T)->next=*T//设置头结点的后继指针
}//初始化双向循环链表
void newLnode(linklist*p)
{
*p=(linklist)malloc(LEN)//新节点
if(!p)
{
printf("申请节点失败")
exit(0)
}
(*p)->info=(linknode)malloc(TEALEN)
}
void prin(linklist * L)
{
if(L==NULL)
{
printf("锋历没有可以显示的信息\n")
return
}
linklist p=(*L)->next
// printf("陆哗********************************************************************************\n")
printf("教师编号 教师姓名 工作量排名 工作总量\n\n")
while (p!=*L)
{
#include <iostream>#include <fstream>
#include <string>
#include <conio.h>
using namespace std
//教师资料
struct Teacher
{
string num
string name
string sex
int age
string education
float wage
Teacher *next
}
//初始化链表
void InitList (Teacher *&L)
{
L = new Teacher
L->next = NULL
}
//重载<<运算符,以老蚂用于输出一个Teacher型结点
ostream &operator <<(ostream &output, Teacher *&t)
{
output <<t->num <<'\t' <<t->name <<'\t' <<t->sex <<'\t'
<<t->age <<'\t' <<t->education <<'\t' <<t->wage <<endl
return output
}
//重载>>运算符,以用于输入一个Teacher型结点
istream &operator >>(istream &input, Teacher *&t)
{
input >>t->num >>t->name >>t->sex >>t->age >>t->education >>t->wage
return input
}
/*
//保存信息
void SaveData (Teacher *L)
{
Teacher *p = L->next
ofstream outfile ("B.txt", ios::out)
if (!outfile)
{
cerr <<"文件打开失败!" <<endl
exit (1)
}
while (p != NULL)
{
outfile <<p
p = p->next
}
outfile.close ()
}
*/
//从文件B.txt中读取教师信息
void ReadData (Teacher *&L)
{
Teacher *r = L, *s
ifstream infile ("B.txt", ios::in)
if (!infile)
{
cerr <<"文件腊饥打开失败!" <<endl
exit (1)
}
infile.seekg (sizeof ("职工号\t姓名\t性别\t年龄\t学历\t工资"))
while (!infile.eof ())
{
s = new Teacher
infile >>s
r->next = s
r = s
}
r->next = NULL
infile.close ()
}
//按教师姓名查找信息
void SearchByName ()
{
system ("cls")
Teacher *L
InitList (L)
ReadData (L)
Teacher *p = L->next
cout <<"请输入教师姓名:"
string str
cin >>str
while ((p != NULL) &&(p->name != str))
{
p = p->next
}
if (p == NULL)
cout <<"查无此人!" <<endl
else
{
cout <<"该教师信息如下:\n"
cout <<"职工号\t姓名\t性别\t年龄\t学历\t工资" <<endl
cout <<p <<endl
}
system ("pause")
}
//按教师工资降序排列
void Sort ()
{
system ("cls")
Teacher *L
InitList (L)
ReadData (L)
Teacher *p = L->next, *r = p->next, *q
p->next = NULL
p = r
if (p == NULL)
{
cout <<"文件中不存在任何教侍局埋师的资料,请输入……" <<endl
system ("pause")
return
}
while (p != NULL)
{
r = r->next
q = L
while ((q->next != NULL) &&(q->next->wage >p->wage))
{
q = q->next
}
p->next = q->next
q->next = p
p = r
}
Teacher *s = L->next
cout <<"职工号\t姓名\t性别\t年龄\t学历\t工资" <<endl
while (s != NULL)
{
cout <<s
s = s->next
}
cout <<endl
system ("pause")
}
//主菜单
void Menu ()
{
while (1)
{
system ("cls")
cout <<endl <<endl <<endl
cout <<"\t\t***************[欢迎使用教师管理系统]***************" <<endl
cout <<"\t\t**------------------------------------------------**" <<endl
cout <<"\t\t** (1) 查询信息 **" <<endl
cout <<"\t\t**------------------------------------------------**" <<endl
cout <<"\t\t** (2) 降序排列 **" <<endl
cout <<"\t\t**------------------------------------------------**" <<endl
cout <<"\t\t** (0) 退出**" <<endl
cout <<"\t\t**------------------------------------------------**" <<endl
cout <<"\t\t***************请用数字键选择相应的功能*************" <<endl
switch (getch ())
{
case '1':
SearchByName ()
break
case '2':
Sort ()
break
case '0':
cout <<"\n\n\t\t\t\t谢 谢 使 用 !" <<endl
exit (0)
default:
break
}
}
}
int main ()
{
//打开B.txt文件,若不存在,则新建一个
ofstream outfile ("B.txt", ios::app)
if (!outfile)
{
outfile.close ()
ofstream outfile ("B.txt", ios::trunc)
outfile <<"职工号\t姓名\t性别\t年龄\t学历\t工资" <<endl
}
outfile.close ()
Menu ()
return 0
}
---------------------------------如果您对我的答案感到满意,请采纳--------------------------------------
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)