有30个学生,每个学生的数据包括学号,姓名,数学,英语,计算机3门课,成绩和总分。要求编写c程序
/** 有30个学生,每个学生的数据包括学号、姓名、数学,英语,计算机3门课成绩和总分。* 要求编写C程序,完成以下任务:* 1. 从键盘输入30个学生的数据信息,计算每个学生3门课的总成绩,并按总分的高低依次输出每个学生的学号、姓名,3门课成绩及总分。* 2. 统计各课最高分和最低分,并输出对应学生的数据信息* 3. 统计各课及格和不及格的人数,输出对应学生的数据信息。*/#include#define N 30struct STUDENT{ char num[6]; char name[20]; float score[3]; float sum;};struct STUDENT stu[N];void print_student(struct STUDENT user){ printf("学号:%s\t姓名:%s\t数学:%3.2f\t英语:%3.2f\t计算机:%3.2f\t总分:%3.2f\n", user.num, user.name, user.score[0], user.score[1], user.score[2], user.sum );}int main(){ int i, j, temp, k; char* score[3] = {"数学", "英语", "计算机"}; int sort[N]; int ss[3][N]; for(i=0; i= 60) { j++; } } printf("%s及格学生人数(%d):\n", score[k], j); for(i=0; i<j; i++) { print_student(stu[ss[k][i]]); } printf("%s不及格学生人数(%d):\n", score[k], N-j); for(i=j; i<N; i++) { print_student(stu[ss[k][i]]); } } return 0;}这样就可以了
编制一个C语言成绩记录簿,每个学生信息包括:学号、姓名、C语言成绩。 具体功能看问题补充
// 某班级学生C语言第一次正考的成绩存于数据文件score.dat中,记录了学生学号、姓名和考试成绩,bk.dat文件中记录了补考学生的学号、姓名和补考成绩,编写程序以链式存储结构实现以下要求:// 1、对该班级按成绩降序排序并统计成绩平均分及每个分数段的人数,结果写入到result.dat中。// 2、再根据补考成绩修改原成绩,修改成绩后仍按成绩降序写在result.dat的后面。成绩修改原则:// 1)补考成绩大于等于60,原成绩以60分记;2)补考成绩小于60,取两次成绩中最高值记。#include#include#include#define MAX 50typedef struct {int xh; //学生学号、姓名和考试成绩char na[MAX];float cj;}datatype;typedef struct Node{datatype data;struct Node* next;} Seqlist;void print(Seqlist* l);void initList(Seqlist *lp);/*置一个空表*/void createList(Seqlist *lp, char strname[]);/*建立成绩顺序表 */void save(Seqlist *lp, char strname[]);/*保存学生顺序表到指定文件*/void sort_cj(Seqlist *lp); /*降序排序*/void average(Seqlist *lp); /*算平均分并写入文件 */void bandscore(Seqlist *lp);/*划分分数段及写入 */void changescore(Seqlist *lp, Seqlist *bk); /*修改成绩*/int main(){Seqlist lp, bk;initList(&lp); initList(&bk);createList(&lp, "score.dat");createList(&bk, "bk.dat");sort_cj(&lp);save(&lp, "result.dat");average(&lp);bandscore(&lp);changescore(&lp, &bk);sort_cj(&lp);save(&lp, "result.dat");return 0;}/*置一个空表*/void initList(Seqlist *lp){lp->next = 0;lp->data.xh =0;lp->data.na[0]='\0';lp->data.cj = 0;}void print(Seqlist*l){Seqlist* p = l->next;while (p){printf("%d %s %f\n", p->data.xh, p->data.na,p->data.cj);p = p->next;}}/*建立成绩顺序表 */void createList(Seqlist *lp, char strname[]){FILE *fp;int xh;float cj;Seqlist*p,*tail=lp;if ((fp = fopen(strname, "rb")) == NULL){printf("file open error\r\n");exit(0);}while (!feof(fp)){p = (Seqlist*)malloc(sizeof(Seqlist));fscanf(fp, "%d%s%f", &p->data.xh, p->data.na, &p->data.cj);tail->next = p;tail = p;}tail->next = NULL; print(lp);fclose(fp);}/*降序排序*/void sort_cj(Seqlist* head){Seqlist* tail = NULL;while (tail != head->next){Seqlist* pre = head;Seqlist* cur = pre->next;while (cur != tail && cur->next != tail){if (cur->data.cjnext->data.cj){//交换当前节点和后一个节点pre->next = cur->next;cur->next = cur->next->next;pre->next->next = cur;}pre = pre->next;cur = pre->next;}tail = cur;}}/*保存学生顺序表到文件(追加)*/void save(Seqlist *l, char strname[]){FILE *fp;Seqlist *lp= l->next;int i;if ((fp = fopen(strname, "ab")) == NULL){printf("file open error\r\n");exit(0);}while (lp){fprintf(fp, "%d %s %.2f\r\n", lp->data.xh, lp->data.na, lp->data.cj);lp = lp->next;}fprintf(fp, "\r\n");fclose(fp);}/*算平均分并写入文件 */void average(Seqlist *l){FILE *fp;int i,num=0;Seqlist *lp = l->next;float s = 0, a;while (lp){num++;s += lp->data.cj;lp = lp->next;}if (num)a = s / num;if ((fp = fopen("result.dat", "ab")) == NULL){printf("file open error\r\n");exit(0);}fprintf(fp, "平均分为%.2f\r\n", a);fprintf(fp, "\r\n");fclose(fp);}/*分数段及写入 */void bandscore(Seqlist *l){FILE *fp;if ((fp = fopen("result.dat", "ab")) == NULL){printf("file open error\r\n");exit(0);}Seqlist*lp = l->next;int i, a = 0, q = 0, w = 0, e = 0, r = 0, t = 0, y = 0;while (lp){a = lp->data.cj / 10;lp = lp->next;switch (a){case 10:q++; break;case 9:w++; break;case 8:e++; break;case 7:r++; break;case 6:t++; break;default:y++; break;}}fprintf(fp, "成绩为100有%d人\r\n", q);fprintf(fp, "成绩为90~99有%d人\r\n", w);fprintf(fp, "成绩为80~89有%d人\r\n", e);fprintf(fp, "成绩为70~79有%d人\r\n", r);fprintf(fp, "成绩为60~69有%d人\r\n", t);fprintf(fp, "不及格的有%d人\r\n", y);fprintf(fp, "\r\n");fclose(fp);}/*修改成绩*/void changescore(Seqlist *lp, Seqlist *bk){int i, j;Seqlist*la = lp->next, *lb = bk->next;while (lb){while (la){if (lb->data.xh == la->data.xh){if (lb->data.cj >= 60)la->data.cj = 60;else if (lb->data.cj > la->data.cj) la->data.cj = lb->data.cj;break;}la = la->next;}lb = lb->next;}print(lp);}