| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:排课系统
只看楼主 加入收藏
西单小六
Rank: 1
等 级:新手上路
帖 子:11
专家分:1
注 册:2011-12-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
排课系统
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
#include"string.h"
#define SIZE sizeof(struct student)
struct student{
    int Subject;
    struct student * next;
};
struct subject
{
    int subject;             //科目数,且规定一名教师教授一门课程
    int classroom;           
};
struct student *creatlist(int subject)
{
    struct student * head;
    struct student * p;
    struct student * p1;
    int i;
    head=(struct student *)malloc(SIZE);
    head->next=NULL;
    p1=head;
    for(i=0;i<subject;i++)
    {
        p=(struct student *)malloc(SIZE);
        p->Subject=i;
        p->next=p1->next;
        p1->next=p;
        p1=p1->next;
    }
    p1->next=NULL;
    return head;
}
void save(int a)
{
    char bb,bd;
    FILE *fp;
    if(a<=9)
    {
        bb='0'+a;
        fp=fopen("kebiao.txt","a+");
        fputc(' ',fp);
        fputc(bb,fp);
        fclose(fp);
    }
    else{
        bb='0'+a/10;
        bd='0'+a%10;
        fp=fopen("kebiao.txt","a+");
        fputc(bb,fp);
        fputc(bd,fp);
        fclose(fp);
    }
}

void save1()
{
    char a[150]="\n|                                                            班级";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(a,fp);
    fclose(fp);
}
void save2(char b)
{
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputc(b,fp);
    fclose(fp);
}
void save3()
{
    char c[150]="的课表                                                             |\n";//135
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(c,fp);
    fclose(fp);
}
void save4()
{
    char d[100]="|                         |";//27
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(d,fp);
    fclose(fp);
}
void save5(int a)
{
    char e[10]="|   教师";//27
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(e,fp);
    fclose(fp);
    save(a);
}
void save6(int a)
{
    char f[10]=" 科目";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(f,fp);
    fclose(fp);
    save(a);
}
void save7(int a)
{
    char g[10]=" 教室",gg[4]="  |";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(g,fp);
    fclose(fp);
    save(a);
    fp=fopen("kebiao.txt","a+");
    fputs(gg,fp);
    fclose(fp);
}
void save8()
{
    char h[2]="\n";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(h,fp);
    fclose(fp);
}
void save9()
{
    char i[150]="\n|          星期一         ||          星期二         ||          星期三         ||          星期四         ||          星期五         |\n";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(i,fp);
    fclose(fp);
}
void save10()
{
    char j[150]="---------------------------------------------------------------------------------------------------------------------------------------";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(j,fp);
    fclose(fp);
}
main()
{
    int n,i,j,grade,gr,cm,m=0;
    int mm=0;
    int aa,ab;
    int bb=1;
    struct subject a[3][6][50];
    struct student *p1,*p2,*p,*mhead;
    printf("输入班级个数(1~15之间):\n");   //定义班级个数
    scanf("%d",&grade);
    printf("输入课程数目(最少为%d门课程):(0<n<=15)\n",grade);
    scanf("%d",&n);
    printf("则需要%d名教师\n",n);
   
    printf("输入教室间数(最少为%d间教室):\n",grade);
    scanf("%d",&cm);
    if((n>0)&&(n<=6))                  //将第一个班的课程表排好
    {
        for(j=0;j<2;j++)
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    a[i][j][0].subject=a[i][j+3][0].subject=m;
                }else{
                    a[i][j][0].subject=a[i][j+3][0].subject=-1;        
                }
                m++;
            }
        }
        m=0;
        for(i=0;i<3;i++)          //周三不安排课程
            a[i][2][0].subject=-1;
        for(j=0;j<2;j++)         //排 其他班级的课表
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    mhead=creatlist(n);
                    p1=mhead->next;
                    p2=mhead;
                    while(p2->next!=NULL)
                    {
                        p2=p2->next;
                    }
                    while(p1->Subject!=a[i][j][0].subject)
                    {
                        p=(struct student *)malloc(SIZE);
                        p->Subject=p1->Subject;
                        p1=p1->next;
                        p->next=p2->next;
                        p2->next=p;
                        p2=p2->next;
                        
                    }
                    p1=p1->next;
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=p1->Subject;
                        a[i][j+3][gr].subject=a[i][j][gr].subject;
                        p1=p1->next;
                    }
                }else{
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j+3][gr].subject=a[i][j][gr].subject=-1;
                    }
                }
                m++;
            }
        }
        for(gr=0;gr<grade;gr++)
        {
            save1();
            printf("班级%d的课表为:\n",gr+1);
            save(bb);
            bb=bb+1;
            save3();
            save10();
            save9();
            save10();
            save8();
            for(i=0;i<3;i++)
            {
                for(j=0;j<5;j++)
                {
                    if(j!=2)
                    {
                        if(a[i][j][gr].subject==-1)
                        {
                            printf("          ");
                            save4();
                        }else{
                            printf("t%d s%d c%d  ",a[i][j][gr].subject+1,a[i][j][gr].subject+1,gr+1);
                            aa=a[i][j][gr].subject+1;
                            ab=gr+1;
                            save5(aa);
                            save6(aa);
                            save7(ab);
                        }
                    }else{
                        printf("        ");
                        save4();
                    }
                }
                printf("\n");
                save8();
                save10();
                save8();
            }
            printf("\n");
            save8();
            save10();
        }
    }else if((n<=9)&&(n>=7))
    {
        for(j=0;j<2;j++)
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    a[i][j][0].subject=a[i][j+3][0].subject=m;
                    m++;
                }
            }
        }
        for(i=0;i<3;i++)
        {
            if(m<n)
            {
                a[i][2][0].subject=m;
            }else{
                a[i][2][0].subject=-1;
            }
            m++;
        }
        m=0;
        for(j=0;j<3;j++)         //排 其他班级的课表
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    mhead=creatlist(n);
                    p1=mhead->next;
                    p2=mhead;
                    while(p2->next!=NULL)
                    {
                        p2=p2->next;
                    }
                    while(p1->Subject!=a[i][j][0].subject)
                    {
                        p=(struct student *)malloc(SIZE);
                        p->Subject=p1->Subject;
                        p1=p1->next;
                        p->next=p2->next;
                        p2->next=p;
                        p2=p2->next;
                        
                    }
                    p1=p1->next;
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=p1->Subject;
                        a[i][j+3][gr].subject=a[i][j][gr].subject;
                        p1=p1->next;
                    }
                }else{
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j+3][gr].subject=a[i][j][gr].subject=-1;
                    }
                }
                m++;
            }
        }
        for(gr=0;gr<grade;gr++)
        {
            save1();
            printf("班级%d的课表为:\n",gr+1);
            save(bb);
            bb=bb+1;
            save3();
            save10();
            save9();
            save10();
            save8();
            for(i=0;i<3;i++)
            {
                for(j=0;j<5;j++)   
                {
                    if(a[i][j][gr].subject!=-1)
                    {
                        printf("t%d s%d c%d  ",a[i][j][gr].subject+1,a[i][j][gr].subject+1,gr+1);
                        aa=a[i][j][gr].subject+1;
                        ab=gr+1;
                        save5(aa);
                        save6(aa);
                        save7(ab);
                    }else{
                        printf("          ");
                        save4();
                    }
                }
                printf("\n");
                save8();
                save10();
                save8();
            }
            printf("\n");
            save8();
            save10();
            save8();
        }
    }else if((n<=15)&&(n>=10))
    {
        for(i=0;i<3;i++)
        {
            for(j=0;j<5;j++)
            {
                if(m<n)
                {
                    a[i][j][0].subject=m;
                }else{
                    a[i][j][0].subject=-1;
                }
                m++;
            }
        }
        m=0;
        for(i=0;i<3;i++)
        {
            for(j=0;j<5;j++)
            {
                if(m<n)
                {
                    mhead=creatlist(n);
                    p1=mhead->next;
                    p2=mhead;
                    while(p2->next!=NULL)
                    {
                        p2=p2->next;
                    }
                    while(p1->Subject!=a[i][j][0].subject)
                    {
                        p=(struct student *)malloc(SIZE);
                        p->Subject=p1->Subject;
                        p1=p1->next;
                        p->next=p2->next;
                        p2->next=p;
                        p2=p2->next;
                    }
                    
                    p1=p1->next;
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=p1->Subject;
                        p1=p1->next;
                    }
                }else{
                    for(gr=0;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=-1;
                    }
                }
                m++;
            }
        }
        for(gr=0;gr<grade;gr++)
        {
            save10();
            save1();
            printf("班级%d的课表为:\n",gr+1);
            save(bb);
            bb=bb+1;
            save3();
            save10();
            save9();
            save10();
            save8();
            for(i=0;i<3;i++)
            {
                for(j=0;j<5;j++)
                {
                    if(a[i][j][gr].subject!=-1)
                    {
                        printf("t%2d s%2d c%2d     ",a[i][j][gr].subject+1,a[i][j][gr].subject+1,gr+1);
                        aa=a[i][j][gr].subject+1;
                        ab=gr+1;
                        save5(aa);
                        save6(aa);
                        save7(ab);
                    }else{
                        printf("      ");
                        save4();
                    }
                }
                save8();
                save10();
                save8();
            }
            printf("\n");
            save8();
        }
    }
    return 0;
}

我们的排课系统,限制太多了,请高手给点儿意见啊……

搜索更多相关主题的帖子: 教师 教授 include 课程 
2011-12-29 19:15
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:20 
一下子上这么多代码阿

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2011-12-31 16:39
快速回复:排课系统
数据加载中...
 
   



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

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