资源简介
一个简单的课程表包括添加删除
代码片段和文件信息
#include
#include
#include
#include
#include
#include “head.h“
Course::Course(){ //构造函数
char str[20];
cout<<“请输入课程名称:“;
cin>>str;
name = new char[strlen( str )+1];
strcpy(namestr);
cout<<“请输入上课地点:“;
cin>>str;
classroom = new char [strlen( str )+1];
strcpy ( classroomstr );
cout<<“请输入教师姓名:“;
cin>>str;
teacher = new char [strlen( str )+1];
strcpy ( teacherstr );
cout<<“请输入课程起始周和结束周:“;
cin>>week.first>>week.last;
cout<<“星期几上课(1-7分别代表星期一到星期日):“;
cin>>time.weekday;
cout<<“第几节到第几节上课:“;
cin>>time.start>>time.end;
cout< }
Course::~Course (){
delete [] name;
delete [] classroom;
delete [] teacher;
}
Week Course::GetWeek () const{ //返回开课周数
Week w;
w.first = week.first;
w.last = week.last;
return w;
}
int Course::GetWeekday () const{//返回星期几上课
return time.weekday;
}
int Course::Getstart () const{//返回起始节数
return time.start;
}
int Course::Getend () const{//返回结束节数
return time.end;
}
char* Course::Getname () const{//返回课程名称
return name;
}
ostream &operator<<(ostream &osCourse& cour) //course输出运算符重载
{
os< os< < < < < < < < return os;
}
istream &operator>>(istream &isCourse &cour) //course输入运算符重载
{
char str[20];
is>>str;
cour.name=new char[strlen(str)+1];
if (!cour.name)
{
cout<<“ memory allocation error\n“;
exit(1);
}
strcpy(cour.namestr);
is>>str;
cour.classroom=new char[strlen(str)+1];
if (!cour.classroom)
{
cout<<“ memory allocation error\n“;
exit(1);
}
strcpy(cour.classroomstr);
is>>str;
cour.teacher=new char[strlen(str)+1];
if (!cour.teacher)
{
cout<<“ memory allocation error\n“;
exit(1);
}
strcpy(cour.teacherstr);
is>>cour.week.first;
is>>cour.week.last;
is>>cour.time.weekday;
is>>cour.time.start;
is>>cour.time.end;
return is;
}
void Interface() //用于显示用户界面
{
cout<<“\t\t************************************************“< cout<<“\t\t\t\t 课程表管理“< cout<<“\t\t************************************************“< cout<<“\t\t\t\t1.课程信息输入“< cout<<“\t\t\t\t2.显示当天课程“< cout<<“\t\t\t\t3.显示本周课程“< cout<<“\t\t\t\t4.课程信息修改“< cout<<“\t\t\t\t0.退出“< }
void InforInput (){ //输入课程信息并写入文档
int choose;
cout<<“开始输入?(1,是 0,否)“;
cin>>choose;
while(choose){
Course cour;
ofstream fout(“course.txt“ios::app);
if(!fout){
cout<<“不能打开输入文件!“< exit(1);
}
else{
fout< cout< }
cout< cout<<“继续输入下一门课程?(1,是 0,否)“;
cin>>choose;
}
}
void DisplayToday (){ //显示当天课表(用户输入第几周,星期几)
int currentweek; //当
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 377 2005-04-10 17:10 Schedule\Schedule\main.cpp
目录 0 2005-04-10 17:01 Schedule\Schedule\Debug
文件 1175 2005-04-10 16:43 Schedule\Schedule\head.h
文件 3401 2005-04-10 21:23 Schedule\Schedule\course.dsp
文件 4426 2005-04-04 17:23 Schedule\Schedule\Schedule.dsp
文件 541 2005-04-04 17:23 Schedule\Schedule\Schedule.dsw
文件 74752 2005-04-10 22:09 Schedule\Schedule\Schedule.ncb
文件 408 2005-04-10 17:22 Schedule\Schedule\Course.txt
文件 1312 2005-04-10 21:27 Schedule\Schedule\Schedule.plg
文件 53760 2005-04-10 22:09 Schedule\Schedule\Schedule.opt
文件 0 2005-04-09 21:13 Schedule\Schedule\Course.txe
文件 41984 2005-04-10 21:25 Schedule\Schedule\course.ncb
文件 5535 2005-04-10 22:09 Schedule\Schedule\course.cpp
文件 53760 2005-04-10 21:25 Schedule\Schedule\course.opt
目录 0 2005-04-10 17:01 Schedule\Schedule
目录 0 2005-04-10 15:01 Schedule
----------- --------- ---------- ----- ----
241649 17
评论
共有 条评论