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

📄 student.c

📁 我写的学生信息管理系统,希望可以给大家带来帮助
💻 C
📖 第 1 页 / 共 4 页
字号:
#include <conio.h>
#include <stdio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include <math.h>
#include<windows.h> 
#include<time.h>
#include<io.h>
#define LEN sizeof(struct student)
struct student 
{    
    char sno[4];              //学号
    char name[21];            //姓名
    int  age;              //年龄
    float  grade[5]  ;          //成绩
    struct student *next;     //指向下一结点的指针
    struct student *pre; 
};
struct student *addstudentinfo();  //添加学生信息
void LandToSystem();               //登陆界面
void BuildStuId();                   //自动生成学号
void InputStuName();                  //输入姓名
int InputStuAge();                   //输入年龄
float InputStugrade();                 //输入成绩
int GetString(char str[100],int lenmax);//输入限定个数字符
int RestrictCode(char buffer[], int maxLen);//限制密码长度
void Addstu();
struct position                          
{
    int curX;//当前列数
    int curY;//当前行数
};
int GetLength();
struct student *flag[100]={0};
struct position GetCurentPos();        //获取当前光标位置
void InterPhase();                     //通用外框
void WinAddStudentInfo();                 //1.添加学生信息
void WinSortDate();                       //2.记录排序
void winprintreport();                    //3.打印学生成绩
void winstudengrade();
void winsearchstudents();                 //6.查询学生信息
void winwelcome();                        //欢迎界面
void goxy(int nx,int ny);                 //光标定位
void Time();                              //获得当前时间 
void WinMessage(char str[]);
FILE *fp;  
void Sortdate();                               //2.记录排序  
void printreport(struct student *head,int n);  //3.打印学生成绩 
void savefile();                               //4.保存学生信息
void searchstudents();                         //6.查询学生信息
void statgrade();                              //7.统计成绩
void out();                                    //0.退出
float total(struct student *nod);                //计算总分
void DataInsertionSort(struct student *head,int (*p)());            //排序
int SnoAscForm(struct student *p,struct student *q);       //学号升序
int SnoDescForm(struct student *p,struct student *q);      //学号降序
int TogradeAscForm(struct student *p,struct student *q);     //总分升序
int TogradeDescForm(struct student *p,struct student *q);    //总分降序
int ChineseDescForm(struct student *p,struct student *q);  //语文降序
int EnglishDescForm(struct student *p,struct student *q);  //英语降序
int MathDescForm(struct student *p,struct student *q);     //数学降序
int PhysicsDescForm(struct student *p,struct student *q);  //物理降序
int ChemistryDescForm(struct student *p,struct student *q);//化学降序   
void StatgradeThree(int (*p)(),int (*q)());             //统计成绩前三名
struct student *searchbysno(struct student *node); //按学号查询
struct student *searchbyname(struct student *node);//按姓名查询             
void deleteinfo(struct student *node);             //删除学生信息
int save(char str[],struct student *node);        //保存
void Loadfile();                                   //读取学生信息
int Loading(char str[]);              
int ContrastChigrade(struct student *p);  
int ContrastEnggrade(struct student *p);
int ContrastMatgrade(struct student *p);
int ContrastPhygrade(struct student *p);
int ContrastChegrade(struct student *p);
int ContrastTotgrade(struct student *p);
void StatSubThree(int (*p)(),int (*q)(),int i);
void StatTotThree(int (*p)(),int (*q)());
void Average(head,count);
struct student *temp,*tail=NULL,*head=NULL;
void ReMoveSpece(char str[],char str1[]);
void DeleStudent(struct student *key);
void DeleteAll();
void AddStudentInfo();
void PrimaryMenuList();
void Blank();
void SortSelect();
int Select(char str1[]);
void FileName(char filename[]);
#define N 10         
int g_count=0;
int  g_sav=1;            
char num[100][4];
int g_z=0;              										
void goxy(int nX, int nY)   /*光标定位的函数*/                    
{
    HANDLE   hCon;  
    COORD   setps;                        //定义一个句柄
    hCon = GetStdHandle(STD_OUTPUT_HANDLE);   //获得输出设备的句柄              									
    setps.X = nX;   
    setps.Y = nY; 
    SetConsoleCursorPosition(hCon,setps);     //定位
}
void Time()/*获得当前时间的函数*/
{
    time_t tval;   
    struct tm *now;     
    tval=time(NULL);   
    now=localtime(&tval);   
    printf("%4d-%d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);     
}
struct position GetCurentPos()/*获取当前光标位置的函数*/
{
    struct position pos;
    CONSOLE_SCREEN_BUFFER_INFO bInfo;
    HANDLE   hCon;//定义一个句柄
    hCon = GetStdHandle(STD_OUTPUT_HANDLE);   //获得输出设备的句柄
    
    GetConsoleScreenBufferInfo( hCon, &bInfo );
    pos.curX=bInfo.dwCursorPosition.X;
    pos.curY=bInfo.dwCursorPosition.Y;
    return pos;
}
void WinMessage(char str[])/*通用消息函数*/
{
    goxy(35,0);
    puts(str);
    goxy(35,17);
    printf(" Message ");
}
void InterPhase()/*通用外框函数*/
{
    int i,j;
    printf("%c",213);
    for(i=0;i<33;i++)
    {
        printf("%c",205);   
    }
    printf("           ");
    for(j=0;j<34;j++)
    {
        printf("%c",205);   
    }
    printf("%c",184);
    for(i=0;i<16;i++)
    {
        printf("%c",179);
        printf("%78c",'\000');
        printf("%c",179);
    }
    printf("%c",195);
    for(i=0;i<33;i++)
    {
        printf("%c",196);
    }
    printf("           ");
    for(j=0;j<34;j++)
    {
        printf("%c",196);
    }
    printf("%c",180);
    for(j=0;j<4;j++)
    {
        printf("%c",179);
        printf("%78c",'\000');
        printf("%c",179);
    }
    printf("%c",192);
    for(i=0;i<78;i++)
    {
        printf("%c",196);
    }
    printf("%c",217);
    printf(" Ver1.0                ----Auther:LiaoYuFan----               Date:");Time();
}
void WinAddStudentInfo()/*添加信息的界面*/
{
    InterPhase();
    WinMessage("Add Info");
    goxy(31,5);
    printf("Sno:");
    goxy(21,6);
    printf("Name[1-20bit]:");
    goxy(24,7);
    printf("Age[ 7-50]:");
    goxy(20,8);
    printf("Chinese[0-100]:");
    goxy(20,9);
    printf("English[0-100]:");
    goxy(23,10);
    printf("Math[0-100]:");
    goxy(20,11);
    printf("Physics[0-100]:");
    goxy(18,12);
    printf("Chemistry[0-100]:");
    goxy(35,5);    
}
void WinSortDate()/*记录排序的界面*/
{
    InterPhase();
    WinMessage("InfoSort");
    goxy(30,4);
    printf("1.Rise By Student Sno");
    goxy(30,6);
    printf("2.Descend Student By Sno");
    goxy(30,8);
    printf("3.Rise By The Total");
    goxy(30,10);
    printf("4.Descend By  The Total");
    goxy(30,12);
    printf("0.When To  Mune");
    goxy(30,14);
    printf("Please Make a Choice[0-4]:");
}
void winsearchstudents()/*查询学生信息功能界面*/
{
    InterPhase();
    WinMessage("SearchStu");
    goxy(27,5);
    printf("1.Search By student Sno");
    goxy(27,7);
    printf("2.Search By student Sname");
    goxy(27,9);
    printf("0.back");
    goxy(27,11);
    printf("Please Input a choice[0-2]:");
}
void winstudengrade()/*有关学生成绩界面*/
{
    int i;
    InterPhase();
    goxy(1,4);
    for(i=1;i<=78;i++)
    printf("-");
    goxy(1,6);
    for(i=1;i<=78;i++)
    printf("-");
    goxy(35,17);
    printf(" Message ");
    goxy(2,5);
    printf("Id  Name");
    goxy(26,5);
    printf("Age Chinese English Math Physics Chemistry Total Avg");
}
void Blank()/*输入是空格情况的封装*/
{
    goxy(2,19);
    printf("The name can't be a blank,Please input again:");
    goxy(2,20);
    printf("Please input any ch to continue");
    getch();
    goxy(2,19);
    printf("                                                   ");
    goxy(2,20);
    printf("                                    ");
}
/*选择菜单没记录时提示信息的封装*/
void NoRecord()
{
    InterPhase();
    system("cls");
    goxy(2,18);
    printf("The system has no record!!");
    system("pause");
    goxy(2,18);
    printf("                                                                          ");
    goxy(53,11);
    printf("          ");
    goxy(53,11);
}
/*排序功能选择是否打印函数的封装*/
void SortSelect()
{
    char key[1];
    system("cls");
    goxy(8,9);
    printf("Do you want to print the student,select Y(y) or N(n):");    			
    while(1)
    {	 
        goxy(2,20);
        printf("                                     ");
        goxy(64,9); 
        printf("   ");
        goxy(64,9);
        GetString(key,1);
        if(key[0]=='Y'||key[0]=='y')
    	{
            system("cls");
            printreport(head,g_count);
            return;
    	}
        else if (key[0]=='N'||key[0]=='n')
    	{
            return;
    	}
        else
    	{
            goxy(2,20);
            printf("Please input the char Y(y) or N(n)");
            getch();
            continue;
    	}
    }
}



/*判断文件名是否非法函数的封装*/
void FileName(char filename[])
{
        char str[9],str1[9]="        ";
        int i,sign=0;
        do  {
            sign=0;	  
            goxy(50,9);
            printf("              ");
            goxy(50,9);
            GetString(str,8);
            ReMoveSpece(str,filename);
            if(filename[0]==0)
    		{
            	Blank();
                sign = 1;
                continue;
    		}
            for (i=0;i<8;i++)   
    		{
                if (filename[i]=='\\' || filename[i]=='/' || filename[i]==':'
                    || filename[i]=='?' || filename[i]=='<' || filename[i]=='>' 
                    || filename[i]=='*' || filename[i]=='|' || filename[i]=='\"') 
        		{
                	goxy(2,20);
                    printf("The file name can't include \\ / : * ? \" < > | ");
                	goxy(2,21);
                    printf("Press any ch to input the file name again");
                	getch();
                	goxy(2,20);
                    printf("                                                   ");
                	goxy(2,21);
                    printf("                                            ");
            		sign=1;
                    strcpy(filename,str1);
            		break;
        		}
    		}
    		
        } while (sign==1);
    	}

////////////////////////////函数实现//////////////////////////
void main()
{
    //LandToSystem();   
    PrimaryMenuList();    	
}
void PrimaryMenuList()
{
    while(1)
    {
        char ch[1];
        int m=0;
        system("cls");
        InterPhase();
        goxy(34,0);
        printf(" Menu List ");
        goxy(34,17);
        printf(" Message ");
        goxy(2,18);
        printf("Hello World!!!");
        goxy(26, 3);
        printf("%s"," 1.  Add student's info                  \n");
        goxy(26, 4);
        printf("%s"," 2.  Sort data                           \n");
        goxy(26, 5);
        printf("%s"," 3.  Print student's report              \n");
        goxy(26, 6);
        printf("%s"," 4.  Save data to file                   \n");
        goxy(26, 7);
        printf("%s"," 5.  Load data from file                 \n");
        goxy(26, 8);
        printf("%s"," 6.  Search students                     \n");
        goxy(26, 9);
        printf("%s"," 7.  Stat grade                          \n");
        goxy(26, 10);
        printf("%s"," 0.  ExitSystem                          \n");
        goxy(26, 11);
        printf("%s"," please Input choice[0-7]:               \n\n");
        goxy(53, 11);				
        GetString(ch,1);
        if (ch[0]==0)
    	{
            Blank();
            continue;
    	}
        if (!isdigit(ch[0]))
    	{
            goxy(1,18);
            printf("Please can't a char ,please input number!");
            system("pause");        
            goxy(53,11);
            printf("          ");
            goxy(1,18);
            printf("                                                                        ");     
            goxy(53,11);
            continue;
        }		
        m=atoi(ch);
        if(m>7||m<0)
    	{
            goxy(1,18);
            printf("Please Input a right number from you [0-7]!");
            system("pause");        goxy(53,11);
            printf("          ");goxy(1,18);printf("                                                                        ");						
            goxy(53,11);
    		
    	}
        if(m>=0&&m<=7)
    	{
            switch(m)
        	{				
            case 1:
                addstudentinfo();
                break;				
            case 2:
                Sortdate();
            	break;
            case 3:
                printreport(head,g_count);
            	break;
            case 4:
                savefile();
            	break;
            case 5:
                Loadfile(); 
            	break;
            case 6:
                searchstudents();
            	break;
            case 7:
                statgrade();
            	break;
            case 0:
            	out();
                break;				
    		}
    	}
        continue;
    }	
}

/////////////////////////2.记录排序//////////////////////////
void Sortdate()
{   
    char key[1];
    if(g_count<=0)
    {

⌨️ 快捷键说明

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