资源简介
C++ 排课程序源代码,包含两个排课程序:
Course_Arrangement用C++写的自动排课程序
遗传算法做排课软件源码
其中第二个源码也就是遗传算法做排课软件做的比较详细,源代码较丰富,也是比较早的C++程序,全部看完看懂需要点耐心。
代码片段和文件信息
/*
File Name: Course_Arrangement.cpp
Intro : This program realize the arragement of courses
Author : Wang Ting
Download : http://www.codefans.net
Date : 2009-11-29
Language : C++
Run Platform: Linux/Unix
*/
#include “course.h“
course::course()
{
days=0;
num_class=0;
}
SUB *create_form() //create form (read datas to SUB from file you given)
{
ifstream infile;
string inputFile;
SUB *head*tail*p;
// course cor;
int size=sizeof(SUB);
head=tail=NULL;
cout<<“Enter the file path: “;
cin>>inputFile;
cout< infile.open(inputFile.c_str());
int i=0;
while(i<15){
i++;
p=(SUB *)malloc(size);
infile>>p->number;
infile>>p->name;
infile>>p->students;
infile>>p->status;
// cor.subs[i]=p;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
}
tail->next=NULL;
return head;
}
SUB1 *create_form1() //create form (read datas to SUB from file subject.txt)
{
ifstream infile1;
string inputFile1=“.\\subject.txt“;
SUB1 *head1*tail1*p1;
int size1=sizeof(SUB1);
head1=tail1=NULL;
infile1.open(inputFile1.c_str());
int i=0;
while(i<15){
i++;
p1=(SUB1 *)malloc(size1);
infile1>>p1->number1;
infile1>>p1->name1;
infile1>>p1->students1;
infile1>>p1->status1;
if(head1==NULL)
head1=p1;
else
tail1->next1=p1;
tail1=p1;
}
tail1->next1=NULL;
return head1;
}
SUB *create_form2() //create form (read datas to SUB from data.txt)
{
ifstream infile;
SUB *head*tail*p;
int size=sizeof(SUB);
head=tail=NULL;
string inputFile=“.\\data.txt“;
infile.open(inputFile.c_str());
int i=0;
while(i<15){
i++;
p=(SUB *)malloc(size);
infile>>p->number;
infile>>p->name;
infile>>p->students;
infile>>p->status;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
}
tail->next=NULL;
return head;
}
void initi(SUB *head) // initialization
{
SUB *p;
for(p=head;p;p->next)
{
p->status=-1;
}
}
bool canchoose(int num_class) // function decides if the class can be chosenreturn bool
{
SUB *head;
SUB *p;
head=create_form();
bool choose=false;
for (p=head;p;p->next)
{
if(p->status!=num_class)
{
choose=true;
}
else
{
choose=false;
}
break;
}
return choose;
}
void choosecourse(int numint num_class) // function: choose course according to number of course and time
{
SUB *p;
SUB *head;
head=create_form();
for(p=head;p;p->next)
{
if(canchoose(num_class) && p->number==num)
{
p->status=num_class;
break;
}
}
}
void printout(SUB1 *head1) // function :output the arrangement information
{
///////////////////output on the file arrange.txt/////////////////////////////////
SUB1 *p1;
FILE *fpp;
if((fpp=fopen(“.\\ar
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
----------- --------- ---------- ----- ----
10012604 717
评论
共有 条评论