📄 text1.c
字号:
#include<stdio.h>
#include<stdlib.h>
struct student
{ long no; /*学号*/
char name[20]; /*姓名*/
float chinese_score; /*语文成绩*/
float math_score; /*数学成绩*/
float english_score; /*英语成绩*/
float all_score; /*总成绩*/
float average_score; /*平均成绩*/
struct student *next; /*链接到下一个学生*/
}*myhead,*mynew,*mythis;
void creat_student(struct student*h);/*创建链表*/
void print_student(struct student*h);/* 显示全部记录*/
void search_student(struct student*h); /*查找记录*/
void add_student(struct student*h);/*插入链表*/
void delt_student(struct student*h); /*删除记录*/
void renew_student(struct student*h);/*插入记录*/
void set_student(struct student*h);/*设置链表*/
void creat()
{
myhead=NULL;
mynew=(struct student*)malloc(sizeof(struct student));
if(mynew!=NULL)
{
printf("Please input name:\n");
scanf("%s",&mynew->name);
printf("Please input no:\n");
scanf("%ld",&mynew->no);
printf("Please input chinese_score:\n");
scanf("%f",&mynew->chinese_score);
while(1)
{
if(sizeof(mynew->chinese_score)!=4||mynew->chinese_score<0||mynew->chinese_score>100)
{
printf("Erorr!!\n");
printf("Please input chinese_score(0~100):\n");
scanf("%f",&mynew->chinese_score);
}
else
break;
}
printf("Please input math_score:\n");
scanf("%f",&mynew->math_score);
while(1)
{
if(sizeof(mynew->math_score)!=4||mynew->math_score<0||mynew->math_score>100)
{
printf("Erorr!!\n");
printf("Please input math_score(0~100):\n");
scanf("%f",&mynew->math_score);
}
else
break;
}
printf("Please input english_score:\n");
scanf("%f",&mynew->english_score);
while(1)
{
if(sizeof(mynew->english_score)!=4||mynew->english_score<0||mynew->english_score>100)
{
printf("Erorr!!\n");
printf("Please input english_score(0~100):\n");
scanf("%f",&mynew->english_score);
}
else
break;
}
mynew->all_score=mynew->chinese_score+mynew->math_score+mynew->english_score;
mynew->average_score=(mynew->chinese_score+mynew->math_score+mynew->english_score)/3;
}
while(1)
{
if(myhead==NULL)
{
myhead=mynew;
myhead->next=NULL;
}
else
{
mythis=myhead;
while(1)
{
if((mythis->next)!=NULL)
mythis=mythis->next;
else
{
mythis->next=mynew;
mynew->next=NULL;
break;
}
}
}
mynew=(struct student*)malloc(sizeof(struct student));
if(mynew!=NULL)
{
printf("Please input name(若无新记录,请输入'#'):\n");
scanf("%s",&mynew->name);
if((mynew->name[0])=='#')
{
system("cls");
printf("over!!\n");
break;
}
else
{
printf("Please input no:\n");
scanf("%ld",&mynew->no);
printf("Please input chinese_score:\n");
scanf("%f",&mynew->chinese_score);
while(1)
{
if(sizeof(mynew->chinese_score)!=4||mynew->chinese_score<0||mynew->chinese_score>100)
{
printf("Erorr!!\n");
printf("Please input chinese_score(0~100):\n");
scanf("%f",&mynew->chinese_score);
}
else
break;
}
printf("Please input math_score:\n");
scanf("%f",&mynew->math_score);
while(1)
{
if(sizeof(mynew->math_score)!=4||mynew->math_score<0||mynew->math_score>100)
{
printf("Erorr!!\n");
printf("Please input math_score(0~100):\n");
scanf("%f",&mynew->math_score);
}
else
break;
}
printf("Please input english_score:\n");
scanf("%f",&mynew->english_score);
while(1)
{
if(sizeof(mynew->english_score)!=4||mynew->english_score<0||mynew->english_score>100)
{
printf("Erorr!!\n");
printf("Please input english_score(0~100):\n");
scanf("%f",&mynew->english_score);
}
else
break;
}
mynew->all_score=mynew->chinese_score+mynew->math_score+mynew->english_score;
mynew->average_score=(mynew->chinese_score+mynew->math_score+mynew->english_score)/3;
}
}
}
}
void print()
{
struct student *p;
p=myhead;
system("cls");
if(p==NULL)
printf("there is no record!");
else
printf("no name chinese_score math_score english_score all_score average_score\n");
while(p!=NULL)
{
printf("%-10ld %-10s %-8.1f %-9.1f %-8.1f %-11.1f %-8.1f\n",p->no,p->name,
p->chinese_score,p->math_score,p->english_score,p->all_score,p->average_score);
p=p->next;
}
}
void search()
{
long num;
mythis=myhead;
system("cls");
printf("Please enter no for searching:\n");
scanf("%ld",&num);
while(1)
{
if((mythis->no)==num)
{
printf(" no name chinese_score math_score english_score all_score average_score\n");
printf("%-10ld %-10s %-8.1f %-9.1f %-8.1f %-11.1f %-8.1f\n",mythis->no,mythis->name,
mythis->chinese_score,mythis->math_score,mythis->english_score,mythis->all_score,mythis->average_score);
break;
}
else
if(((mythis->no)!=num)&&(mythis->next)!=NULL)
{
mythis=mythis->next;
}
else
if((mythis->next)==NULL)
{
printf("There isn't %ld student on the list\n",num);
break;
}
}
}
void add()
{
mynew=(struct student*)malloc(sizeof(struct student));
if(mynew!=NULL)
{
printf("Please input name:\n");
scanf("%s",&mynew->name);
printf("Please input no:\n");
scanf("%ld",&mynew->no);
printf("Please input chinese_score:\n");
scanf("%f",&mynew->chinese_score);
while(1)
{
if(sizeof(mynew->chinese_score)!=4||mynew->chinese_score<0||mynew->chinese_score>100)
{
printf("Erorr!!\n");
printf("Please input chinese_score(0~100):\n");
scanf("%f",&mynew->chinese_score);
}
else
break;
}
printf("Please input math_score:\n");
scanf("%f",&mynew->math_score);
while(1)
{
if(sizeof(mynew->math_score)!=4||mynew->math_score<0||mynew->math_score>100)
{
printf("Erorr!!\n");
printf("Please input math_score:(0~100):\n");
scanf("%f",&mynew->math_score);
}
else
break;
}
printf("Please input english_score:\n");
scanf("%f",&mynew->english_score);
while(1)
{
if(sizeof(mynew->english_score)!=4||mynew->english_score<0||mynew->english_score>100)
{
printf("Erorr!!\n");
printf("Please input english_score:(0~100):\n");
scanf("%ld",&mynew->english_score);
}
else
break;
}
mynew->all_score=mynew->chinese_score+mynew->math_score+mynew->english_score;
mynew->average_score=(mynew->chinese_score+mynew->math_score+mynew->english_score)/3;
system("cls");
printf("Success!!\n");
}
mythis=myhead;
while(1)
{
if((mythis->next)!=NULL)
mythis=mythis->next;
else
{
mythis->next=mynew;
mynew->next=NULL;
break;
}
}
}
void delt()
{
long num;
struct student *p;
printf("Please enter the no for delet:\n");
scanf("%ld",&num);
mythis=myhead;
system("cls");
while(1)
{
if((myhead->no)==num)
{
myhead=myhead->next;
printf("记录已删除!!\n");
free(mythis);
break;
}
if((myhead->no)!=num)
{
while(1)
{
if(((mythis->next)!=NULL)&&((mythis->no)!=num))
{
p=mythis;
mythis=mythis->next;
continue;
}
else if(((mythis->next)==NULL)&&((mythis->no)!=num))
{
printf("Not found!!\n");
break;
}
else if(((mythis->no)==num)&&((mythis->next)!=NULL))
{
p->next=mythis->next;
printf("记录已删除!!\n");
free(mythis);
break;
}
else if(((mythis->no)==num)&&((mythis->next)==NULL))
{
p->next=NULL;
printf("记录已删除!!\n");
free(mythis);
break;
}
}
break;
}
}
}
void renew()
{
long num;
printf("please input the no to renew:\n");
scanf("%ld",&num);
mythis=myhead;
while(1)
{
if(((mythis->no)!=num)&&((mythis->next)!=NULL))
mythis=mythis->next;
else if(((mythis->no)!=num)&&((mythis->next)==NULL))
{
printf("Not found!!\n");
break;
}
else if((mythis->no)==num)
{
printf("Please input new chinese_score:\n");
scanf("%f",&mythis->chinese_score);
while(1)
{
if(sizeof(mythis->chinese_score)!=4||mythis->chinese_score<0||mythis->chinese_score>100)
{
printf("Erorr!!\n");
printf("Please input new chinese_score(0~100):\n");
scanf("%f",&mythis->chinese_score);
}
else
break;
}
printf("Please input new math_score:\n");
scanf("%f",&mythis->math_score);
while(1)
{
if(sizeof(mythis->math_score)!=4||mythis->math_score<0||mythis->math_score>100)
{
printf("Erorr!!\n");
printf("Please input new math_score(0~100):\n");
scanf("%f",&mythis->math_score);
}
else
break;
}
printf("Please input new english_score:\n");
scanf("%f",&mythis->english_score);
while(1)
{
if(sizeof(mythis->english_score)!=4||mythis->english_score<0||mythis->english_score>100)
{
printf("Erorr!!\n");
printf("Please input new english_score(0~100):\n");
scanf("%f",&mythis->english_score);
}
else
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -