資源簡介
一個簡單的課程表包括添加刪除

代碼片段和文件信息
#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
評論
共有 條評論