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

📄 system.c

📁 学籍管理 包括1. 学生基本数据输入功能 2. 学生成绩输入功能 3. 学生数据和成绩的更新和删除功能 4. 按姓名/学号查找学生成绩功能 5. 按学号排序输出学生数据、各科成绩和平均成绩
💻 C
📖 第 1 页 / 共 5 页
字号:
#include "stdio.h"
#include "ctype.h"
#include "string.h"
#include "dos.h"

struct course
{
    int courseid;
    char coursename[24];
    int credithour;
    float score;
    int ispassed;
    struct course *nextcourse;
};

struct student
{
    long studentid;
    char studentname[24];
    char sex;
    int age;
    char birthday[11];
    char identity[19];
    char province[21];
    char city[21];
    char address[51];
    char college[41];
    char department[41];
    int numofcourses;
    int passedcourses;
    int totalcredithour;
    int passedcredithour;
    float averagescore;
    struct course *courselist;
    struct student *nextstudent;
};

struct coursestatistic
{
    int courseid;
    char coursename[24];
    int credithour;
    int population;
    int passedcourses;
    float averagescore;
    struct coursestatistic *nextcourse;
};

struct student *addstudent(struct student *newstudent, struct student *listhead, int *issuccessful);
struct course *addcourse(struct course *newcourse, struct course *listhead);
struct student *delstuid(long delid, struct student *listhead, int *issuccessful);
struct student *delstuname(char delname[], struct student *listhead, int *issuccessful);
struct course *delcourse(struct course *currentcourse, struct course *listhead);
struct student *clearstudent(struct student *listhead);
struct course *clearcourse(struct course *listhead);
struct student *creatstudent(struct student *studentlist);
struct student *changestudent(struct student *currentstudent, struct student *listhead);
struct student *chastuid(struct student *currentstudent, long newid, struct student *listhead);
struct course *chacouid(struct student *thisstudent, struct course *currentcourse, int newid, struct student *studentlist);
struct course *creatcourse(struct student *studentlist, struct course *courselist, int *issuccessful);
struct student *import(struct student *listhead, int *counter);
void export(struct student *studentlist, int *counter);
void printstudent(struct student *currentstudent);
void printcourse(struct course *currentcourse);
void printlist(struct student *listhead, int *counter);
void statistic(struct student *studentlist);
struct coursestatistic *addstatistic(struct course *newcourse, struct coursestatistic *listhead);
struct student *findstuid(long findid, struct student *listhead);
struct student *findstuname(char findname[], struct student *listhead);
void findcourse(int findid, struct student *listhead);
void setpassword(char password[]);
void inputpassword(char password[]);
void updatelist(struct student *listhead);

struct student *addstudent(struct student *newstudent, struct student *listhead, int *issuccessful)
{
    struct student *p1,*p2;

    if(newstudent==NULL)
        *issuccessful=0;
    else
    {
        p1=listhead;
        if(listhead==NULL)
        {
            listhead=newstudent;
            newstudent->nextstudent=NULL;
            printf("\n%s %ld %s\n","Add student ID",newstudent->studentid,"successfully.");
            *issuccessful=1;
        }
        else
        {
            while(newstudent->studentid>p1->studentid&&p1->nextstudent!=NULL)
            {
                p2=p1;
                p1=p1->nextstudent;
            }
            if(newstudent->studentid<=p1->studentid)
                if(newstudent->studentid==p1->studentid)
                {
                    printf("\n%s %ld %s\n","Student ID",newstudent->studentid,"has existed. Cann't add a same ID.");
                    free(newstudent);
                    *issuccessful=0;
                }
                else
                {
                    if(listhead==p1)
                    {
                        listhead=newstudent;
                        newstudent->nextstudent=p1;
                    }
                    else
                    {
                        p2->nextstudent=newstudent;
                        newstudent->nextstudent=p1;
                    }
                    printf("\n%s %ld %s\n","Add student ID",newstudent->studentid,"successfully.");
                    *issuccessful=1;
                }
            else
            {
                p1->nextstudent=newstudent;
                newstudent->nextstudent=NULL;
                printf("\n%s %ld %s\n","Add student ID",newstudent->studentid,"successfully.");
                *issuccessful=1;
            }
        }
    }
    return listhead;
}

struct course *addcourse(struct course *newcourse, struct course *listhead)
{
    struct course *p1,*p2;

    if(newcourse!=NULL)
    {
        p1=listhead;
        if(listhead==NULL)
        {
            listhead=newcourse;
            newcourse->nextcourse=NULL;
            printf("\n%s %d %s\n","Add course ID",newcourse->courseid,"successfully.");
        }
        else
        {
            while(newcourse->courseid>p1->courseid&&p1->nextcourse!=NULL)
            {
                p2=p1;
                p1=p1->nextcourse;
            }
            if(newcourse->courseid<=p1->courseid)
            {
                if(listhead==p1)
                {
                    listhead=newcourse;
                    newcourse->nextcourse=p1;
                }
                else
                {
                    p2->nextcourse=newcourse;
                    newcourse->nextcourse=p1;
                }
                printf("\n%s %d %s\n","Add course ID",newcourse->courseid,"successfully.");
            }
            else
            {
                p1->nextcourse=newcourse;
                newcourse->nextcourse=NULL;
                printf("\n%s %d %s\n","Add course ID",newcourse->courseid,"successfully.");
            }
        }
    }
    return listhead;
}

struct student *delstuid(long delid, struct student *listhead, int *issuccessful)
{
    struct student *p1,*p2;

    if(listhead==NULL)
    {
        printf("\n%s %ld %s\n","Student ID",delid,"hasn't been found.");
        *issuccessful=0;
    }
    else
    {
        p1=listhead;
        while(delid>p1->studentid&&p1->nextstudent!=NULL)
        {
            p2=p1;
            p1=p1->nextstudent;
        }
        if(delid==p1->studentid)
        {
            if(p1==listhead)
                listhead=p1->nextstudent;
            else
                p2->nextstudent=p1->nextstudent;
            p1->courselist=clearcourse(p1->courselist);
            free(p1);
            printf("\n%s %ld %s\n","Delete student ID",delid,"successully.");
            *issuccessful=1;
        }
        else
        {
            printf("\n%s %ld %s\n","Student ID",delid,"hasn't been found.");
            *issuccessful=0;
        }
    }
    return listhead;
}

struct student *delstuname(char delname[], struct student *listhead, int *issuccessful)
{
    struct student *p1,*p2;

    if(listhead==NULL)
    {
        printf("\n%s %s %s\n","Student name",delname,"hasn't been found.");
        *issuccessful=0;
    }
    else
    {
        p1=listhead;
        while(strcmp(delname,p1->studentname)!=0&&p1->nextstudent!=NULL)
        {
            p2=p1;
            p1=p1->nextstudent;
        }
        if(strcmp(delname,p1->studentname)==0)
        {
            if(p1==listhead)
                listhead=p1->nextstudent;
            else
                p2->nextstudent=p1->nextstudent;
            p1->courselist=clearcourse(p1->courselist);
            free(p1);
            printf("\n%s %s %s\n","Delete student name",delname,"successully.");
            *issuccessful=1;
        }
        else
        {
            printf("\n%s %s %s\n","Student name",delname,"hasn't been found.");
            *issuccessful=0;
        }
    }
    return listhead;
}

struct course *delcourse(struct course *currentcourse, struct course *listhead)
{
    struct course *p;

    if(currentcourse==listhead)
        listhead=listhead->nextcourse;
    else
    {
        for(p=listhead;p->nextcourse!=currentcourse;p=p->nextcourse);
        p->nextcourse=currentcourse->nextcourse;
    }
    free(currentcourse);
    return listhead;
}

struct student *clearstudent(struct student *listhead)
{
    struct student *currentstudent;

    for(currentstudent=listhead;listhead!=NULL;currentstudent=listhead)
    {
        listhead=listhead->nextstudent;
        currentstudent->courselist=clearcourse(currentstudent->courselist);
        free(currentstudent);
    }
    return listhead;
}

struct course *clearcourse(struct course *listhead)
{
    struct course *currentcourse;

    for(currentcourse=listhead;listhead!=NULL;currentcourse=listhead)
    {
        listhead=listhead->nextcourse;
        free(currentcourse);
    }
    return listhead;
}

struct student *creatstudent(struct student *studentlist)
{
    struct student *newstudent,*currentstudent;
    long id;
    int i,done;
    char ch;
    struct course *p;
    int *issuccessful=&done;
    struct date currentdate;

    printf("\n%s\n%s","Please input the student ID.","Student ID: ");
    fflush(stdin);
    i=0;
    id=0;
    ch=getch();
    while(i==0||ch!='\r')
    {
        if(i<9&&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(currentstudent=studentlist;currentstudent!=NULL;currentstudent=currentstudent->nextstudent)
        if(id==currentstudent->studentid)
        {
            printf("\n%s %ld %s\n","Student ID",id,"has existed. Cann't add a same ID.");
            break;
        }
    if(currentstudent!=NULL)
        return NULL;
    else
    {
        newstudent=(struct student *)malloc(sizeof(struct student));
        newstudent->studentid=id;
        printf("\n%s\n%s","Please input the student name.","Student Name: ");
        fflush(stdin);
        i=0;
        ch=getch();
        while(i==0||ch!='\r')
        {
            if(i<23&&(isalpha(ch)||i!=0&&ch==' '))
            {
                newstudent->studentname[i++]=ch;
                printf("%c",ch);
            }
            if(i>0&&ch=='\b')
            {
                printf("\b \b");
                i--;
            }

⌨️ 快捷键说明

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