C语言大作业(全) 下载本文

内容发布更新时间 : 2024/12/30 0:18:41星期一 下面是文章的全部内容请认真阅读。

#include \#include \#include \#include \#include \

#define LEN sizeof(struct student) #define NULL 0 int n,m; int k=1;

struct student {char num[20]; char name[20]; int age;

char profession[50]; int maths; int english; int C_program; float ave;

struct student * next; };

float ave(struct student * p1) { }

void save(struct student *head) {

struct student *p1 = head; FILE *outFile;

outFile = fopen(\

if (outFile == NULL) { printf(\} else {

float ave;

ave=(float)(p1->maths+p1->english+p1->C_program)/3; return ave;

while(p1 != NULL) {

fwrite(p1, sizeof(struct student), 1, outFile); p1 = p1->next; }

fclose(outFile); } }

//将数据存入文档中

void check(struct student * head,struct student * p1) {struct student *h=head; for(m=0;mnext ) }

//检验学号是否重复

struct student * creat() {struct student * head; struct student *p1,*p2; n=0;

p1=p2=(struct student *)malloc(LEN); printf(\学号:\\n\ scanf(\ getchar();

printf(\姓名:\\n\ gets(p1->name); printf(\年龄:\\n\ scanf(\

getchar(); printf(\专业:\\n\

{ }

if(strcmp( h->num,p1->num)==0)

{printf(\输入号码重复\\n\printf(\请重新输入学号:\scanf(\getchar(); check(head,p1); }

gets(p1->profession); printf(\数学成绩:\\n\ scanf(\ printf(\英语成绩:\\n\ scanf(\ printf(\语言成绩:\\n\ scanf(\ head=NULL;

while(strcmp(p1->num,\{n=n+1;

if(n==1)head=p1; else p2->next=p1; p2=p1;

p1=(struct student *)malloc(LEN); printf(\学号:\\n\ scanf(\ getchar();

check(head,p1);//检查输入的学号是不是重复且是不是重复输错 printf(\姓名:\\n\ gets(p1->name); printf(\年龄:\\n\ scanf(\

getchar(); printf(\专业:\\n\ gets(p1->profession); printf(\数学成绩:\\n\ scanf(\ printf(\英语成绩:\\n\ scanf(\ printf(\语言成绩:\\n\ scanf(\}

p2->next=NULL; save(head); return(head);}

//录入数据并将其保存至文档

void print(struct student *head) {struct student * p;

printf(\这%d个学生的成绩为:\\n\

printf(\学号 姓名 年龄 专业 数学 英语 C语言 平均成绩\\n\