大一上学期C语言学生奖学金管理系统

大一上学期C语言课程设计

总结:程序中还存在很多的bug,也有很多功能没完善,但这是人生中第一个课设,故发表出来纪念一下。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN sizeof(struct student) 

struct student
{
   
   
   char num[15];
   char name[10];
   int clas;
   int Math;
   int English;
   int Physic;
   int sum;
   int rank;
   struct student *next;	
} ;

void create(void)  //录入信息 
{
   
   
	struct student *head,*p1,*p2;
	FILE *fp;
	int n=0; 
	head=NULL;
	p1=p2=(struct student *)malloc(LEN);
	printf("please enter the schoolnumber(such as 5116),name,class(such as 11),and the score of Math,English and Physic:\n");
	scanf("%s",p1->num);
	getchar();
	while(p1->num[0]!='@')  //录入信息以@结束 
	{
   
   
		scanf("%s%d%d%d%d",p1->name,&p1->clas,&p1->Math,&p1->English,&p1->Physic);  //出错,因没加&!!! 
		p1->rank=0;
		p1->sum=0;   
		n++;
		if(n==1) head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student *)malloc(LEN);
		scanf("%s",p1->num);
		getchar();
	}
	p2->next=NULL;
	free(p1);
	printf("record is OK!\n");
	if((fp=fopen("student.txt","w"))==NULL)
	{
   
   
		printf("cannot open file!\n");
		//fclose(fp);
		exit(0);
	}
	p1=head;
	while(p1!=NULL)  //数据存放再文件中 
	{
   
    
		fprintf(fp,"%s %s %d %d %d %d %d %d\n",p1->num,p1->name,p1->clas,p1->Math,p1->English,p1->Physic,p1->sum,p1->rank);
		p1=p1->next; 
	} 
	fclose(fp);	  	
}

/***********
void record(struct student *p1)//讲链表中的数据放在文件student.txt中 
{
  	FILE *fp;
  	struct student *p;
  	//char filename[10];
  	p=p1;
  	//printf("...........\n");
  	//scanf("%s",filename);
	if((fp=fopen("student.txt","w"))==NULL)
	{
		printf("cannot open file!\n");
		//fclose(fp);
		exit(0);
	}
	while(p!=NULL)  //数据存放再文件中 
	{ 
		fprintf(fp,"%s %s %d %d %d %d %d %d\n",p->num,p->name,p->clas,p->Math,p->English,p->Physic,p->sum,p->rank);
		p=p->next; 
	} 
	free(p);  //释放内存                                                               //     出错!     因把p1内存释放导致出错 
	fclose(fp);	  	
	
}
*********/
void print(struct student *head)  //输出全部数据函数 
{
   
   
	struct student *p;
	p=head; 
	printf("---------------------------STUDENT--------------------------------------\n");
	printf("|num           |name   |clas  |Math  |English  |Physic     |sum  |rank  |\n");
    printf("------------------------------------------------------------------------\n");	
	while(p!=NULL)
	{
   
   
		printf(" %-15s%-10s%-7d%-7d%-10d%-10d%-7d%-5d\n",p->num,p->name,p->clas,p->Math,p->English,p->Physic,p->sum,p->rank);
		p=p->next;
	}
}

void searchbyscore(struct student *head)  //按成绩段查询信息 
{
   
   
	struct student *p;
	char s[10];
	int a,b,k;
	p=head;
	printf("please enter the range of score,such as 60--70:\n");
	scanf("%d--%d",&a,&b);
	if(a>b||a==b)
	printf("Your enter is wrong !\n");
	else
	{
   
   
		printf("please choose the course ,Math,English or Physic:\n");
		scanf("%s",s);  //存放要查询的成绩
		if(strcmp(s,"Math")==0)
		{
   
   
			k=0;
			while(p!=NULL)
			{
   
   
				if(p->Math>=a&&p->Math<=b)
				{
   
   
					k++;
					if(k==1)
					{
   
   
						printf("---------------------------STUDENT--------------------------------------\n");
						printf("|num           |name   |clas  |Math  |English  |Physic     |sum  |rank  |\n");
    					printf("------------------------------------------------------------------------\n");
    				}
					printf(" %-15s%-10s%-7d%-7d%-10d%-10d%-7d%-5d\n",p->num,p->name,p->clas,p->Math,p->English,p->Physic,p->sum,p->rank);
				}
				p=p->next;
			}
			if(k==0)
			printf("not found the statistic !\n");
		} 
		else if(strcmp(s,"English")==0)
		{
   
   
			
			k=0;
			while(p!=NULL)
			{
   
   
				if(p->English>=a&&p->English<=b)
				{
   
   
					k++;
					if(k==1)
					{
   
   
						printf("---------------------------STUDENT--------------------------------------\n");
						printf("|num           |name   |clas  |Math  |English  |Physic     |sum  |rank  |\n");
    					printf("------------------------------------------------------------------------\n");
    				}
					printf(" %-15s%-10s%-7d%-7d%-10d%-10d%-7d%-5d\n",p->num,p->name,p->clas,p->Math,p->English,p->Physic,p->sum,p->rank);
				 }
				p=p->next;
			}
			if(k==0)
			printf("not found the statistic !\n");
		} 		
		else if(strcmp(s,"Physic")==0)
		{
   
   
			
			k=0;
			while(p!=NULL)
			{
   
   
				if(p->Physic>=a&&p->Physic<=b)
				{
   
   
					k++;
					if(k==1)
					{
   
   
						printf("---------------------------STUDENT--------------------------------------\n");
						printf("|num           |name   |clas  |Math  |English  |Physic     |sum  |rank  |\n");
    					pri
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值