#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
typedef struct date
{
int year;
int month;
int day;
}DATE;
typedef struct stu
{
long stuID; //学号
char stuname[10]; //名字
char stusex; //性别
DATE birthday; //生日
int score[4]; //4科分数
float aver; //平均分
}STU;
typedef struct node
{
STU stu;
struct node* next; //指向下一个节点的指针
}NODE;
NODE* head = NULL; //定义头指针
struct node* creatnode();
void start();
void inputstudent(STU stu[], int n, int m); //录入学生信息
void totalscore(STU stu[], int n); //计算学生总分及排名并能根据姓名查询学生成绩及排名
void savestudent(); //保存学生信息
void scoreline_uptodown(STU stu[], int n); //按每个学生的总分由高到底
#define N 30
int main()
{
NODE* list = creatnode();
if (head == NULL)
{
head = list;
}
STU stu[N];
int n;
int m = 4;
printf("输入学生人数:");
scanf_s("%d", &n);
while (1)
{
start();
char ch = _getch();
switch (ch)
{
case '1': //录入学生信息
inputstudent(stu,n,m);
break;
case '2': //保存学生信息
void savestudent();
break;
case '3': //按总分由高到低排出名次
break;
case '4': //按总分由低到高排出名次
break;
case '5': //按学号由小到大排出成绩表
break;
case '6': //按姓名字典顺序排序排出成绩表
break;
case '7': //计算学生总分及排名并能根据姓名查询学生成绩及排名
totalscore(stu,n);
break;
case '8': //计算学生总分及排名并能根据学号查询学生成绩及排名
break;
case '9': //退出系统
break;
}
}
return 0;
}
void start()
{
printf("*****************************************\n");
printf("欢迎使用学生成绩管理系统 *\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("*0.根据姓名查询学生成绩及排名 *\n");
printf("*00退出系统 *\n");
printf("*****************************************\n");
}
void inputstudent(STU stu[], int n, int m)
{
int i, j;
NODE* newnode = (NODE*)malloc(sizeof(node)); //创建一个新结点来作头结点,使newnode这个指针可以通过->来当作结构体变量来用
newnode->next = NULL;
if (head == NULL)
{
head = newnode;
}
else
{
newnode->next = head;
head = newnode; //newnode = head; 修改
}
for ( i = 0; i < n; i++)
{
printf("学号:");
scanf_s("%ld", &newnode->stu.stuID);
printf("姓名:");
scanf_s("%s", newnode->stu.stuname, 10); //修改
printf("性别:");
scanf_s(" %c", &newnode->stu.stusex, 1); //修改
printf("年:");
scanf_s("%d", &newnode->stu.birthday.year);
printf("月:");
scanf_s("%d", &newnode->stu.birthday.month);
printf("日:");
scanf_s("%d", &newnode->stu.birthday.day);
printf("4科成绩:");
for ( j = 0; j < 4; j++)
{
scanf_s("%d", &stu[i].score[j]);
}
}
}
void totalscore(STU stu[], int n) //计算学生总分及排名并能根据姓名查询学生成绩及排名
{
int i, j, arr[30] = { 1 };
int sum[30];
for (i = 0; i < 4; i++)
{
sum[i] = 0;
for (j = 0; j < 4; j++)
{
sum[i] = sum[i] + stu[i].score[j];
}
}
for (i = 0; i < n; i++)
{
int c;
c = sum[i];
sum[i] = sum[0];
sum[0] = c;
for (j = 0; j < n - 1; j++)
{
if (sum[i] < sum[j + 1])
arr[i] = arr[i] + 1;
}
}
while(1)
{
printf("输入所要查询的学生姓名:");
char nameput[10];
scanf_s("%s", nameput);
for (j = 0; j < n; j++)
{
for (i = 0; i < 200; i++)
{
if (nameput[i] != stu[j].stuname[i])
break;
else
printf("总分:%d 名次:%d", sum[j],arr[j]);
}
}
}
}
void savestudent() //保存学生信息
{
FILE* pf = fopen("ppp.txt", "w"); //创建并打开文件
if (pf == NULL) //判断打开文件是否失败
{
printf("err!");
return;
}
NODE* p = head;
while (p!=NULL)
{
fwrite(&p->stu, 1, sizeof(STU), pf);
p = p->next;
}
fclose(pf);
printf("数据保存成功\n");
system("pluse"); //暂停
system("cls"); //清屏
}
void scoreline_uptodown(STU stu, int n)
{
int i;
for (i = 0; i < n; i++)
{
}
}
code error, how to modify?
0 Answer
No answer yet
这家伙很懒,什么都没留下...