⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_c.cpp

📁 学生管理系统
💻 CPP
字号:
//程序设计基础二 综合作业
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct stud        //学生信息结构
{
  long   num; 
  char   name[20];
  double score;
};

struct studcode
{
	struct stud student; 
    struct studcode *next;
};
void create(struct studcode **,int*);
void chazhao1(struct studcode **);
void chazhao2(struct studcode **);
void shanchu(struct studcode **,int *);
void charu(struct studcode **,int *);
void paixu(struct studcode *,int);
void menu()   //综合作业功能菜单
{
    	printf(" \n                         学 生 信 息 管 理 系 统\n");
		printf(" \n                                 菜  单\n\n");
		printf(" \n                   1.    建  立  链  表  并  显  示 \n");
		printf(" \n                   2.    查 找 某 学 号 的 学 生 信 息 \n");
		printf(" \n                   3.    查 找 某 姓 名 的 学 生 信 息 \n");
		printf(" \n                   4.    删 除 某 个 学 号 的 学 生\n");
		printf(" \n                   5.    插 入 新 的 学 生 信 息 \n");
		printf(" \n                   6.    按 分 数 降 序 排 序 输 出 \n");
		printf(" \n                   0.    退      出\n\n");
}

void main()
{
	char choose;
	int  flag=1;
	int n;
  struct studcode *head;
  head=NULL;
    while (flag)	    
	{
    	menu();    //调用功能菜单函数,显示菜单项。
    	printf("      请选择:");
        choose=getchar();

		switch(choose)
		{
		   case '1':                               
			       create(&head,&n);//调用建立链表的函数;输出链表信息;
			       
				   getchar();
				   getchar();
			       break; 
		   case '2': if(head==NULL) printf("         请先建链表");     
			       else chazhao1(&head);//调用按学号查找学生信息的函数;并输出查找结果信息;
			      
				   getchar();
				   getchar();
			       break;
		   case '3': if(head==NULL) printf("         请先建链表");     
			      else chazhao2(&head); //调用按姓名查找学生信息的函数;并输出查找结果信息;
			       
				   getchar();
				   getchar();
			       break;
           case '4': if(head==NULL) printf("          请先建链表");	 
			     else shanchu(&head,&n); //调用根据学号删除某个学生信息的函数;并输出删除后的链表信息;
			      
				   getchar();
				   getchar();
			       break;
		   case '5': if(head==NULL) printf("          请先建链表");	
			     else charu(&head,&n); //调用插入新的学生信息的函数;并输出插入后的链表信息;
			       
				   getchar();
				   getchar();
			       break;
		   case '6': if(head==NULL) printf("      请先建链表");    
			     else paixu(head,n); //调用按分数降序排序输出的函数;并输出排序后的链表信息;
			      
				   getchar();
				   getchar();
			       break;
           case '0': 
			       //结束程序运行!
			       flag=0;
				   printf("\n     *** The End! ***\n");
				   break;
		   default: printf("\n    Wrong Selection !(选择错误,重选)\n");
		}
	 }
}
void create(struct studcode **head,int *v)
{
	struct studcode *p;
	struct stud a;
	 int b=0;
	printf("input numbers end of 0\n");
	printf("学号\t姓名\t成绩\n");
	scanf("%ld %s %lf",&a.num,a.name,&a.score);
	
	 while(a.num){
     
		 p=(struct studcode *) malloc (sizeof(struct studcode));
        p->student=a;
	    p->next=*head;
	
	   *head=p;
	
     scanf("%ld %s %lf",&a.num,a.name,&a.score);
		b++;
	 }
	 p=*head;
 printf("学号\t姓名\t成绩\n");
	 while(p!=NULL)
	 {  
        
		 printf("%ld\t%s\t%0.2lf\n",p->student.num,p->student.name,p->student.score);
		 p=p->next;
	 }
	 printf("\n");
	 *v=b;
	 
}
void chazhao1(struct studcode * *head)
{
	int m=0;
	long x;
	struct studcode *p;
	p=*head;
 
	scanf("%ld",&x);
	
	while(p!=NULL)
	{
		if(p->student.num==x)
		{
             printf("学号\t姓名\t成绩\n");  
			printf("%ld\t%s\t%0.2lf\n",p->student.num,p->student.name,p->student.score);
			m=1;break;
		}
		else p=p->next;
	}
	if(m==0) printf("not find\n");
}
void chazhao2(struct studcode * *head)
{
	int m=0;
	char name[20];
	struct studcode *p;
	p=*head;
	scanf("%s",name);
	while(p!=NULL)
	{
		if(strcmp(name,p->student.name)==0)
		{
           printf("学号\t姓名\t成绩\n");
			printf("%ld\t%s\t%0.2lf\n",p->student.num,p->student.name,p->student.score);
			m=1;break;
		}
		 p=p->next;
	}
	if(m==0) printf("not find\n");
}
void shanchu(struct studcode * *head,int*v)
{
	
	long x;
	struct studcode *p,*last;
	p=*head;
   scanf("%ld",&x);
   
	while(p->student.num!=x&&p->next!=NULL)
	{
		last=p;
		p=p->next;
	}
	if(p->student.num==x)
	{
		if(p==*head)
			*head=p->next;
		else last->next=p->next;
		free(p);
	}
     p=*head;
 printf("学号\t姓名\t成绩\n");
	 while(p!=NULL)
	 {
		 printf("%ld\t%s\t%0.2lf\n",p->student.num,p->student.name,p->student.score);
		 p=p->next;
	 }
	 printf("\n");
	 --*v;
}

void charu(struct studcode * *head,int*v)
{
	struct studcode *other,*current,*last,*p;
    struct stud xin;
 printf("学号\t姓名\t成绩\n");
    scanf("%ld %s %lf",&xin.num,xin.name,&xin.score);
   
  
  other=(struct studcode *) malloc (sizeof(struct studcode));
   other->student=xin;
   current=*head;
   while(xin.num<current->student.num&&current->next!=NULL)
   {
	   last=current;
	   current=current->next;
   }
   if(xin.num>current->student.num)
	   if(current==*head)
	   {
		   other->next=*head;
		   *head=other;
	   }
	   else{
		   other->next=current;
		   last->next=other;
	   }
	   else{
		   other->next=NULL;
		   current->next=other;
	   }
  
  p=*head;
 printf("学号\t姓名\t成绩\n");
	 while(p!=NULL)
	 {
		 printf("%ld\t%s\t%0.2lf\n",p->student.num,p->student.name,p->student.score);
		 p=p->next;
	 }
	 printf("\n");
	 ++*v;
	 
}

void paixu(struct studcode *head,int n)
{
	int i,j;
	struct stud temp;
	struct studcode *p1,*p2,*p;
	for(p1=head,i=0;i<n-1;i++,p1=p1->next)
		for(p2=p1->next,j=i+1;j<n;j++,p2=p2->next)
		if(p1->student.score<p2->student.score)
		{
			temp=p2->student;
			p2->student=p1->student;
            p1->student=temp;
		}
 printf("学号\t姓名\t成绩\n");
		for(p=head;p!=NULL;p=p->next)
			 printf("%ld\t%s\t%0.2lf\n",p->student.num,p->student.name,p->student.score);
		 
}


		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -