怎么用C语言编一个学生成绩记录簿?

作者&投稿:贝丽 (若有异议请与网页底部的电邮联系)
~ #include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char id[15];
char name[10];
int score;
} StudentInfo;
typedef struct
{
StudentInfo arr[100];
int length;
} SeqList;
FILE *fp;
char *filePath = "C:/StudentInfo.txt";
void initSeqList(SeqList *L)
{
L->length = 0;
}
void insertSeqList(SeqList *L, int i, StudentInfo info)å
{
int j;
for(j = L->length; j > i; j--)
L->arr[j] = L->arr[j-1];
L->arr[j] = info;
L->length++;
}
void printStudentInfo(StudentInfo info)
{
printf("%s\t%s\t%d\n", info.id, info.name, info.score);
}
void printSeqListWithSeqNo(SeqList L)
{
for(int i = 0; i < L.length; i++)
{
printf("%d\t", i+1);
printStudentInfo(L.arr[i]);
}
}
void printSeqList(SeqList L)
{
for(int i = 0; i < L.length; i++)
printStudentInfo(L.arr[i]);
}
int queryInfoById(SeqList L, char *id)
{
for(int i = 0; i < L.length; i++)
if(strcmp(id, L.arr[i].id)==0)
return i;
return -1;
}
int queryInfoByName(SeqList L, char *name)
{
for(int i = 0; i < L.length; i++)
if(strcmp(name, L.arr[i].name)==0)
return i;
return -1;
}
void save2File(SeqList L)
{
fp = fopen(filePath, "w");
for (int i = 0; i < L.length; i++)
fprintf(fp, "%s\t%s\t%d\n", L.arr[i].id, L.arr[i].name, L.arr[i].score);
}
void showMenu(SeqList L);

void addInfo(SeqList L)
{
StudentInfo info;
int index;
do {
printf("请输入学号:");
scanf("%s", info.id);
index = queryInfoById(L, info.id);
if (index != -1)
{
printf("输入的学号已存在。\n");
printStudentInfo(L.arr[index]);
}
} while(index != -1);
do {
printf("请输入姓名:");
scanf("%s", info.name);
index = queryInfoByName(L, info.name);
if(index != -1)
{
printf("输入的姓名已存在。\n");
printStudentInfo(L.arr[index]);
}
} while(index != -1);
printf("请输入成绩:");
scanf("%d", &info.score);
L.arr[L.length] = info;
L.length++;
save2File(L);
}

void editInfo(SeqList L)
{
StudentInfo info;
char choice;
printf("1. 按学号修改\n2. 按姓名修改\n3. 返回上一层\n");
while((choice=getchar())=='\n');
int index;
if(choice == '1' || choice == '2')
{
if(choice == '1')
{
printf("请输入学号:");
scanf("%s", info.id);
index = queryInfoById(L, info.id);
} else {
printf("请输入姓名:");
scanf("%s", info.name);
index = queryInfoByName(L, info.name);
}
if(index != -1)
printStudentInfo(L.arr[index]);
else {
printf("%s 为 %s 的学生不存在\n", choice==1?"学号":"姓名", choice==1?info.id:info.name);
editInfo(L);
return;
}
printf("成绩改为:");
scanf("%d", &L.arr[index].score);
save2File(L);
}else if(choice == '3')
showMenu(L);
else {
printf("选择有误,请重新选择\n");
editInfo(L);
return;
}
}

void insertSort(SeqList *L)
{
for(int j = 1; j < L->length; j++)
{
StudentInfo key = L->arr[j];
int i = j - 1;
while(i >= 0 && L->arr[i].score < key.score)
{
L->arr[i+1] = L->arr[i];
i--;
}
L->arr[i+1] = key;
}
}
void statisticInfo(SeqList L)
{
// 显示 60 分以下、60~79、80~89、90 分以上各分数段的学生信息
SeqList sectionListArr[4];
for (int i = 0; i < 4; i++)
initSeqList(§ionListArr[i]);
float sum = 0, average, passedRate;
for (int i = 0; i < L.length; i++)
{
int score = L.arr[i].score;
sum += score;
if(score < 60)
insertSeqList(§ionListArr[0], sectionListArr[0].length, L.arr[i]);
else if(score >= 60 && score < 80)
insertSeqList(§ionListArr[1], sectionListArr[1].length, L.arr[i]);
else if(score >= 80 && score < 90)
insertSeqList(§ionListArr[2], sectionListArr[2].length, L.arr[i]);
else insertSeqList(§ionListArr[3], sectionListArr[3].length, L.arr[i]);
}
average = sum/L.length;
passedRate = (L.length-sectionListArr[0].length)*100.0/L.length;
insertSort(&L);
printf("60 分以下的学生:\n");
printSeqList(sectionListArr[0]);
printf("\n60 ~ 79 分的学生:\n");
printSeqList(sectionListArr[1]);
printf("\n80 ~ 89 分的学生:\n");
printSeqList(sectionListArr[2]);
printf("\n90 分以上的学生:\n");
printSeqList(sectionListArr[3]);
printf("\n及格率:%.1f %%\n平均分:%.1f\n", passedRate, average);
printf("按顺序从高到低排序:\n");
insertSort(&L);
printSeqListWithSeqNo(L);
printf("\n最高分:\n");
printStudentInfo(L.arr[0]);
printf("\n最低分:\n");
printStudentInfo(L.arr[L.length-1]);

}

void queryInfo(SeqList L)
{
char choice;
printf("1. 按学号查询\n2. 按姓名查询\n3. 返回上层\n");
while((choice=getchar())=='\n');
int index;
if (choice == '1')
{
char id[15];
printf("请输入学号:");
scanf("%s", id);
index = queryInfoById(L, id);
} else if(choice == '2') {
char name[10];
printf("请输入姓名:");
scanf("%s", name);
index = queryInfoByName(L,name);
} else if(choice == '3') {
showMenu(L);
return;
} else {
printf("选择有误,请重新选择\n");
queryInfo(L);
return;
}
if(index == -1)
printf("没有查询到结果\n");
else
printStudentInfo(L.arr[index]);

}
void showMenu(SeqList L)
{
char choice;
printf("\n1. 查询\n2. 添加成绩\n3. 修改成绩\n4. 统计分析\n5. 退出\n");
while((choice = getchar()) == '\n');
switch(choice)
{
case '1': queryInfo(L); break;
case '2': addInfo(L); break;
case '3': editInfo(L); break;
case '4': statisticInfo(L); break;
case '5': exit(0);
}
}
int main(void)
{
StudentInfo temp;
SeqList *L = (SeqList*)malloc(sizeof(SeqList));
do {
initSeqList(L);
fp = fopen(filePath, "r");
int i = 0;
while(fscanf(fp, "%s%s%d", temp.id, temp.name, &temp.score) != EOF)
insertSeqList(L, i++, temp);
showMenu(*L);
fclose(fp);
}while(1);
return 0;
}


C语言设计一个学生学籍管理系统,要求文件形式保存,且用到链表
float score1; float score2; float score3; char filename[] = "D:\\\\编程学习\\\\编程实践\\\\c语言课程设计1 学生信息管理\\\\data.txt"; \/\/文件名,此处为简化编程,采用固定地址名称,未作输入 FILE *fp; pstu head,ptr; \/\/创建带表头结点的空单链表head,用来存放载入信息 head = (pstu)malloc(SIZE)...

C语言 编写一个程序,输入10位同学的姓名和成绩,并按学生成绩从高到低...
include<stdio.h>#include<string.h>#define N 10struct student{char name[20];int score;};void main(){struct student stu[N];struct student *p; int i,v,s,temp;char tempname1[20],tempname2[20];for(i=0;i<N;i++){printf("please input %d student name\\n",i+1);scanf...

用C语言编写一程序,统计N个学生的成绩信息。
printf("请输入每个学生的信息:\\n");for(i=0;i<n;i++){ printf("第%d个学生:\\n",i+1);stud[i].mc=i+1;printf("输入学号:");scanf("%d",&stud[i].number);printf("输入姓名:");scanf("%s",stud[i].name);printf("输入数学成绩:");scanf("%lf",&stud[i].math);printf(...

C语言编程(每次用键盘输入一个学生的2门分数,计算并输出每个学生的总分...
include <stdio.h>int main(){int a,b,s,yx=0,jg=0; float av; while(1) {scanf("%d%d",&a,&b); s=a+b; av=s\/2.0; if(a<0||b<0)break; printf("总分:%d\\t平均分:%.1f\\n",s,av); if(av>=85)yx++; else if(av>=60)jg++; } printf("优秀人数...

怎样用C语言编写数学公式
1、C语言有现场的常用数学函数,所在函数库为math.h、stdlib.h。函数名及解释:int abs(int i) 返回整型参数i的绝对值double cabs(struct complex znum) 返回复数znum的绝对值double fabs(double x) 返回双精度参数x的绝对值long labs(long n) 返回长整型参数n的绝对值 double exp(double x) ...

在电脑上怎么编写c语言输入我是一个学生?
include<stdio.h> void main() { char s[80];printf("请输入一句话:"); scanf("%s",s);printf("你输入的是:%s\\n",s);} 程序运行后提示“请输入一句话:”你可以在冒号后面输入:我是一个学生 输入完成后回车,程序在下一行输出“你输入的是:xxxx”并换行,其中xxxx就是刚才你输入的...

请用C语言编一个程序计算3位学生3门课成绩总分和平均成绩?
\\n");for(j=0;j<3;j++){ printf("成绩%d: ",j+1);scanf("%d",&str[count].score[j]);sum+=str[count].score[j];} str[count].avr=sum\/3;printf("\\n是否继续?(y or n)");fflush(stdin);scanf("%c",&ch);count++;} return stud;} \/\/成绩排序函数 void sort()...

用C语言编写程序,完成以下功能: (1) 有5个学生,每个学生的数据包括学号...
void max(STU *stu, int num, STU *stuRev, int *stuRevNum) \/\/stu为学生数组的首地址,num为数组长度 \/\/stuRev表示要接收的数组,stuRevNum表示最终接收的个数,即最高成绩同学的个数(有可能不止一个同学){ STU temp[5] ;float maxtotal = 0 ;int i ,temp_index=0 ;for(i=0; i...

c语言作业 编写一个输出学生成绩等级的程序
C语言是一种计算机程序设计语言,它既具有高级语言的特点,又具有汇编语言的特点。它由美国贝尔研究所的D.M.Ritchie于1972年推出,1978年后,C语言已先后被移植到大、中、小及微型机上,它可以作为工作系统设计语言,编写系统应用程序,也可以作为应用程序设计语言,编写不依赖计算机硬件的应用程序。它的...

C语言编程!用姓名,学号,数学成绩和语文成绩描述一个学生的情况。编写程...
i;student stu[N];for (i = 0; i < N; ++i){printf ("输入第 %d 个学生的信息(顺序为姓名,学号,数学成绩,语文成绩,并用空格分开):\\n", i + 1);scanf ("%s %s %f %f", stu[i].name, stu[i].id, &stu[i].math_score, &stu[i].lang_score);}printf ("\\n")...

长海县19716105473: 用C语言设计一个学生成绩记录薄
尾义二甲: #include <stdio.h>#include <stdlib.h>#include <string.h> struct student{ char name[60]; char ID[7]; int score;}; int dq(struct student st[]);void xianshi();void bc(struct student st[]);void add(); void select();void zz();void chazhao();void xhcz();void xmcz();...

长海县19716105473: 编制一个C语言成绩记录簿 -
尾义二甲: 设计要求: 成绩记录簿中记录以下数据:学号、姓名、课程编号、课程名称、成绩、学分,所有成绩都以百分制计分.在程序中可以输入新的成绩记录,可以按学号或姓名查询一个学生的所有成绩,和已完成的总学分.也可以按课程编号查出一个班的成绩表,班成绩表后面要统计平均分,和及格率. 2. 提高水平 在程序中增加将数据写入文本文件和从文件中读入数据的功能,文件名由用户输入. 3. 提示 在没有使用文件时,数据可以保存在一个大的数组中,要注意的数据项的类型. 知识范围;C程序设计第三版谭浩强

长海县19716105473: 如何用C语言编成绩记录薄? -
尾义二甲: 先定义一个结构体(用伪代码说明了) typedef struct _STUDENTINFO { 学生的相关信息,如姓名,学号, 成绩等 struct _STUDENTINFO *next; //指向下一个学生

长海县19716105473: 成绩记录薄的程序怎么写?? 编制一个C语言成绩记录薄,每个学生信息包括:学号、姓名、C语言成绩.具体功能:⑴创建信息链表并以磁盘文件保存;⑵读取磁盘文件并显示输出所有学生的成绩;⑶按学号或姓 -
尾义二甲: /******头文件(.h)***********/ #include "stdio.h" /*I/O函数*/ #include "stdlib.h" /*其它说明*/ #include "string.h" /*字符串函数*/ #include "conio.h" /*屏幕操作函数*/ #include "mem.h" /*内存操作函数*/ #include "ctype.h" /*字符操作函数*...

长海县19716105473: 编制一个C语言成绩记录簿,要求每个学生信息包括:学号、姓名、C语言成绩.具体功能: (1)创建信息 -
尾义二甲: 我以前做过的一个, 你看看,/* 数据描述:学号 姓名 班级 高数 英语 总分程序完成功能:(1) 浏览数据 (2) 增加数据 (3) 修改数据(4) 查询数据(按姓名,按总分) (5) 退出 */#include #include #include using namespace std;...

长海县19716105473: c语言编程《成绩记录簿》
尾义二甲: #include "stdio.h" #include "stdlib.h" #include "string.h" int shoudsave=0; // struct student { char num[10];//学号 char name[20]; int cgrade; char neartime[10];//最近更新时间 }; typedef struct node { struct student data; struct node *next; }...

长海县19716105473: 编制一个c语言成绩记录簿,每个学生信息包括:学号,姓名,c语言成绩. -
尾义二甲: /*students.c*/ #include <stdio.h> #include <string.h> #include <stdlib.h> #include "students.h"struct list //结构体 {int sno;char sname[2];int sage;char sprof[2];int sclass;struct list *next; }; stud *Create(int n) {stud *p,*c,*h;p=(stud *) malloc (...

长海县19716105473: C语言成绩记录簿 -
尾义二甲: /*头文件*/

长海县19716105473: 编程如何用C语言编写一个学生成绩管理系统程序 -
尾义二甲: 我们才做了这个作业... #include <malloc.h> #include <stdio.h> #include <stdlib.h> #define LEN sizeof(struct scorenode) #define DEBUG #include <string.h> struct scorenode { int number;/*学号*/ char name[8];/*姓名*/ float cj1;/*成绩1*/ ...

长海县19716105473: 怎样用c语言编简单的成绩查询
尾义二甲: 对于每个学生的信息,用下面的结构体存储: typedef struct {char name[30];char number[20];int grade; }student; 23个人用个结构体数组就行了. 大致流程如下:先将数据信息从键盘输入,并写到相应的文件中,文件格式自定就可以了.在查询的时候,先从键盘读入要查询的学号或者姓名,再去从文件中读数据,逐个匹配就行了.至于代码,建议还是你自己多动手写,这样才会有进步.希望对你有帮助!

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网