大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#include#include//清屏要用到的头文件
#include//文件操作要用到的头文件
#include//字符串比较用到的strcmp的
//定义结构体,来创建链表;
typedef struct Node
{
int ID;
char Name[30];
int Score1,Score2,Score3,sum;
double average;
struct Node* next; //指针域;
} node;
node list;
int Read_FILE(node* L); //读文件;
int Save_FILE(node* L); //保存文件;
void Catalogue(); //目录的函数;
void Add_Printf(); //增加学生信息界面;
void Add(node* L,node e); //实现增加信息的功能;
void Delete(node* L); //删除学生信息输出界面;
void dodelete(node* s); //实现删除学生信息;
void Fix(node* L); //修改学生信息;
void Search(node* L); //查询学生信息的输出界面;
node* Search_id(int id,node* L); //实现按学号查询学生信息;
node* Search_in(char name[],node* L); //实现按姓名查询学生信息;
void Printf(node* L); //实现输出学生信息的功能;
void Printf_(); //界面;
void Sort(node* L); //排序;
int cmpbsum(node * L);
int cmpssum(node * L);
int cmps1(node * L);
int cmpb1(node * L);
int cmps2(node * L);
int cmpb2(node * L);
int cmps3(node * L);
int cmpb3(node * L);
int cmpssave(node * L);
int cmpbave(node * L);
void Goodbye(); //退出系统;s
int main()
{
int choice=0;
int go;
while(1)
{
Catalogue();
scanf("%d",&choice);
switch(choice)
{
case 1:
Add_Printf();
break;
case 2:
Delete(&list);
break;
case 3:
Fix(&list);
break;
case 4:
Search(&list);
break;
case 5:
Printf(&list);
break;
case 6:
Sort(&list);
break;
case 0:
Goodbye();
break;
}
printf("是否继续操作?(用1表示Yes,用0表示No\n)");
scanf("%d",&go);
if(go==0)
{
break;
}
}
return 0;
}
void Catalogue()
{
system("cls"); //清屏;
printf("************************\n");
printf("************************\n");
printf("*****1.增加学生信息*****\n");
printf("*****2.删除学生信息*****\n");
printf("*****3.修改学生信息*****\n");
printf("*****4.查询学生信息*****\n");
printf("*****5.输出学生信息*****\n");
printf("*****6.排序学生信息*****\n");
printf("*****0.退出管理系统*****\n");
printf("************************\n");
printf("************************\n");
printf("\n");
printf("请输入您想实现的功能对应的编号:");
}
int Read_FILE(node* L) //读取文件;
{
FILE* fpRead = fopen("D:\\code\\student\\student_information.txt","r"); //打开文件 //r,文件必须存在,只读
node st; //创建一个st节点,用来存放读出来的数据;
node* s; //创建一个s节点,作用:把数据读出来后用来连接的;
node* t = L; //把L表的头节点赋值给t; //通过st存放数据再把数据传给s,通过s插入到t之后,t继续遍历;
if(fpRead == NULL)
{
printf("文件打开失败!");
return 0;
}
while(fscanf(fpRead,"%d %s %d %d %d %d %lf ",&st.ID,&st.Name,&st.Score1,&st.Score2,&st.Score3,&st.sum,&st.average)!=EOF)
{
s = (node*)malloc(sizeof(node)); //申请内存;
*s = st;
//尾插法;
t->next = s;
t = s;
t->next = NULL;
}
fclose(fpRead);
return 1;
}
int Save_FILE(node* L) //保存文件;
{
FILE* fpWrite = fopen("D:\\code\\student\\student_information.txt","w+"); //w+s,文件存在截断为0;不存在就创建;
if(fpWrite == NULL)
{
printf("文件打开失败!");
return 0;
}
node* p = L->next;
while(p != NULL)
{
fprintf(fpWrite,"%d %s %d %d %d %d %lf\n",p->ID,p->Name,p->Score1,p->Score2,p->Score3,p->sum,p->average);
p = p->next;
}
fclose(fpWrite);
return 1;
}
void Add_Printf() //增加学生信息的输出界面;
{
system("cls");
node st;
printf("请输入学生的信息。\n");
printf("请输入学生学号:\n");
scanf("%d",&st.ID);
printf("请输入学生姓名:\n");
scanf("%s",&st.Name);
printf("请输入学生的高数成绩:\n");
scanf("%d",&st.Score1);
printf("请输入学生的思修成绩:\n");
scanf("%d",&st.Score2);
printf("请输入学生的专业课成绩:\n");
scanf("%d",&st.Score3);
Add(&list,st);
}
void Add(node* L,node e) //实现增加学生信息的功能;
{
//头插法;
node* p = L;
node* s = (node*)malloc(sizeof(node));
*s = e;
s->next = p->next;
p->next = s;
s->sum = s->Score1 + s->Score2 + s->Score3;
s->average = (double)(s->Score1 + s->Score2 + s->Score3)/3.0;
Save_FILE(L); //增加之后要保存呀;
}
node* Search_id(int id,node* L) //实现按学号查询学生信息;
{
node* p = L;
while(p->next != NULL)
{
if(p->next->ID == id)
{
return p;
}
p = p->next;
}
return p->next;
}
node* Search_in(char name[],node* L) //实现按姓名查询学生信息;
{
node* p = L;
while(p->next != NULL)
{
if(strcmp(name,p->next->Name) == 0) //strcmp(str1,str2) 若str1 str2相等,则返回0;
{
return p;
}
p = p->next;
}
return p->next;
}
void Search(node* L) //查找学生信息的输出界面;
{
system("cls");
int choice = 0;
printf("如按学号查找请输入‘1’ \n");
printf("如按姓名查找请输入‘0’ \n");
scanf("%d",&choice);
int id;
char name[30];
node* st;
if(choice == 1)
{
printf("请输入待查询的学号:\n");
scanf("%d",&id);
st = Search_id(id,L);
if(st == NULL)
{
printf("系统中并无此人!\n");
}
else
{
st = st->next;
printf("——————————————————————————————————————————\n");
printf("|学号\t|姓名\t|高数\t|思修\t|专业课\t|总分\t|平均分\t|\n");
printf("%d\t|%s\t|%d\t|%d\t|%d\t|%d\t|%.2lf\t|\n",st->ID,st->Name,st->Score1,st->Score2,st->Score3,st->sum,st->average);
printf("——————————————————————————————————————————\n");
}
}
else
{
printf("请输入待查询的姓名:\n");
scanf("%s",name);
st = Search_in(name,L);
if(st == NULL)
{
printf("系统中并无此人!\n");
}
else
{
st=st->next;
printf("——————————————————————————————————————————\n");
printf("|学号\t|姓名\t|高数\t|思修\t|专业课\t|总分\t|平均分\t|\n");
printf("%d\t|%s\t|%d\t|%d\t|%d\t|%d\t|%.2lf\t|\n",st->ID,st->Name,st->Score1,st->Score2,st->Score3,st->sum,st->average);
printf("——————————————————————————————————————————\n");
}
}
}
void Delete(node* L) //删除学生信息的输出界面;
{
system("cls");
int id;
node* p;
printf("请输入要删除的学生的学号:\n");
scanf("%d",&id);
node* st = Search_id(id,L);
p = st;
if(st == NULL)
{
printf("系统中并无此人!\n");
return 0;
}
st =st->next;
printf("——————————————————————————————————————————\n");
printf("|学号\t|姓名\t|高数\t|思修\t|专业课\t|总分\t|平均分\t|\n");
printf("%d\t|%s\t|%d\t|%d\t|%d\t|%d\t|%.2lf\t|\n",st->ID,st->Name,st->Score1,st->Score2,st->Score3,st->sum,st->average);
printf("——————————————————————————————————————————\n");
dodelete(p);
printf("删除成功!");
Save_FILE(L); //保存;
}
void dodelete(node* s) //实现删除学生信息;
{
node* t = s->next;
s->next = t->next;
t->next = NULL;
free(t); //释放 防止成为野指针;
}
void Fix(node* L)
{
system("cls");
int id;
printf("请输入要修改的学生的学号:\n");
scanf("%d",&id);
node* st = Search_id(id,L);
if(st == NULL)
{
printf("系统中并无此人!\n");
return 0;
}
st = st->next;
int choice = 0;
while(1)
{
system("cls");
printf("——————————————————————————————————————————\n");
printf("|学号\t|姓名\t|高数\t|思修\t|专业课\t|总分\t|平均分\t|\n");
printf("%d\t|%s\t|%d\t|%d\t|%d\t|%d\t|%.2lf\t|\n",st->ID,st->Name,st->Score1,st->Score2,st->Score3,st->sum,st->average);
printf("——————————————————————————————————————————\n");
printf("1.修改学生学号\n");
printf("2.修改学生姓名\n");
printf("3.修改学生高数成绩\n");
printf("4.修改学生思修成绩\n");
printf("5.修改学生专业课成绩\n");
printf("\n");
printf("请输入待修改数据的编号:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("请输入学号:\n");
scanf("%d",&st->ID);
break;
case 2:
printf("请输入姓名:\n");
scanf("%s",&st->Name);
break;
case 3:
printf("请输入高数成绩:\n");
scanf("%d",&st->Score1);
break;
case 4:
printf("请输入思修成绩:\n");
scanf("%d",&st->Score2);
break;
case 5:
printf("请输入专业课成绩:\n");
scanf("%d",&st->Score3);
break;
}
printf("是否继续,继续请输入1,否则输入0\n");
scanf("%d",&choice);
if(choice == 0)
{
Save_FILE(L);
break;
}
}
printf("修改后的信息为:\n");
printf("——————————————————————————————————————————\n");
printf("|学号\t|姓名\t|高数\t|思修\t|专业课\t|\n");
printf("%d\t|%s\t|%d\t|%d\t|%d\t|%d\t|%.2lf\t|\n",st->ID,st->Name,st->Score1,st->Score2,st->Score3);
printf("——————————————————————————————————————————\n");
Save_FILE(L); //保存;
}
void Printf_() //界面
{
printf("——————————————————————————————————————————\n");
printf("|学号\t|姓名\t|高数\t|思修\t|专业课\t|总分\t|平均分\t|\n");
printf("——————————————————————————————————————————\n");
}
void Printf(node* L) //功能
{
system("cls");
node* p = L->next;
Printf_();
if(p != NULL)
{
while(p != NULL)
{
printf("%d\t|%s\t|%d\t|%d\t|%d\t|%d\t|%.2lf\t|\n",p->ID,p->Name,p->Score1,p->Score2,p->Score3,p->sum,p->average);
printf("——————————————————————————————————————————\n");
p =p->next;
}
}
}
int cmps1(node * L) //高数升序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->Score1 >p->Score1)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmpb1(node * L) //高数降序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->Score1< p->Score1)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmps2(node * L) //思修升序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->Score2 >p->Score2)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmpb2(node * L) //思修降序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->Score2< p->Score2)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmps3(node * L) //专业课升序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->Score3 >p->Score3)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmpb3(node * L) //专业课降序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->Score3< p->Score3)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmpssum(node * L) //总分升序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->sum >p->sum)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmpbsum(node * L) //总分降序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
if(q->sum< p->sum)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
return L;
}
int cmpsave(node * L) //平均分升序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->average >p->average)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
int cmpbave(node * L) //平均分降序;
{
int i,count = 0, num;
node *p, *q, *tail;
p = L;
while(p->next != NULL)
{
count++;
p = p->next;
}
for(i = 0; i< count - 1; i++)
{
num = count - i - 1;
q = L->next;
p = q->next;
tail = L;
while(num--)
{
if(q->average< p->average)
{
q->next = p->next;
p->next = q;
tail->next = p;
}
tail = tail->next;
q = tail->next;
p = q->next;
}
}
return L;
}
void Sort(node* L)
{
system("cls");
int choice = 1;
int a=0;
printf("0.按高数升序排列\n");
printf("1.按高数降序排列\n");
printf("2.按思修升序排列\n");
printf("3.按思修降序排列\n");
printf("4.按专业课升序排列\n");
printf("5.按专业课序排列\n");
printf("6.按三科总分升序排列\n");
printf("7.按三科总分降序排列\n");
printf("8.按平均分升序排列\n");
printf("9.按平均分降序排列\n");
printf("\n");
printf("请输入想要实现的功能的数字编号\n");
scanf("%d",&a);
switch(a)
{
case 0:
{
cmps1(L);
break;
}
case 1:
{
cmpb1(L);
break;
}
case 2:
{
cmps2(L);
break;
}
case 3:
{
cmpb2(L);
break;
}
case 4:
{
cmps3(L);
break;
}
case 5:
{
cmpb3(L);
break;
}
case 6:
{
cmpssum(L);
break;
}
case 7:
{
cmpbsum(L);
break;
}
case 8:
{
cmpsave(L);
break;
}
case 9:
{
cmpbave(L);
break;
}
}
Printf_(); //界面
Printf(L); //功能
Save_FILE(L); //保存;
}
void Goodbye()
{
system("cls");
printf("已退出系统,欢迎您下次使用!\n");
exit(0);
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
创新互联公司10多年企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,企业网站建设及推广,对成都加固等多个领域拥有丰富的网站制作经验的网站建设公司。