| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 861 人关注过本帖
标题:课程选择系统代码,大神看看啊,怎么录不进信息
只看楼主 加入收藏
zcfyxw
Rank: 1
等 级:新手上路
帖 子:68
专家分:7
注 册:2012-12-26
结帖率:60%
收藏
已结贴  问题点数:20 回复次数:16 
课程选择系统代码,大神看看啊,怎么录不进信息
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int N1,N2;
struct student
{
    int num2;
    char name2[20];
    int nelenum[50];              /*所选课程编号*/
    int nelen;                    /*所选课程学分和*/
    struct student * next;
};
struct course
{
    int num1;        /*课程编号*/
    char name1[20];  /*课程名称*/

    char type[20];   /*类型,性质*/
    int credit;      /* 学分   */
    int period;      /*  课时 */
    char teacher[20];
    int people;                   /*选此门课程的人数*/
    struct course *next;            /*结构体指针*/
};
struct course * head1;
struct student * head2;
struct course *zhang()                 /*从键盘录入课程信息*/
{
    char ch;
    struct course *p1,*p2;

    p1=p2=(struct course *)malloc(sizeof(struct course));
    printf("C Numbers\tC name \tC nature\tcredits \tperiod\tteacher\n");
    scanf("%d%s%s%d%d%s",&p1->num1,p1->name1,p1->type,&p1->credit,&p1->period,p1->teacher);
    ch=getchar();
    p1->people=0;
    head1=NULL;
    while(ch!=0x0b)
    {
        if(head1==NULL)
         head1=p1;
        else
         p2->next=p1;
        p2=p1;
        p1=(struct course * )malloc(sizeof(struct course));
        scanf("%d%s%s%d%d%s",&p1->num1,p1->name1,p1->type,&p1->credit,&p1->period,p1->teacher);
        p1->people=0;
        getchar();
        ch=getchar();
    }
}
void zhang1()                      /*从文件录入课程信息*/
{
    FILE * fp;
    char filepath[20];
    struct course *p1,*p2;
    N1=0;
    printf("Please input you want to read the path of the class:");
    getchar();
    gets(filepath);
    if((fp=fopen(filepath,"rt"))==NULL)
    {
        printf("Can't find % s file!\n",filepath);
        exit(0);
    }
    p1=p2=(struct course*)malloc(sizeof(struct course));
    fread(p1,sizeof(struct course),1,fp);
    head1=NULL;
    while(!feof(fp))
    {
        N1=N1+1;
        if(N1==1)
            head1=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct course * )malloc(sizeof(struct course));
        fread(p1,sizeof(struct course),1,fp);
    }
    p2->next=NULL;
}
void load()             /*录入课程信息函数*/
{
    int i;
    printf("\t\t\tEntry course information\n");
    printf("\n1.From the keyboard input");
    printf("\n2.From file entry");
    printf("\n3.To return to main menu\n");
    printf("Please enter1-3:");
    scanf("%d",&i);
    switch(i)
    {
    case 1:head1=zhang();break;
    case 2:zhang1();break;
    case 3:break;
    }
}
void insert(struct course *incourse)             /*增加课程信息*/
{
    struct course *p0,*p1,*p2;
    p1=head1;
    p0=incourse;
    if(head1==NULL)
    {
        head1=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num1>p1->num1) && (p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num1<=p1->num1)
        {
            if(head1==p1)
                head1=p0;
            else
                p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
    }
    N1=N1+1;
}
void delc(int num1)             /*删除课程信息*/
{
    struct course *p1,*p2;
    if(head1==NULL)
    {
        printf("\nCannot delete!\n");
        goto end;
    }
    p1=head1;
    while(num1!=p1->num1 && p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num1==p1->num1)
    {
        if(p1==head1)
            head1=p1->next;
        else
            p2->next=p1->next;
        printf("deleted\n");
        N1=N1-1;
    }
    else
        printf("Without this course\n");
    end:;
}
void *listc()                 /*浏览课程信息*/
{
    struct course * p;
    p=head1;
    printf("C Numbers   C name    C nature    credits  period    teacher   Elective number\n");
    while(p!=NULL)
    {
        printf("%6d%13s%10s%7d%7d%12s%5d\n",p->num1,p->name1,p->type,p->credit,p->period,p->teacher,p->people);
        p=p->next;
    }
}
void search2()               /*按学分查找课程信息*/
{
   int a;
   struct course*p;
   printf("please enter the course credit");
   scanf("%d",&a);
   p=head1;

   printf("C Numbers   C name    C nature    credits   period    teacher   Elective number\n");
    while(p!=NULL)
    {
       if(p->credit==a)
        {
         printf("%6d%13s%10s%7d%7d%12s%5d\n",p->num1,p->name1,p->type,p->credit,p->period,p->teacher,p->people);
        }
        p=p->next;
    }
}
void search3()               /*按性质查找课程信息*/
{
   int type1[20];
   struct course*p;
   printf("please enter the course type:");
   scanf("%s",type1);
   p=head1;

   printf("C Numbers   C name    C nature    credits   period    teacher   Elective number\n");
    while(p!=NULL)
    {
       if(strcmp(type1,p->type)==0)
        {
         printf("%6d%13s%10s%7d%7d%12s%5d\n",p->num1,p->name1,p->type,p->credit,p->period,p->teacher,p->people);
        }
        p=p->next;
    }
}
void search()  /*课程信息查找函数*/
{
     int i;
     printf("1.According to the course credit to find\n");
     printf("2.According to the course type to find\n");
     printf("3.return\n");
     printf("Please enter1-3:\n");
     scanf("%d",&i);
     switch(i)
    {
     case 1:search2();break;
     case 2:search3();break;
     case 3:break;
     }
}
void managementc()             /*课程信息管理函数*/
{
    struct course * p1;
    int i,num1;
    printf("\t\t\tCourse information management\n");
    printf("1.Entry course information\n");
    printf("2.Add course\n");
    printf("3.Delete course\n");
    printf("4.Curriculum information browsing\n");
    printf("5.Find students' information\n");
    printf("6.return\n");
    printf("Please enter1-6:\n");
    scanf("%d",&i);
    switch(i)
    {
    case 1:system("cls");load();break;
    case 2:{p1=(struct course *)malloc(sizeof(struct course));
        printf("C Numbers\tC name\tCourse nature\tcredits\tclass\tteacher\n");
        scanf("%d%s%s%d%d%s",&p1->num1,p1->name1,p1->type,&p1->credit,&p1->period,p1->teacher);
        p1->people=0;
        insert(p1);
           }      break;
    case 3:printf("Please input you want to delete the course Numbers:\n");
        scanf("%d",&num1);
        delc(num1);      break;
    case 4:listc();break;
    case 5:search();break;
    case 6:break;
    }
}
void putin(void)           /*从键盘录入学生信息*/
{
    int i;
    struct student *p1,*p2;
    N2=0;
    p1=p2=(struct student *)malloc(sizeof(struct student));
    printf("Student id\tname\n");
    scanf("%d%s",&p1->num2,p1->name2);
    p1->nelen=0;
    for(i=0;i<20;i++) p1->nelenum[i]=0;
    head2=NULL;
    while(p1->num2!=0)
    {
        N2=N2+1;
        if(N2==1)
            head2=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct student * )malloc(sizeof(struct student));
        scanf("%d%s",&p1->num2,p1->name2);
        p1->nelen=0;
        for(i=0;i<20;i++) p1->nelenum[i]=0;
    }
    p2->next=NULL;}
void putin2()              /*从文件录入学生信息*/
{

    FILE * fp;
    char filepath[20];
    struct student *p1,*p2;
    N2=0;
    printf("Please input you want to read the path:");
    getchar();
    gets(filepath);
    if((fp=fopen(filepath,"rt"))==NULL)
    {
        printf("Can't find % s file!\n",filepath);
        exit(0);
    }
    p1=p2=(struct student*)malloc(sizeof(struct student));
    fread(p1,sizeof(struct student),1,fp);
    head2=NULL;
    while(!feof(fp))
    {

        N2=N2+1;
        if(N2==1)
            head2=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct student * )malloc(sizeof(struct student));
        fread(p1,sizeof(struct student),1,fp);
    }
    p2->next=NULL;
}
void input()               /*录入学生信息函数*/
{
    int i;
    printf("\t\t\tEntering students' information\n");
    printf("\n1.From the keyboard input\n");
    printf("2.From file entry\n");
    printf("3.To return to main menu\n");
    printf("Please enter1-3:\n");
    scanf("%d",&i);
    switch(i)
    {
    case 1:putin();     break;
    case 2:putin2();    break;
    case 3:break;
    }
}
void inserts(struct student * incouse)             /*增加学生信息*/
{
    struct student *p0,*p1,*p2;
    p1=head2;
    p0=incouse;
    if(head2==NULL)
    {
        head2=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num2>p1->num2) && (p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num2 <= p1->num2)
        {
            if(head2==p1) head2=p0;
            else p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;}
    }
    N2=N2+1;
}
void dels(int num2)                   /*删除学生信息*/
{
    struct student *p1,*p2;
    if(head2==NULL)
    {
        printf("\nCannot delete\n");
        goto end;
    }
    p1=head2;
    while(num2!=p1->num2 && p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num2==p1->num2)
    {
        if(p1==head2)
            head2=p1->next;
        else
            p2->next=p1->next;
        printf("deleted\n");
        N2=N2-1;
    }
    else
        printf("Not the student Numbers\n");
end:;
}
 lists()                     /*浏览学生信息*/
{
    struct student * p;
    int a;
    p=head2;
    printf("S Numbers   S name    selected C credits    Selected C Numbers\n");
    while(p!=NULL)
    {
        printf("%6d%13s",p->num2,p->name2);
        printf("%6d",p->nelen);

        for(a=0;p->nelenum[a]!=0&&a<14;a++)
            printf("%6d",p->nelenum[a]);
        printf("\n");
        p=p->next;
    }
}
void managements()          /*学生信息管理函数*/
{
    struct student * p1;
    int i,num2;
    printf("\t\t\tStudent information management\n");
    printf("1.Entering students' information\n");
    printf("2.Add students' information\n");
    printf("3.Delete student information\n");
    printf("4.Students' information browsing\n");
    printf("5.To return to main menu\n");
    printf("Please select1-5:\n");
    scanf("%d",&i);
    switch(i)
    {
    case 1:system("cls");input();break;
    case 2:{p1=(struct student *)malloc(sizeof(struct student));
        p1->nelen=0;
        p1->nelenum[0]=0;
        printf("num\tname\n");
        scanf("%d%s",&p1->num2,p1->name2);
        inserts(p1);}break;
    case 3:{printf("Please input you want to delete student Numbers:\n");
        scanf("%d",&num2);
        dels(num2);
           }    break;
    case 4:lists();break;
    case 5:break;
    }
}
void elect()             /*学生选课*/
{
    struct student * s;
    struct course * p;
    int a,i,b;
    printf("Please enter your student id:\n");
    scanf("%d",&a);
    s=head2;
    while((s->num2)!=a&&s->next!=NULL) s=s->next;
    if(s->num2!=a)
    {
        printf("Your information does not exist, please enter again:\n");
        goto end;
    }
    if((s->nelen)>10)
    {
        printf("Your credit is full already");
        goto end;
    }
    printf("Please input you want to elective course Numbers\n");
    scanf("%d",&b);
    for(i=0;(s->nelenum[i])!=0;i++);
    s->nelenum[i]=b;
    p=head1;
    while((p->num1)!=b)
        p=p->next;
    (p->people)++;
    (s->nelen)=(s->nelen)+(p->credit);
end:;
}
void back()              /*学生退课*/
{
    struct student * p;
    struct course * p1;
    int b,i,j,a;
    printf("Please enter your student id:\n");
    scanf("%d",&a);
    p=head2;
    while(p->num2!=a&&p!=NULL) p=p->next;
    if(p==NULL)
        printf("Your information does not exist:\n");
    else
    {
        printf("Please input you check chosen course:\n");
        scanf("%d",&b);
        p1=head1;
        while(p1->num1!=b) p1=p1->next;
        for(i=0;p->nelenum[i]!=b;i++);
        for(j=i;p->nelenum[j]!=0;j++)
            p->nelenum[j]=p->nelenum[j+1];
        p->nelenum[--j]=0;
        (p->nelen)=(p->nelen)-(p1->credit);
        (p1->people)--;
        printf("succeed!\n");
    }
}
void search1()                      /*按学生编号查找学生信息*/
{
    int a,b;
    struct student * p;
    printf("Please enter the student Numbers");
    scanf("%d",&a);
    p=head2;
    printf("S id       S name    Selected C Numbers  selected C credits\n");
    while(p!=NULL)
    {
        if(p->num2==a)
        {
            printf("%6d%13s ",p->num2,p->name2);
            for(b=0;p->nelenum[b]!=0&&b<14;b++)
                printf("%d",p->nelenum[b]);
            printf("%10d\n",p->nelen);
        }
        p=p->next;
    }
}
void elective()             /*学生选课信息管理*/
{
    int i;
    printf("\t\t\tStudents' course selection information management\n");
    printf("1.elective\n");
    printf("2.Drop a course\n");
    printf("3.According to the student id to find\n");
    printf("4.To return to main menu\n");
    printf("Please enter1-4:\n");
    scanf("%d",&i);
    switch(i)
    {
    case 1:elect();break;
    case 2:back();break;
    case 3:search1();break;
    case 4:break;
    }
}
void *intoc()                       /*存储课程信息*/
{
    FILE * fp;
    struct course * p;
    char filepath[30];
    printf("Input path:");
    getchar();
    gets(filepath);
    if((fp=fopen(filepath,"w"))==NULL)
    {
        printf("\Cannot store!");
        exit(0);
    }
    p=head1;
    while(p!=NULL)
    {
        fprintf(fp,"%d%s%s%d%d%s%d\n",p->num1,p->name1,p->type,p->credit,p->period,p->teacher,p->people);
        p=p->next;
    }
    fclose(fp);
    printf("Already stored into the file % s!\n",filepath);
}
void intos()                            /*存储学生信息*/
{
    FILE * fp;
    struct student * p;
    char filepath[30];
    printf("Please input the path:");
    getchar();
    gets(filepath);
    if((fp=fopen(filepath,"wt"))==NULL)
    {
        printf("\nCannot store!");
        exit(0);
    }
    p=head2;
    while(p!=NULL)
    {
        fwrite(p,sizeof(struct student),1,fp);
        p=p->next;
    }
    fclose(fp);
    printf("Already stored into the file % s!\n",filepath);
}
void into()                      /*信息存储函数*/
{
    int i;
    printf("\t\t\tInformation storage\n");
    printf("1.Course information storage\n");
    printf("2.Student information storage\n");
    printf("3.To return to main menu\n");
    printf("Please enter1-3\n");
    scanf("%d",&i);
    switch(i)
    {
    case(1):intoc();break;
    case(2):intos();break;
    case(3):break;
    }
}
void main()                     /*主函数*/
{
    char m;
    int i;
start:
    printf("\t\t\t***************************\n");
    printf("\n\t\t\tWelcome to use this system!\n");
    printf("\t\t\t***************************\n");
    printf("\n");
    printf("\t\tmenu:\n");
    printf("\t\t\t1.Course information management\n");
    printf("\t\t\t2.Student information management\n");
    printf("\t\t\t3.Students' course selection\n");
    printf("\t\t\t4.Information storage\n");
    printf("\t\t\t5.Exit system");
    printf("\t\t\t\nPlease enter1-4:\n");
    scanf("%d",&i);
      if(i<1 || i>5)
      {
        printf("Please enter a:\n");
      }

    if(scanf("%c",&m))
    {
        printf("Input error, please enter again:\n");

    }
    switch(i)
    {
    case 1:system("cls");managementc();goto start;break;
    case 2:system("cls");managements();goto start;break;
    case 3:system("cls");elective();goto start;break;
    case 4:system("cls");into();goto start;break;
    case 5:system("cls");printf("\n    Thank you for your use\n    Bye-Bye!\n");
    }
  getch();
}      
































搜索更多相关主题的帖子: 课程 系统 teacher include course 
2013-01-08 20:25
a4811
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:107
注 册:2012-12-20
收藏
得分:0 
自己写的还是从哪复制过来的?
咱说实话,一般人看到这排场,就没食欲了。
2013-01-08 20:47
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
老实说,你老师没教过你们怎么写程序就要自己写这种东西的?

授人以渔,不授人以鱼。
2013-01-08 20:55
zcfyxw
Rank: 1
等 级:新手上路
帖 子:68
专家分:7
注 册:2012-12-26
收藏
得分:0 
回复 3楼 TonyDeng
我同学让我帮他看的,我也不知道她哪弄的,我看了一天,真心改不成,还问宝哥了,他也无语了
2013-01-08 21:23
zcfyxw
Rank: 1
等 级:新手上路
帖 子:68
专家分:7
注 册:2012-12-26
收藏
得分:0 
回复 2楼 a4811
同学让改的,估计是网上找的,真心吓尿了,那么多函数
2013-01-08 21:24
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:10 
哎,我测试了好久啊,你说的那段可以输入保存,后面的实在看不下去了,我找goto的标签就找了好久,结果....全乱套了

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-01-08 21:26
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
你在网上抄人的东西干嘛呢,那些代码最多错误的。别的不看,单看这个函数定义struct course *zhang()就知道错误,它有可能成功吗?

授人以渔,不授人以鱼。
2013-01-08 21:36
wangjialong
Rank: 2
等 级:论坛游民
帖 子:77
专家分:95
注 册:2012-11-8
收藏
得分:0 
目测每次申请内存后都没有释放,文件打开时没加双引号,将数据导入链表时以数据块读取时应为sizeof()-4,因结构体中有一个为指针

新手发言,请多指教。
2013-01-08 22:43
wangjialong
Rank: 2
等 级:论坛游民
帖 子:77
专家分:95
注 册:2012-11-8
收藏
得分:0 
下面的实在不想看了,请包涵。

新手发言,请多指教。
2013-01-08 22:44
zcfyxw
Rank: 1
等 级:新手上路
帖 子:68
专家分:7
注 册:2012-12-26
收藏
得分:0 
回复 9楼 wangjialong
能看都够意思,我也是很无语,我说无能为力了,同学说你杀了我吧
2013-01-09 10:01
快速回复:课程选择系统代码,大神看看啊,怎么录不进信息
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050139 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved