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

📄 credit[1].c

📁 题目描述 :每位学生必须完成基础课50学分、专业课50学分、选修课24学分、人文类课程8学分、实验性课程20学分才能够毕业。 功能简介:本程序为用户提供了一个学生学分管理系统
💻 C
📖 第 1 页 / 共 2 页
字号:
    newfirst=NULL;
    newend=NULL;
    printf("Sort by basic class credit is finished...\n");
}
void SortByMajor()
{
    struct LinkNode *q,*newfirst=NULL,*newend=NULL,*pre,*p,*old;
    struct stuinfo temp;
    int major;
    while(first){
        q=NULL;
        current=first->next;
        pre=first;
        major=first->data.major;
        while(current){
            if(major<current->data.major){
                q=pre;
                major=current->data.major;
        	}
            pre=pre->next;
            current=pre->next;
        }
        if(q==NULL){
            temp=first->data;
            old=first;
            first=first->next;
            free(old);
        }
        else{
            temp=q->next->data;
            old=q->next;
            q->next=old->next;
            free(old);
        }
        if(newfirst!=NULL){
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newend->next=p;
            newend=p;
        }
        else{
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newfirst=newend=p;
        }
    }
    first=newfirst;
    end=newend;
    newfirst=NULL;
    newend=NULL;
    printf("Sort by major class credit is finished...\n");
}
void SortByOptional()
{
    struct LinkNode *q,*newfirst=NULL,*newend=NULL,*pre,*p,*old;
    struct stuinfo temp;
    int optional;
    while(first){
        q=NULL;
        current=first->next;
        pre=first;
        optional=first->data.optional;
        while(current){
            if(optional<current->data.optional){
                q=pre;
                optional=current->data.optional;
        	}
            pre=pre->next;
            current=pre->next;
        }
        if(q==NULL){
            temp=first->data;
            old=first;
            first=first->next;
            free(old);
        }
        else{
            temp=q->next->data;
            old=q->next;
            q->next=old->next;
            free(old);
        }
        if(newfirst!=NULL){
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newend->next=p;
            newend=p;
        }
        else{
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newfirst=newend=p;
        }
    }
    first=newfirst;
    end=newend;
    newfirst=NULL;
    newend=NULL;
    printf("Sort by optional class credit is finished...\n");
}
void SortByHum()
{
    struct LinkNode *q,*newfirst=NULL,*newend=NULL,*pre,*p,*old;
    struct stuinfo temp;
    int humanity;
    while(first){
        q=NULL;
        current=first->next;
        pre=first;
        humanity=first->data.humanity;
        while(current){
            if(humanity<current->data.humanity){
                q=pre;
                humanity=current->data.humanity;
        	}
            pre=pre->next;
            current=pre->next;
        }
        if(q==NULL){
            temp=first->data;
            old=first;
            first=first->next;
            free(old);
        }
        else{
            temp=q->next->data;
            old=q->next;
            q->next=old->next;
            free(old);
        }
        if(newfirst!=NULL){
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newend->next=p;
            newend=p;
        }
        else{
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newfirst=newend=p;
        }
    }
    first=newfirst;
    end=newend;
    newfirst=NULL;
    newend=NULL;
    printf("Sort by humanity class credit is finished...\n");
}
void SortByExp()
{
    struct LinkNode *q,*newfirst=NULL,*newend=NULL,*pre,*p,*old;
    struct stuinfo temp;
    int exp;
    while(first){
        q=NULL;
        current=first->next;
        pre=first;
        exp=first->data.exp;
        while(current){
            if(exp<current->data.exp){
                q=pre;
                exp=current->data.exp;
        	}
            pre=pre->next;
            current=pre->next;
        }
        if(q==NULL){
            temp=first->data;
            old=first;
            first=first->next;
            free(old);
        }
        else{
            temp=q->next->data;
            old=q->next;
            q->next=old->next;
            free(old);
        }
        if(newfirst!=NULL){
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newend->next=p;
            newend=p;
        }
        else{
            p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
            p->data=temp;
            p->next=NULL;
            newfirst=newend=p;
        }
    }
    first=newfirst;
    end=newend;
    newfirst=NULL;
    newend=NULL;
    printf("Sort by experiment class credit is finished...\n");
}
void Statistic()
{
    char ch;
    int base,major,optional,hum,exp,all;
    base=major=optional=hum=exp=all=0;
    current=first;
    /*scan the link list and get the statistic information*/
    while(current){
        if(current->data.base>=50)base++;
        if(current->data.major>=50)major++;
        if(current->data.optional>=24)optional++;
        if(current->data.humanity>=8)hum++;
        if(current->data.exp>=20)exp++;
        if(current->data.base>=50&&current->data.major>=50&&current->data.optional>=24&&current->data.humanity>=8&&current->data.exp>=20)all++;
        current=current->next;
    }
    printf("There %d students have finished the basic class.\n",base);
    printf("There %d students have finished the major class.\n",major);
    printf("There %d students have finished the optional class.\n",optional);
    printf("There %d students have finished the humanity class.\n",hum);
    printf("There %d students have finished the experiment class.\n",exp);
    printf("There %d students have finished all the class.\n",all);
    printf("Press any key to continue...");
    ch=getch();
}
int SaveData()
{
    FILE *fp;
    char *path,*pathtxt,ch;
    path=(char *)malloc(sizeof(char)*80);
    pathtxt=(char *)malloc(sizeof(char)*80);
    printf("Please input the filename you want to save:");
    fflush(stdin);
    /*get the save path and file name*/
    gets(path);
    strcpy(pathtxt,path);
    strcat(pathtxt,".txt");
    fp=fopen(path,"wb+");
    if(!fp){
        printf("Can't open the file you entered!");
        return 0;
    }
    current=first;
    while(current){
        fwrite(&current->data,sizeof(struct stuinfo),1,fp);
        current=current->next;
    }
    fclose(fp);
    fp=fopen(pathtxt,"w+");
    if(!fp){
        printf("Can't open file you entered!");
        return 0;
    }
    current=first;
    fprintf(fp," Number     Basic   Major   Optional    Humanity    Experiment\n");
    while(current){
        fprintf(fp,"%s\t %d\t %d\t   %d\t\t  %d\t\t   %d\n",current->data.num,current->data.base,current->data.major,current->data.optional,current->data.humanity,current->data.exp);
        current=current->next;
    }
    fclose(fp);
    printf("The student's information is saved in %s\n",pathtxt);
    printf("Press any key to continue...");
    ch=getch();
    return 1;
}
int LoadData()
{
    FILE *fp;
    char ch,*path;
    struct stuinfo temp;
    struct LinkNode *p;
    int t=0;
    path=(char *)malloc(sizeof(char)*80);
    printf("Please input the filename you want to load:");
    fflush(stdin);
    gets(path);
    fp=fopen(path,"rb");
    if(!fp){
        printf("Can't open the file you entered!");
        return 0;
    }
    while(!feof(fp)){
        fread(&temp,sizeof(struct stuinfo),1,fp);
        if(feof(fp))break;
        if(IsValid(temp)){
            if(first!=NULL){
                p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
                p->data=temp;
                p->next=NULL;
                end->next=p;
                end=p;
        	}
            else{
                p=(struct LinkNode *)malloc(sizeof(struct LinkNode));
                p->data=temp;
                p->next=NULL;
                first=end=current=p;
        	}
        }
        else t++;
    }
    if(t)printf("There is %d number is same in original data, so these data is omited.\n",t);
    printf("Press any key to continue...");
    ch=getch();
    return 1;
}
int IsValid(struct stuinfo t)
{
    int l=strlen(t.num);
    /*if credit is below zero or the number is less than 8, the data is invalid*/
    if(t.base<0||t.major<0||t.optional<0||t.humanity<0||t.exp<0||l!=8)return 0;
    current=first;
    /*if the number is already have the same in link list, the data is invalid*/
    while(current){
        if(strcmp(current->data.num,t.num)==0)return 0;
        current=current->next;
    }
    return 1;
}

int AsValid(struct stuinfo t)
{
    int l=strlen(t.num);
    /*if credit is below zero or the number is less than 8, the data is invalid*/
    if(t.base<0||t.major<0||t.optional<0||t.humanity<0||t.exp<0||l!=8)return 0;
    /*don't mention if student's number exit or not */
    return 1;
}



/*delete the link list, release the space*/
void DestroyLink()
{
    struct LinkNode *p;
    if(first!=NULL){
        p=first;
        first=first->next;
        free(p);
    }
    first=current=end=NULL;
}

⌨️ 快捷键说明

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