版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、#include<iostream>#include<fstream>using namespace std;#define SUCCESS 0#define ERROR_COMMAND 1#define ERROR_ARGV 2#define ERROR_REGISTER 3#define ERROR_CLEAR 4#define
2、0;ERROR_DELETE 5#define ERROR_ADD 6#define ERROR_QUERY 7#define SUCCESS_MSG 8#define ERROR_CANCEL 9#define SUCCESS_CANCEL 10#define S
3、UCCESS_CHANGE 11#define ERROR_CHANGE 12#define MAXLEN 256class Controllerprivate: AgendaManager manager; int nextMeetingID; string returnMsg;public: Controller(void); Controller(void); /將輸入的命令進(jìn)行解析
4、160;int DispatchMessage( char* msg ); /將字符串按第一個spliter 將字符串分成兩段,假如第二段頭存在spliter將存在的spliter 都刪除 int Split( char str, char spliter, char* firstPart, char* secondPart ); Date StrToDate( char* str ); void ToLower( char* str ); string GetReturnMsg();class Controllerp
5、rivate: AgendaManager manager; int nextMeetingID; string returnMsg;public: Controller(void); Controller(void); /將輸入的命令進(jìn)行解析 int DispatchMessage( char* msg ); /將字符串按第一個spliter 將字符串分成兩段,假如第二段頭存在spliter將存在的spliter 都刪除 int Split
6、( char str, char spliter, char* firstPart, char* secondPart ); Date StrToDate( char* str ); void ToLower( char* str ); string GetReturnMsg(); class UserListprivate: vector<User> userList;public: UserList(void); UserList(void); bool AddUser( char* userNam
7、e, char* password ); bool CheckIn( char* userName, char* password ); bool HasUser( char* userName ); User& GetUserByName( char* userName ); /vector<User>:size_type get_userList_size(); void Write(); bool Cancel(char* username, char* password); void Change
8、_Password(char* userName, char* newpassword);class Userprivate: char nameMAXLEN; char passwordMAXLEN; MeetingList meetingList;public: User(void); User( char* name, char* password); User(void); bool IsValid(); bool IsPasswordRight( char* password ); bool I
9、sUserNameRight( char* userName ); bool IsTimeFree( Date startTime, Date endTime ); bool AddMeeting( int meetingID, char* sponser, char* invitee, Date startTime, Date endTime, char* title ); bool GetMeetingInvitee( char* invitee , int meetingID ); bool GetMeetingInviteeByTitle( ch
10、ar* invitee , char* title ); bool CreaterOfMeeting( char* title ); /bool DeleteMeeting( int meetingID ); bool DeleteMeetingByTitle( char* title ); /int GetFirstMeetingID(); bool GetFirstMeetingTitle( char* title ); bool RemoveAllMeetings(); vector<Meeting&
11、gt; Query( Date startTime, Date endTime); char* get_name(); char* get_password(); void Write(); vector<Meeting> QueryAll(); void Change_Password( char* newpassword); class MeetingListprivate: vector<Meeting> meetingList;public: MeetingList(vo
12、id); MeetingList(void); bool AddMeeting( int meetingID, char* sponser, char* invitee, Date startTime, Date endTime, char* title ); bool GetMeetingInvitee( char* invitee, int meetingID ); bool GetMeetingInviteeByTitle( char* invitee , char* title ); bool CreaterOfMeeting( cha
13、r* title, char* sponser ); /bool DeleteMeeting( int meetingID ); bool DeleteMeetingByTitle( char* title ); /int GetFirstMeetingID( char* sponser ); bool GetFirstMeetingTitle( char* sponser, char* title ); bool RemoveAllMeetings(); bool IsTimeFree( Date startTime,
14、Date endTime ); vector<Meeting> Query( Date start, Date end ); void Write(ofstream&); vector<Meeting> QueryAll(); class Meetingprivate: int meetingID; char titleMAXLEN; Date startTime; Date endTime; ch
15、ar sponserMAXLEN; /創(chuàng)建人 char inviteeMAXLEN; /被邀請人 public: Meeting(void); Meeting( int meetingID, char* sponser, char* invitee, Date startTime, Date endTime, char* title ); int GetMeetingID(); Date GetStartTime(); Date GetEndTime(); char* Get
16、Invitee(); char* GetSponser(); char* GetTitle(); Meeting(void);class Dateprivate: int year; int month; int day; int hour;public: Date(void); Date( int year, int month, int day, int hour ); unsigned long GetTimeNum(); int Compare( Date anotherDat
17、e ); bool IsValidDate(); int GetYear(); int GetMonth(); int GetDay(); int GetHour(); Date(void); int main() Controller controller; int returnValue; char cmd2048; cout<<"-歡迎使用議程管理系統(tǒng)-"<<endl<<endl; while( true )
18、60; /獲取用戶輸入的命令 cout<<'$' cin.getline(cmd, 2047 ); /命令交由Controller處理 returnValue = controller.DispatchMessage(cmd); /根據(jù)返回值作出相應(yīng)的提示 switch( returnValue ) case SUCCESS: cout
19、<<"操作成功完成!"<<endl<<endl; break; case ERROR_COMMAND: cout<<"無法識別的命令!"<<endl<<endl; break; case ERROR_ARGV: cout<<"參數(shù)數(shù)量不正確!"<<endl<
20、<endl; break; case ERROR_REGISTER: cout<<"注冊失敗,用戶名已存在!"<<endl<<endl; break; case ERROR_CLEAR: cout<<"清空用戶會議列表失敗!"<<endl<<endl; break;&
21、#160; case ERROR_DELETE: cout<<"刪除會議失敗,可能會議不存在或該用戶不是會議創(chuàng)建者!"<<endl<<endl; break; case ERROR_ADD: cout<<"添加會議失敗,請檢查參數(shù)正確性!"<<endl<<endl; break; case ERR
22、OR_QUERY: cout<<"查詢會議失敗,請檢查參數(shù)正確性!"<<endl<<endl; break; case SUCCESS_MSG: cout<<"IDt創(chuàng)建人tt被邀請人t開始時間t結(jié)束時間t標(biāo)題"<<endl; cout<<controller.GetReturnMsg().c_str()<<endl
23、<<endl; break; case ERROR_CANCEL: cout<<"注銷用戶失敗!"<<endl<<endl; break; case SUCCESS_CANCEL: cout << "注銷用戶成功!" << endl<<endl; break;&
24、#160; case SUCCESS_CHANGE: cout << "修改密碼成功!" << endl<<endl; break; case ERROR_CHANGE: cout<<"修改密碼失敗!"<<endl<<endl; break; default: b
25、reak; return 0; /類的定義/控制器:對UI輸入的命令進(jìn)行解析,并相應(yīng)的作出反應(yīng)Controller:Controller(void) nextMeetingID = 0; returnMsg = "" ifstream infile; infile.open("userList.txt"); char nameMAXLEN,passwordMAXLEN,name1MAXLEN; char sponse
26、rMAXLEN,inviteeMAXLEN,starttimeMAXLEN,endtimeMAXLEN,titleMAXLEN; int id; while(infile>>name>>password) manager.Register(name,password); infile.clear(); infile.close (); infile.open("userList.txt"); while(infile>>name&g
27、t;>password) strcpy(name1,name); strcat(name,".txt"); ifstream infile1; infile1.open(name); while(infile1>>id>>sponser>>invitee>>starttime>>endtime>>title)
28、; if(strcmp(sponser,name1)=0) manager.AddMeeting(id,sponser,password,invitee,StrToDate(starttime),StrToDate(endtime),title); nextMeetingID+; infile1.clear(); infile1.close(); infile.clear(); infile.close()
29、; Controller:Controller(void)/將輸入的命令進(jìn)行解析int Controller:DispatchMessage( char* msg ) char cmd256; char argvs1024; char argv1256; char argv2256; char argv3256; char argv4256; char argv5256; char argv6256; memset( cmd, 0, 256 ); memset( argvs, 0, 1
30、024 ); memset( argv1, 0, 256 ); memset( argv2, 0, 256 ); memset( argv3, 0, 256 ); memset( argv4, 0, 256 ); memset( argv5, 0, 256 ); memset( argv6, 0, 256 ); Split( msg, ' ', cmd, argvs ); ToLower( cmd ); if( strcmp( cmd, "register" ) = 0
31、 ) if( Split( argvs, ' ', argv1, argv2 ) != 1 ) return ERROR_ARGV; if( manager.Register( argv1, argv2 ) ) return SUCCESS; else return ERROR_REGISTER; /對命令add進(jìn)行解析,由于add 有5個參數(shù),所以要考慮缺少參數(shù)的情況 if( s
32、trcmp( cmd, "add" ) = 0 ) if( Split( argvs, ' ', argv1, argvs ) != 1 ) return ERROR_ARGV; if( Split( argvs, ' ', argv2, argvs ) != 1 ) return ERROR_ARGV; if( Split( argvs, ' ', argv3, argvs ) !
33、= 1 ) return ERROR_ARGV; if( Split( argvs, ' ', argv4, argvs ) != 1 ) return ERROR_ARGV; if( Split( argvs, ' ', argv5, argv6 ) != 1 ) return ERROR_ARGV; if( manager.AddMeeting( nextMeetingID, argv1, a
34、rgv2, argv3, StrToDate(argv4), StrToDate(argv5), argv6 ) ) nextMeetingID+; return SUCCESS; else return ERROR_ADD; if( strcmp( cmd, "query" ) = 0 ) int i = 0;&
35、#160; char tempStr2048; char startTime256; char endTime256; Meeting meeting; vector<Meeting> meetingList; if( Split( argvs, ' ', argv1, argvs ) != 1 ) return ERROR_ARGV; if( Split( argvs, ' '
36、;, argv2, argvs ) != 1 ) return ERROR_ARGV; if( Split( argvs, ' ', argv3, argv4 ) != 1 ) return ERROR_ARGV; bool result = manager.Query( argv1, argv2, StrToDate( argv3 ), StrToDate( argv4 ), meetingList ); &
37、#160;if( !result ) return ERROR_QUERY; returnMsg = "" int size = meetingList.size(); if( size = 0 ) returnMsg = "會議列表為空!" return SUCCESS_MSG; for( i = 0; i <
38、size; i+ ) meeting = meetingListi; sprintf(startTime, "%d/%d/%d/%d", meeting.GetStartTime().GetYear(), meeting.GetStartTime().GetMonth(), meeting.GetStartTime().GetDay(), meeting.GetStartTime().GetHour() ); sprintf(endTime, &qu
39、ot;%d/%d/%d/%d", meeting.GetEndTime().GetYear(), meeting.GetEndTime().GetMonth(), meeting.GetEndTime().GetDay(), meeting.GetEndTime().GetHour() ); sprintf( tempStr, "%dt%stt%stt%st%st%sn", meeting.GetMeetingID(), meeting.GetSponser(), meeting.GetInvitee(), startTime,
40、endTime, meeting.GetTitle() ); returnMsg.append( tempStr ); return SUCCESS_MSG; if( strcmp( cmd, "delete" ) = 0 ) if( Split( argvs, ' ', argv1, argvs ) != 1 ) return ERROR_ARGV;
41、160;if( Split( argvs, ' ', argv2, argv3 ) != 1 ) return ERROR_ARGV; /* int meetingID = atoi( argv3 ); if( manager.DeleteMeeting( argv1, argv2, meetingID ) ) */ if( manager.DeleteMeetingByTitle( argv1, argv2, argv3 ) )
42、60; return SUCCESS; else return ERROR_DELETE; /清除某個用戶所有的會議 if( strcmp( cmd, "clear" ) = 0 ) if( Split( argvs, ' ', argv1, argv2 ) != 1 ) return ERROR_ARGV; if( manager.RemoveMeetingList( a
43、rgv1, argv2 ) ) return SUCCESS; else return ERROR_CLEAR; /批處理存儲在文本文件fileName中的register、add、query、delete、clear等命令 if(strcmp(cmd, "batch")=0) ifstream infile; char sMAXLEN; infile.open(argvs);
44、 while(infile.getline(s, 2047 ) Split( s, ' ', cmd, argvs ); ToLower( cmd ); /用戶注冊 if(strcmp(cmd,"register")=0) if( Spli
45、t( argvs, ' ', argv1, argv2 ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; else if( manager.Register( argv1, argv2 ) ) cout << "register操作成功" << endl; &
46、#160;else cout<<"注冊失敗,用戶名已存在!"<<endl<<endl; /對命令add進(jìn)行解析,由于add 有5個參數(shù),所以要考慮缺少參數(shù)的情況 if(strcmp(cmd,"add")=0) if( Split( argvs, ' ', argv
47、1, argvs ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; else if( Split( argvs, ' ', argv2, argvs ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl;
48、60; else if( Split( argvs, ' ', argv3, argvs ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; else if( Split( argvs, ' ', argv4, argvs ) != 1 ) cout<&l
49、t;"參數(shù)數(shù)量不正確!"<<endl<<endl; else if( Split( argvs, ' ', argv5, argv6 ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; else if( manager.AddMeeting( nextMe
50、etingID, argv1, argv2, argv3, StrToDate(argv4), StrToDate(argv5), argv6 ) ) nextMeetingID+; cout << "add操作成功"<<endl<<endl; else
51、0; cout<<"添加會議失敗,請檢查參數(shù)正確性!"<<endl<<endl; /某一時間段會議記錄查詢 if(strcmp(cmd,"query")=0) int i = 0;
52、160; char tempStr2048; char startTime256; char endTime256; Meeting meeting; vector<Meeting> meetingList; if( Split( argvs, ' ', argv1, argvs ) != 1 )
53、; cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; if( Split( argvs, ' ', argv2, argvs ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; if( Split( argvs, ' ', argv3,
54、 argv4 ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; bool result = manager.Query( argv1, argv2, StrToDate( argv3 ), StrToDate( argv4 ), meetingList ); if( !result )
55、0; cout<<"查詢會議失敗,請檢查參數(shù)正確性!"<<endl<<endl; returnMsg = "" int size = meetingList.size(); if( size = 0 ) returnMsg = "會議列表為空!&q
56、uot; cout<<"IDt創(chuàng)建人tt被邀請人t開始時間t結(jié)束時間t標(biāo)題"<<endl; cout<<GetReturnMsg().c_str()<<endl<<endl; for( i = 0; i < size; i+ )
57、160; meeting = meetingListi; sprintf(startTime, "%d/%d/%d/%d", meeting.GetStartTime().GetYear(), meeting.GetStartTime().GetMonth(), meeting.GetStartTime().GetDay(), meeting.GetStartTime().GetHour() ); sprintf(endTime, &qu
58、ot;%d/%d/%d/%d", meeting.GetEndTime().GetYear(), meeting.GetEndTime().GetMonth(), meeting.GetEndTime().GetDay(), meeting.GetEndTime().GetHour() ); sprintf( tempStr, "%dt%stt%stt%st%st%sn", meeting.GetMeetingID(), meeting.GetSponser(), meeting.GetInvitee(),
59、 startTime, endTime, meeting.GetTitle() ); returnMsg.append( tempStr ); cout<<"IDt創(chuàng)建人tt被邀請人t開始時間t結(jié)束時間t標(biāo)題"<<endl; cout<<GetReturnMsg().c_str()<<endl<<
60、endl; /刪除回憶記錄 if(strcmp(cmd,"delete")=0) if( Split( argvs, ' ', argv1, argvs ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl;
61、; if( Split( argvs, ' ', argv2, argv3 ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; /* int meetingID = atoi( argv3 ); if( manager.DeleteMeeting( argv1, argv2, meetingID
62、 ) ) */ if( manager.DeleteMeetingByTitle( argv1, argv2, argv3 ) ) cout<<"delete操作成功完成!"<<endl<<endl; else cout<<"刪除會議失敗,可能會議不存在或該用戶不是會
63、議創(chuàng)建者!"<<endl<<endl; /清除某個用戶所有的會議 if(strcmp(cmd,"clear")=0) if( Split( argvs, ' ', argv1, argv2 ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<
64、;endl<<endl; if( manager.RemoveMeetingList( argv1, argv2 ) ) cout<<"clear操作成功完成!"<<endl<<endl; else cout<<"清空用戶會議列表失敗!"<<endl<<endl;
65、160; if(strcmp( cmd,"cancelregister")=0) if( Split( argvs, ' ', argv1, argv2 ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl;
66、160; if( manager.CheckIn( argv1, argv2 ) ) manager.RemoveMeetingList( argv1, argv2 ); manager.Cancel(argv1, argv2); cout << "注銷用戶成功!" << endl<<e
67、ndl; else cout<<"注銷用戶失敗!"<<endl<<endl; if( strcmp( cmd, "queryall" ) = 0 ) int i = 0; char tempStr2
68、048; char startTime256; char endTime256; Meeting meeting; vector<Meeting> meetingList; if( Split( argvs, ' ', argv1, argv2 ) != 1 ) cout<&l
69、t;"參數(shù)數(shù)量不正確!"<<endl<<endl; bool result = manager.QueryAll( argv1, argv2, meetingList ); if( !result ) cout<<"查詢會議失敗,請檢查參數(shù)正確性!"<<endl<<endl; &
70、#160; returnMsg = "" int size = meetingList.size(); if( size = 0 ) returnMsg = "會議列表為空!" for( i = 0; i < size; i+ )
71、; meeting = meetingListi; sprintf(startTime, "%d/%d/%d/%d", meeting.GetStartTime().GetYear(), meeting.GetStartTime().GetMonth(), meeting.GetStartTime().GetDay(), meeting.GetStartTime().GetHour() );
72、; sprintf(endTime, "%d/%d/%d/%d", meeting.GetEndTime().GetYear(), meeting.GetEndTime().GetMonth(), meeting.GetEndTime().GetDay(), meeting.GetEndTime().GetHour() ); sprintf( tempStr, "%dt%stt%stt%st%st%sn", meeting.GetMeetingID(), meeting.GetSpons
73、er(), meeting.GetInvitee(), startTime, endTime, meeting.GetTitle() ); returnMsg.append( tempStr ); if(strcmp(cmd,"changepassword")=0)
74、60; if( Split( argvs, ' ', argv1, argvs ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<endl<<endl; if( Split( argvs, ' ', argv2, argv3 ) != 1 ) cout<<"參數(shù)數(shù)量不正確!"<<
75、endl<<endl; if( manager.CheckIn( argv1, argv2 ) ) manager.Change_Password(argv1,argv2,argv3); cout << "修改密碼成功!" << endl<<endl;
76、; else cout<<"修改密碼失敗!"<<endl<<endl; infile.close(); return SUCCESS; if(strcmp( cmd,"cancelregister")=0) &
77、#160; if( Split( argvs, ' ', argv1, argv2 ) != 1 ) return ERROR_ARGV; if( manager.CheckIn( argv1, argv2 ) ) manager.RemoveMeetingList( argv1, argv2 ); manager.Cancel(argv1, argv2); return SUCCESS_
78、CANCEL; else return ERROR_CANCEL; if( strcmp( cmd, "queryall" ) = 0 ) int i = 0; char tempStr2048; char startTime256; char endTime256; Meeting meeting; vector<Meeti
79、ng> meetingList; if( Split( argvs, ' ', argv1, argv2 ) != 1 ) return ERROR_ARGV; bool result = manager.QueryAll( argv1, argv2, meetingList ); if( !result ) return ERROR_QUERY;
80、;returnMsg = "" int size = meetingList.size(); if( size = 0 ) returnMsg = "會議列表為空!" return SUCCESS_MSG; for( i = 0; i < size; i+ ) meeting = meetingListi;
81、60; sprintf(startTime, "%d/%d/%d/%d", meeting.GetStartTime().GetYear(), meeting.GetStartTime().GetMonth(), meeting.GetStartTime().GetDay(), meeting.GetStartTime().GetHour() ); sprintf(endTime, "%d/%d/%d/%d", meeting.GetEndTime().GetYear(), meeting.GetE
82、ndTime().GetMonth(), meeting.GetEndTime().GetDay(), meeting.GetEndTime().GetHour() ); sprintf( tempStr, "%dt%stt%stt%st%st%sn", meeting.GetMeetingID(), meeting.GetSponser(), meeting.GetInvitee(), startTime, endTime, meeting.GetTitle() ); returnMsg.append(
83、tempStr ); return SUCCESS_MSG; if(strcmp(cmd,"changepassword")=0) if( Split( argvs, ' ', argv1, argvs ) != 1 ) return ERROR_ARGV; if( Split( argvs, &
84、#39; ', argv2, argv3 ) != 1 ) return ERROR_ARGV; if( manager.CheckIn( argv1, argv2 ) ) manager.Change_Password(argv1,argv2,argv3); return SUCCESS_CHANGE; else return ERROR_CHANGE; if( strcmp( cmd, "qui
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024物業(yè)服務(wù)合同服務(wù)內(nèi)容與標(biāo)的
- 地鐵車輛段維修挖機(jī)租賃合同樣本
- 企業(yè)內(nèi)部保安員招聘合同
- 借用資質(zhì)的內(nèi)部合作協(xié)議
- 2024版二手房買賣合同無房產(chǎn)證
- 二零二五年度能源消耗優(yōu)化合作協(xié)議書2篇
- 二零二五年度電子元器件庫存管理合同3篇
- 2024版建設(shè)工程合同管理題庫
- 2024環(huán)境保護(hù)合同協(xié)議書
- 二零二五年度社保代繳業(yè)務(wù)合作協(xié)議2篇
- 鑄牢中華民族共同體意識-考試復(fù)習(xí)題庫(含答案)
- 新GCP醫(yī)療器械臨床試驗(yàn)知識試題(附含答案)
- 2024年浙江首考高考選考生物試卷試題真題(含答案詳解)
- 春節(jié)期間安全告知書
- 天津市紅橋區(qū)2023-2024學(xué)年七年級上學(xué)期期末地理試題
- 西門子數(shù)字化工廠-數(shù)字化車間-先進(jìn)制造技術(shù)
- 飯店新店后廚培訓(xùn)方案
- 青少年禮儀培訓(xùn)課件
- 2024醫(yī)院消防安全培訓(xùn)
- 景區(qū)銷售可行性報告
- 公路自然災(zāi)害的防治-路基水毀的類型與防治對策
評論
0/150
提交評論