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

📄 student.c

📁 我写的学生信息管理系统,希望可以给大家带来帮助
💻 C
📖 第 1 页 / 共 4 页
字号:
}
///////////////////////统计单科成绩前三名///////////////////////
void StatSubThree(int (*p)(),int (*q)(),int i)
{
    struct student *node; 
    
    int m=1,n,j=6;
    DataInsertionSort(head,p);
    node=head->next;
    while (node->next!=NULL)
    {
        if (m>2&&(*q)(node))
        {
            break;
        }
        node=node->next;
        m++;
    }       
    node=head->next;  
    for(n=1;n<=m;n++)
    {
        printf("\n\t%4s",node->sno);
    	
        printf("  \t%-20s",node->name);
    	
        printf("\t%d",node->age);
    	
        printf("\t%6.1f\n",node->grade[i]);
        node=node->next;
    }
    printf("\n");
}
void StatTotThree(int (*p)(),int (*q)())
{
    struct student *node; 
    
    int m=1,i;
    DataInsertionSort(head,p);
    node=head->next;
    while (node->next!=NULL)
    {
        if (m>2&&(*q)(node))
        {
            break;
        }
        node=node->next;
        m++;
    }       
    node=head->next;
    printf("\t\tTop3 by Total Garde\n\n");
    for(i=1;i<=m;i++)
    {
        printf("\t%4s",node->sno);
    	
        printf("  \t%-20s",node->name);
    	
        printf("\t%d",node->age);
        printf("\t%6.1f\n",total(node));
        node=node->next;
    }
    printf("\n");
}
void  Average(struct student *head,int n)
{
    int i = 0;
    float grade1 = 0.0f,grade2 = 0.0f,grade3 = 0.0f,grade4 = 0.0f, grade5 = 0.0f;
    struct student *node; 
    node=head->next;
    for(i=1;i<=n;i++)
    {
        grade1 +=node->grade[0];
        grade2 +=node->grade[1];
        grade3 +=node->grade[2];
        grade4 +=node->grade[3];
        grade5 +=node->grade[4];
        node = node->next;
    }
    printf("---------------------------SubjectAverage---------------------------\n\n");
    printf("\t Chinese\tEnglish\tMath\tPhysics\tChemistry\n");
    printf("\t %7.1f\t%7.1f\t%.1f\t%7.1f\t%9.1f\n",grade1/n,grade2/n,grade3/n,grade4/n,grade5/n);
}
//////////////////////////成绩前后结点比较////////////////////////
int ContrastChigrade(struct student *p)
{
    return p->grade[0] > p->next->grade[0];
}
int ContrastEnggrade(struct student *p)
{
    return p->grade[0] > p->next->grade[0];
}
int ContrastMatgrade(struct student *p)
{
    return p->grade[0] > p->next->grade[0];
}
int ContrastPhygrade(struct student *p)
{
    return p->grade[0] > p->next->grade[0];
}
int ContrastChegrade(struct student *p)
{
    return p->grade[0] > p->next->grade[0];
}
int ContrastTotgrade(struct student *p)
{
    return total(p) > total(p->next);
}
/////////////////////按学号查询////////////////////


struct student *searchbysno(struct student *node)
{
    int i,sign=0;
    char str[4],str1[4];
    node=node->next;
    system("cls");
    winstudengrade();
    goxy(35,0);
    printf("SearchBySno");
    goxy(2,19);
    printf("Please input student Sno[001-100]:");
    while (1)
    {
        goxy(37,19);
        GetString(str1,3);
        ReMoveSpece(str1,str);
        for (i=0;i<3;i++)      //判断是否数字
        {
            if (!isdigit(str[i]))
    		{
                sign=1;
                goxy(2,21);
                printf("your input number is error,please input again");
                goxy(2,22);
                printf("Press any ch to continue");
                getch();
                goxy(41,20);
                printf("     ");
                goxy(2,21);
                printf("                                                ");
                goxy(2,22);
                printf("                           ");
                break;
    		}
        }
        if (sign==1)
            sign=0;
        else
            break;
    }
    while (node!=NULL)
    {
        if (strstr(node->sno,str))
        {
            goxy(1,7);
            printf("%-5s%-20s%3d%8.1f%8.1f%5.1f%8.1f",node->sno,node->name,node->age,node->grade[0],node->grade[1],node->grade[2],node->grade[3]);
            printf("%10.1f%6.1f%5.1f",node->grade[4],total(node),total(node)/5.0);
            return node;
        }
        node=node->next;
    }
    return 0;   
}
/////////////////////////按姓名查询///////////////////
struct student *searchbyname(struct student *node)
{
    int i,j=7,k=0,stringlen,fsign=0,ssign=0,lenth=0;
    char str[21],str1[21];
    node=head->next;
    system("cls");
    winstudengrade();
    goxy(35,0);
    printf("SearchByName");
    goxy(2,20);
    printf("Please input the student name:");
    while (1)
    {
        goxy(32,20);
        GetString(str1,20);
        ReMoveSpece(str1,str);
        stringlen=strlen(str);
        for (i=0;i<stringlen;i++)        //判断是否字母
        {
            if (!isalpha(str[i]))
    		{
                fsign=1;
                goxy(2,21);
                printf("please input  Letters");
                goxy(2,22);
                printf("Press any ch to continue");
                getch();
                goxy(32,20);
                printf("                                  ");
                goxy(2,21);
                printf("                                                ");
                goxy(2,22);
                printf("                           ");
                break;
    		}
        }
        if (fsign==1)
            fsign=0;
        else
            break;
    }
  for (i=0;i<stringlen;i++)
    {
        str[i]=tolower(str[i]);		
    }	
    while (node!=NULL)
    {
        strcpy(str1,node->name);    
        for (i=0;i<(int)strlen(str1);i++)
    	{
            str1[i]=tolower(str1[i]);
    	}
        if (strstr(str1,str))
        {
            goxy(1,j);
            j++;
            printf("%-5s%-20s%3d%8.1f%8.1f%5.1f%8.1f",node->sno,node->name,node->age,node->grade[0],node->grade[1],node->grade[2],node->grade[3]);
            printf("%10.1f%6.1f%5.1f",node->grade[4],total(node),total(node)/5.0);
            ssign=1;
    		
            flag[k]=node;
    		
        	k++;
        }
        node=node->next;
    }
    if (ssign==0)
        return 0;
    else
        return flag[0];
}
/////////////////////删除学生信息////////////////////////
void deleteinfo(struct student *node)
{
    g_sav=0;
    if (node->next!=NULL)
    {
        node->pre->next=node->next;
        node->next->pre=node->pre;  
        strcpy(num[g_z],node->sno);
        g_z++;
        free(node);
        g_count--;      
    }
    else
    {
        node->pre->next=NULL;
        strcpy(num[g_z],node->sno);
        g_z++;
        free(node);
        g_count--;    
    }
}
int GetLength()
{
    struct student *temp;
    int len=0;
    temp=head->next;	
    while(temp!=NULL)
    {
        len++;
        temp=temp->next;
    }
    return len;
}
int Select(char str1[])
{   
    char str[1];
    do
    {	
        goxy(2,18);	
        printf("%s",str1);	
        GetString(str,1);
        if(str[0]=='Y'||str[0]=='y')
            return 1;
        else if(str[0]=='N'||str[0]=='n')
            return -1;
        else
    	{
            goxy(2,18);
            printf("                                                                    ");
            goxy(2,18);
            printf("Please input Y(y) or N(n),Press input any key to continue!");
            getch();
            goxy(2,18);
            printf("                                                                     ");			
    	}
    }while(1);		
}

///////////////////////保存学生信息///////////////////////////
void savefile()
{
    char filename[9];
    int m=0;
    if(g_count<=0)
    {
        goxy(2,20);
        printf("The system has no record!!");
        system("pause");
    }
    else
    {
    	do
    	{
            system("cls");
            InterPhase();
            WinMessage("Save Info");
            goxy(23,9);
            printf("Please input the file name:");
            FileName(filename);
            if((access(filename,0)) == 0)
    		{
                m=Select("The filename is exist,do you want to cover with it?  Y(y) or N(n):");
            	if(m==1)
        			;
                else if(m==-1)
                	continue;
    		}
            if (save(filename,head))
    		{
                g_sav = 1;
                goxy(2,20);
                printf("Save succeed,press any ch to continue");
            	getch();
            	return;
    		}
        	else
    		{
                goxy(2,20);
                printf("Save failed,press any ch to continue");
            	getch();
            	return;
    		}
        }while(1);
    }
}
////////////////////////////保存/////////////////////////////
int save(char str[],struct student *node)
{
    int i=0;
    i=GetLength();
    fp=fopen(str,"wb");
    node=node->next;
    if (fp!=NULL)
    {
        fwrite(&i,sizeof(int),1,fp);
        while(node!=NULL)
    	{
            fwrite(node,sizeof(struct student),1,fp);  
            node=node->next;			
    	}
        fwrite(num,400*sizeof(char),1,fp);
        fwrite(&g_z,sizeof(int),1,fp);
    }
    fclose(fp);
    return 1;
}
void DeleteAll()
{
    struct student *preNode = head->next;
    temp = head->next;
    while(temp != NULL)
    {
        preNode = temp;
        temp = temp->next;
        free (preNode);
    }
    head = NULL;
}
////////////////////////////读取学生信息//////////////////////////
void Loadfile()
{
    char filename[9];
    int m;
    if(g_sav == 0)
    {
        m = Select("Do you want to save the record?Press Y(y) or N(n):");
        if(m == 1)
    	{	
            system("cls");
            savefile();
    	}
        else if(m == -1)
    		;
        DeleteAll();
        goxy(2,18);
        printf("                                                                   ");
        goxy(2,19);
        printf("                                                                   ");
        goxy(2,20);
        printf("                                                                   ");
    }
    while(1)
    {
        system("cls");
        InterPhase();
        WinMessage("LoadInfo");
        goxy(23,9);
        printf("Please input the file name:");
        goxy(2,20);
        printf("Please load the record to system");
        getch();
        goxy(2,20);
        printf("                                    ");		
        FileName(filename); 
        if(Loading(filename) == 1)
    	{
            goxy(2,21);
            printf("Load succees,Press any key to continue");
            getch();
            return;    	    	
    	}
        if (Loading(filename) == 0)
    	{
            m=Select("Load fail,do you want to select again? Y(y) or N(n):");
            if(m==1)
                continue;
            else if(m==-1)
                return;						
    	}
    }
}

////////////////////////////读取/////////////
int Loading(char str[])
{
    int success = 1 ,n = 0 ,i = 0,j = 0,k = 0,m = 0;
    fp=fopen(str,"rb"); 
    if (fp == NULL)
        return 0;
    if (fp != NULL)
    {
        fread(&j,sizeof(int),1,fp);
        temp = (struct student *)malloc(sizeof(struct student));
        g_count = 0;
        while(k<j)
        {			
            fread(temp,sizeof(struct student),1,fp);
            if (head == NULL)
        	{   
                head=(struct student*)malloc(LEN); 
                head->pre=NULL;
                tail=head;
                temp->next=NULL;
                temp->pre=tail;
                tail->next=temp;
                tail=temp;		 
        	}	
        	else
        	{	
                temp->next=NULL;
                temp->pre=tail;
                tail->next=temp;
                tail=temp;

⌨️ 快捷键说明

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