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

📄 student_manage.c

📁 student_manage简单的实现了学生信息管理信息系统
💻 C
字号:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
typedef struct Student
{
int Num;
char Name[20];
int Score;
struct Student *next;
}StuNode;
int Creat(StuNode* Head);  int Print(StuNode* Head);
int Insert(StuNode* Head,StuNode* newNode,int Position);
StuNode* Search(StuNode* Head,int Num);int Delete(StuNode*Head,int Num);StuNode *sort(StuNode*Head);
StuNode *namesort(StuNode *Head);
void main()
{
StuNode *StuList,*newStuNode;
int newStu,StuNum;
int Selection;
do
	{
printf(“******************************************************\n”); printf(“Menu:\n”); printf(“1: create list.\n”); printf(“2: print list.\n”); printf(“3: insert node.\n”); printf(“4: delete node.\n”); printf(“5: search a student.\n”); printf(“6:sort the list by the number.\n”); printf(“7:sort the list by the name.\n”); printf(“0:exit.\n”); printf(“******************************************************\n”); printf(“Your selection is:”); scanf(“%d”,&Selection); printf(“\n\n”); switch (Selection)
		{
case 1:StuList=(StuNode*)malloc(sizeof(StuNode));
StuList->next=NULL;
Creat(StuList); break;
case 2:
Print(StuList); break;
case 3:
printf(“Please input the position after the new student:”); scanf(“%d”,&newStu); if ((newStuNode=(StuNode*)malloc(sizeof(StuNode)))==NULL){
printf(“The memory is insufficient.\n”);
			}
printf(“Please input this student\’ information(Num,Score,Name):”); scanf(“%d,%d”,&newStuNode->Num,&newStuNode->Score); getchar(); gets(newStuNode->Name);
Insert(StuList,newStuNode,newStu); break;
case 4:
printf(“Please input the number to delete:”); scanf(“%d”,&StuNum);
Delete(StuList,StuNum); break;
case 5:
printf(“Please input the number of the student:”); scanf(“%d”,&StuNum); newStuNode=Search(StuList,StuNum); if (newStuNode!=NULL)
			{
printf(“The No. %d student\’ score is %d,his name is %s.\n”,newStuNode->Num,newStuNode->Score,newStuNode->Name);
			}
else
			{
printf(“There is not a such student.\n”);
			}
break; case 0:
break; case 6:sort(StuList);
break; case 7:namesort(StuList);
break; default:
printf(“Your selection is error.\n”);
		}
}while(Selection!=0);
}
int Creat(StuNode* Head)
{
int i,n;
StuNode *newNode,*Last;
printf(“Please input the number of students:”);
scanf(“%d”,&n);
newNode=(StuNode*)malloc(sizeof(StuNode));
if (newNode==NULL)
	{
printf(“The memory is insufficient.\n”);
return 0;
	}
printf(“Please input the information of NO.1 student(Num,Score,Name):”); scanf(“%d,%d”,&newNode->Num,&newNode->Score); getchar(); gets(newNode->Name);
Head->next=newNode; newNode->next=NULL;
Last=newNode; for (i=1;i<n;i++)
	{
newNode=(StuNode*)malloc(sizeof(StuNode));
if (newNode==NULL)
		{
printf(“The memory is insufficient.\n”);
return 0;
		}
printf(“Please input the information of NO. %d student(Num,Score,Name):”,i+1); scanf(“%d,%d”,&newNode->Num,&newNode->Score); getchar(); gets(newNode->Name); newNode->next=NULL;
Last->next=newNode;   Last=newNode;
	}
return 1;
}
int Print(StuNode* Head)
{
StuNode *p;
if (Head==NULL)
	{
printf(“There is no information.\n”);
return 0;
	}
p=Head->next;
while (p!=NULL)
{ printf(“The No. %d student\’s score is %d,his name is %s\n”,p->Num,p->Score,p->Name); p=p->next;
	}
return 1;
}
int Insert(StuNode* Head,StuNode* newNode,int Position)
{
int Count;
StuNode *parent,*son;
if (Head==NULL)
return 0; if (Position==1)
	{
		newNode->next=Head->next;		Head->next=newNode;
		return 1;
	}
Count=1;
parent=Head;
son=parent->next;
while (son!=NULL && Count<Position)
	{
parent=son;
son=parent->next;
Count++;
	}
if (son==NULL)
return 0; newNode->next=son;	parent->next=newNode; return 1;
}
StuNode* Search(StuNode* Head,int Num)
{
StuNode *node;
if (Head==NULL)
	{
printf(“There is no students.\n”);
return NULL;
	}
node=Head->next;
while(node!=NULL && node->Num!=Num)
	{
node=node->next;
	}
if (node!=NULL)
	{return node;
	}
return NULL;
}
int Delete(StuNode* Head,int Num)
{
StuNode *parent,*son;
if (Head==NULL)
	{
printf(“There is no students.\n”);
return 0;
	}
parent=Head;
son=parent->next;
if (son!=NULL && son->Num!=Num)
	{
parent=son;
son=son->next;
	}
if (son==NULL)
	{
printf(“There is no such a student.\n”);
return 0;
	}
parent->next=son->next;
free(son);
return 1;
}
StuNode* sort(StuNode *Head)
{
StuNode *endpt     ,*p   , *p1   , *p2;
p1=Head;
for(endpt=NULL;endpt!=Head;endpt=p)
	 {
for(p=p1=Head;p1->next->next!=endpt;p1=p1->next)
		{
if(p1->next->Num>p1->next->next->Num)
			{
				p2=p1->next->next;				p1->next->next=p2->next;
				p2->next=p1->next;				p1->next=p2;
				p=p1->next->next;
			}
		}
	 }	 return(Head);
}
StuNode* namesort(StuNode *Head)
{
StuNode *endpt    ,*p    , *p1   ,*p2;
p1=Head;
for(endpt=NULL;endpt!=Head;endpt=p)
     {
for(p=p1=Head;p1->next->next!=endpt;p1=p1->next)
     {
if(strcmp(p1->next->Name,p1->next->next->Name)>0)
       {
	 p2=p1->next->next;	 p1->next->next=p2->next;	 p2->next=p1->next;
	 p1->next=p2;	 p=p1->next->next;
       }
      }
      }
return(Head);
}
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(DATE)
typedef struct date
{
int year;
int month;
int day;
}DATE;
int leap_year(int year)
{
return(year%4==0&&year%100==0||year%400==0);
}
int year_day(DATE *p)
{
int1m=p->month; return((p->day)+31*((m>1)+(m>3)+(m>5)+(m>7)+(m>8)+(m>10))+30*((m>4)+(m>6)+(m>9)+(m>11))+(28+leap_year(p->year))*(m>2));
}
long int day_sum(DATE *p1,DATE *p2)
{
int leayear=0,year=p1->year;
long int sum=0;
for(;year<p2->year;year++)
if(leap_year(year))
leayear++; sum=365*((p2->year)-(p1->year))+leayear; return(sum+year_day(p2)-year_day(p1));
}
void main()
{
int date(int,int,int);
void print(void);
DATE *date1,*date2,*newdate;
int c;
do
 {
printf(“**************************\n”);
printf(“1  Caculate the sum days.\n”);
printf(“2  Caculate the minus days.\n”);
printf(“3  print the calendar.\n”);
printf(“0  Exit.\n”);
printf(“***************************\n”);
printf(“Your selection is.”);
scanf(“%d”,&c);
switch?
  {
case 1:printf(“Input new date\n”);
newdate=(DATE*)malloc(LEN); scanf(“%d/%d/%d”,&newdate->year,&newdate->month,&newdate->day); printf(“It is the %d days\n”,year_day(newdate)); break;
case 2:printf(“Input two days\n”);
date1=(DATE*)malloc(LEN); if(date1==NULL)
printf(“There is no space\n”); scanf(“%d/%d/%d”,&date1->year,&date1->month,&date1->day);
date2=(DATE*)malloc(LEN); if(date2==NULL)
printf(“There is no space\n”); scanf(“%d/%d/%d”,&date2->year,&date2->month,&date2->day);
printf(“There are %ld days between the dates\n”,day_sum(date1,date2)); break;
case 3:printf(“Input a year.\n”);
print(); break;   
case 0:break; default :printf(“You press wrong,press again\n”);
   }
}while(c!=0);
}
int date(int year,int month,int day)//判断该年某月某日是星期几的计算 
{ int leap,cn=0,sum,m=month;//cn计算的是从该年1月1日起,到达这一天的天数总和 leap=leap_year(year); 
cn=day+31*((m>1)+(m>3)+(m>5)+(m>7)+(m>8)+(m>10))+30*((m>4)+(m>6)+(m>9)+(m>11))+(28+leap_year(year))*(m>2);
sum=year-1+(year-1)/4-(year-1)/100+(year-1)/400+cn;//这是核心的一条公式,返回值是星期几
return(sum%7); 
} 
void print(void)//打印的核心算法 
{ 
int i,j,n,leap,days,k,count,year;
scanf(“%d”,&year);
leap=leap_year(year);//判断是否闰年 
days=date(year,1,1);//计算该年第一天是星期几 
printf(“%dyear\n”,year); 
for(i=1;i<=12;i++) 
   { 
printf(“                       %3dmonth\n”,i); 
printf(“\n”); 
printf(“\t”); 
printf(“%-8s%-8s%-8s%-8s%-8s%-8s%-8s\n”,”Sun”,”Mon”,”Tues”,”Wed”,”Thurs”,”Fri”,”Sat”); if(days==7) 
	{ days=0;
n=days; 
	} 
else n=days; 
printf(“\t”); 
for(j=1;j<=8*days;j++) 
printf(“ “); 
count=31-((i==4)+(i==6)+(i==9)+(i==11))-(3-leap_year(year));
for(k=1;k<=count;k++)//以下代码是控制界面的对齐 
	{ 
printf(“%-8d”,k); 
n++; 
if(n==7) 
	{
printf(“\n”);
printf(“\t”);
n=0;
	  } 
	} 
printf(“\n\n”); days=n;   
 } 
}

⌨️ 快捷键说明

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