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

📄 system.c

📁 学籍管理 包括1. 学生基本数据输入功能 2. 学生成绩输入功能 3. 学生数据和成绩的更新和删除功能 4. 按姓名/学号查找学生成绩功能 5. 按学号排序输出学生数据、各科成绩和平均成绩
💻 C
📖 第 1 页 / 共 5 页
字号:
                    }
                    if(i>0&&ch=='\b')
                    {
                        currentcourse->credithour/=10;
                        printf("\b \b");
                        i--;
                    }
                    ch=getch();
                }
                printf("\n");
                thisstudent->averagescore+=currentcourse->score*currentcourse->credithour;
                thisstudent->totalcredithour+=currentcourse->credithour;
                thisstudent->averagescore/=thisstudent->totalcredithour;
                if(currentcourse->ispassed)
                    thisstudent->passedcourses+=currentcourse->credithour;
            }
            else
            {
                strcpy(currentcourse->coursename,tempcourse->coursename);
                currentcourse->credithour=tempcourse->credithour;
                printf("\n%s%s\n\n%s%d\n","Course Name: ",currentcourse->coursename,"Credit Hour: ",currentcourse->credithour);
            }
        }
    }
    return thisstudent->courselist;
}

struct course *creatcourse(struct student *studentlist, struct course *courselist, int *issuccessful)
{
    struct student *currentstudent;
    struct course *newcourse,*currentcourse;
    int i,j,id,isfound=0,tempint1,tempint2;
    char ch;

    printf("\n%s\n%s","Please input the course ID.","Course ID: ");
    fflush(stdin);
    i=0;
    id=0;
    ch=getch();
    while(i==0||ch!='\r')
    {
        if(i<4&&isdigit(ch))
        {
            id=id*10+(int)ch-48;
            printf("%c",ch);
            i++;
        }
        if(i>0&&ch=='\b')
        {
            id/=10;
            printf("\b \b");
            i--;
        }
        ch=getch();
    }
    printf("\n");
    for(currentcourse=courselist;currentcourse!=NULL;currentcourse=currentcourse->nextcourse)
        if(id==currentcourse->courseid)
        {
            printf("\n%s %d %s\n","Course ID",id,"has existed. Cann't add a same ID.");
            *issuccessful=0;
            break;
        }
    if(currentcourse!=NULL)
        return NULL;
    else
    {
        newcourse=(struct course *)malloc(sizeof(struct course));
        newcourse->courseid=id;
        for(currentstudent=studentlist;currentstudent!=NULL;currentstudent=currentstudent->nextstudent)
        {
            for(currentcourse=currentstudent->courselist;currentcourse!=NULL;currentcourse=currentcourse->nextcourse)
                if(newcourse->courseid==currentcourse->courseid)
                {
                    isfound=1;
                    break;
                }
            if(isfound)
                break;
        }
        if(!isfound)
        {
            printf("\n%s\n%s\n%s","This is a new course.","Please input the course name.","Course Name: ");
            fflush(stdin);
            i=0;
            ch=getch();
            while(i==0||ch!='\r')
            {
                if(i<23&&(isalpha(ch)||i!=0&&(isdigit(ch)||ch=='\''||ch=='.'||ch=='-'||ch==' ')))
                {
                    newcourse->coursename[i++]=ch;
                    printf("%c",ch);
                }
                if(i>0&&ch=='\b')
                {
                    printf("\b \b");
                    i--;
                }
                ch=getch();
            }
            newcourse->coursename[i]='\0';
            printf("\n");
            printf("\n%s\n%s","Please input the credit hour of the course.(1~12)","Credit Hour: ");
            fflush(stdin);
            i=0;
            newcourse->credithour=0;
            ch=getch();
            while(newcourse->credithour==0||ch!='\r')
            {
                if(i<2&&isdigit(ch)&&!(i==0&&ch=='0')&&!(i==1&&(newcourse->credithour!=1||newcourse->credithour==1&&ch!='0'&&ch!='1'&&ch!='2')))
                {
                    newcourse->credithour=newcourse->credithour*10+(int)ch-48;
                    printf("%c",ch);
                    i++;
                }
                if(i>0&&ch=='\b')
                {
                    newcourse->credithour/=10;
                    printf("\b \b");
                    i--;
                }
                ch=getch();
            }
            printf("\n");
        }
        else
        {
            strcpy(newcourse->coursename,currentcourse->coursename);
            newcourse->credithour=currentcourse->credithour;
            printf("\n%s%s\n\n%s%d\n","Course Name: ",newcourse->coursename,"Credit Hour: ",newcourse->credithour);
        }
        printf("\n%s\n%s","Please input the score of the course which the student gets.","Score: ");
        fflush(stdin);
        i=j=0;
        tempint1=tempint2=0;
        ch=getch();
        while(i==0||ch!='\r')
        {
            if(tempint1==10&&ch=='0')
            {
                tempint1*=10;
                printf("%c",ch);
                i++;
            }
            if(i<2&&isdigit(ch))
            {
                tempint1=tempint1*10+(int)ch-48;
                printf("%c",ch);
                i++;
            }
            if(i>0&&ch=='\b')
            {
                tempint1/=10;
                printf("\b \b");
                i--;
            }
            if(tempint1!=100&&ch=='.')
            {
                printf("%c",ch);
                ch=getch();
                while(ch!='\r'&&(j==1||ch!='\b'))
                {
                    if(j<1&&isdigit(ch))
                    {
                        tempint2=(int)ch-48;
                        printf("%c",ch);
                        j++;
                    }
                    if(ch=='\b')
                    {
                        tempint2=0;
                        printf("\b \b");
                        j=0;
                    }
                    ch=getch();
                }
                if(j==0&&ch=='\b')
                {
                    printf("\b \b");
                    ch=getch();
                }
            }
            else
                ch=getch();
        }
        newcourse->score=tempint1+tempint2/10.0;
        printf("\n");
        if(newcourse->score>=60.0)
            newcourse->ispassed=1;
        else
            newcourse->ispassed=0;
        newcourse->nextcourse=NULL;
        *issuccessful=1;
        return newcourse;
    }
}

struct student *import(struct student *listhead, int *counter)
{
    FILE *fp;
    struct student *newstudent;
    char ch,filename[81],tempsex[7],temppassword[17],password[17];
    int i,j,k,tempint1,tempint2,tempi,choose,done,tempcounter;
    struct course *newcourse,*listend;
    int *issuccessful=&done;
    float tempfloat;
    long templong;

    printf("\n%s\n%s","Please input the file name to import.","File Name: ");
    fflush(stdin);
    i=0;
    ch=getch();
    while(i==0||ch!='\r')
    {
        if(isprint(ch))
        {
            filename[i]=ch;
            printf("%c",ch);
            i++;
        }
        if(i>0&&ch=='\b')
        {
            printf("\b \b");
            i--;
        }
        ch=getch();
    }
    filename[i]='\0';
    printf("\n");
    while((fp=fopen(filename,"r"))==NULL)
    {
        printf("\n%s\n%s\n%s\n%s","Can't open the file, please choose the operation.","1-Retry","2-Cancel","Choice: ");
        fflush(stdin);
        i=0;
        choose=0;
        ch=getch();
        while(i==0||ch!='\r')
        {
            if(i<1&&(ch=='1'||ch=='2'))
            {
                choose=(int)ch-48;
                printf("%c",ch);
                i++;
            }
            if(i>0&&ch=='\b')
            {
                printf("\b \b");
                i--;
            }
            ch=getch();
        }
        printf("\n");
        switch(choose)
        {
            case 1: printf("\n%s\n%s","Please input the file name to import.","File Name: ");
                    fflush(stdin);
                    i=0;
                    ch=getch();
                    while(i==0||ch!='\r')
                    {
                        if(isprint(ch))
                        {
                            filename[i]=ch;
                            printf("%c",ch);
                            i++;
                        }
                        if(i>0&&ch=='\b')
                        {
                            printf("\b \b");
                            i--;
                        }
                        ch=getch();
                    }
                    filename[i]='\0';
                    printf("\n");
                    break;
            case 2: return listhead;
        }
    }
    fscanf(fp,"%c",&ch);
    if(ch=='e')
    {
        printf("\nThis is an encrypted file.");
        do
        {
            inputpassword(temppassword);
            fscanf(fp,"%d%c",&j,&ch);
            j+=50;
            k=(int)ch-97;
            for(i=0;i<k;i++)
            {
                fscanf(fp,"%c",&ch);
                if((i+j)%2==0)
                {
                    tempint1=(int)(ch)-i-47;
                    password[i]=(char)(tempint1<32?tempint1+95:tempint1);
                }
                else
                {
                    tempint1=i+158-(int)ch;
                    password[i]=(char)(tempint1>126?tempint1-95:tempint1);
                }
            }
            password[i]='\0';
            if(strcmp(temppassword,password)!=0)
            {
                printf("\nInvalid Password! Fail to import from the file.\n\nPlease choose the operation.\n1-Retry\n2-Cancel\nChoice: ");
                fflush(stdin);
                i=0;
                choose=0;
                ch=getch();
                while(i==0||ch!='\r')
                {
                    if(i<1&&(ch=='1'||ch=='2'))
                    {
                        choose=(int)ch-48;
                        printf("%c",ch);
                        i++;
                    }
                    if(i>0&&ch=='\b')
                    {
                        printf("\b \b");
                        i--;
                    }
                    ch=getch();
                }
                printf("\n");
                switch(choose)
                {
                    case 1: rewind(fp);
                            fscanf(fp,"%c",&ch);
                            break;
                    case 2: fclose(fp);
                            return listhead;
                }
            }
        }
        while(strcmp(temppassword,password)!=0);
        fscanf(fp,"%d#%c",&tempint1,&ch);
        tempcounter=tempint1*95+(int)ch-32-j;
        if(tempcounter==0)
        {
            fclose(fp);
            printf("\n%s %s.\n","No students data is in the file",filename);
        }
        else
        {
            for(k=1;k<=tempcounter;k++,j%=100)
            {
                newstudent=(struct student *)malloc(sizeof(struct student));

⌨️ 快捷键说明

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