议程管理系统程序_第1页
议程管理系统程序_第2页
议程管理系统程序_第3页
议程管理系统程序_第4页
议程管理系统程序_第5页
已阅读5页,还剩68页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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);     /将输入的命令进行解析&#

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);     /将输入的命令进行解析 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; /创建人 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<<"-欢迎使用议程管理系统-"<<endl<<endl; while( true )

18、60;  /获取用户输入的命令  cout<<'$'  cin.getline(cmd, 2047 );  /命令交由Controller处理  returnValue = controller.DispatchMessage(cmd);  /根据返回值作出相应的提示  switch( returnValue )    case SUCCESS:   cout

19、<<"操作成功完成!"<<endl<<endl;   break;  case ERROR_COMMAND:   cout<<"无法识别的命令!"<<endl<<endl;   break;  case ERROR_ARGV:   cout<<"参数数量不正确!"<<endl<

20、<endl;   break;  case ERROR_REGISTER:   cout<<"注册失败,用户名已存在!"<<endl<<endl;   break;  case ERROR_CLEAR:   cout<<"清空用户会议列表失败!"<<endl<<endl;   break;&

21、#160; case ERROR_DELETE:   cout<<"删除会议失败,可能会议不存在或该用户不是会议创建者!"<<endl<<endl;   break;  case ERROR_ADD:   cout<<"添加会议失败,请检查参数正确性!"<<endl<<endl;   break;  case ERR

22、OR_QUERY:   cout<<"查询会议失败,请检查参数正确性!"<<endl<<endl;   break;  case SUCCESS_MSG:   cout<<"IDt创建人tt被邀请人t开始时间t结束时间t标题"<<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输入的命令进行解析,并相应的作出反应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)/将输入的命令进行解析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进行解析,由于add 有5个参数,所以要考虑缺少参数的情况 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<<"参数数量不正确!"<<endl<<endl;    else if( manager.Register( argv1, argv2 ) )     cout << "register操作成功" << endl;   &

46、#160;else     cout<<"注册失败,用户名已存在!"<<endl<<endl;      /对命令add进行解析,由于add 有5个参数,所以要考虑缺少参数的情况   if(strcmp(cmd,"add")=0)       if( Split( argvs, ' ', argv

47、1, argvs ) != 1 )        cout<<"参数数量不正确!"<<endl<<endl;    else if( Split( argvs, ' ', argv2, argvs ) != 1 )     cout<<"参数数量不正确!"<<endl<<endl;  

48、60;    else if( Split( argvs, ' ', argv3, argvs ) != 1 )     cout<<"参数数量不正确!"<<endl<<endl;       else if( Split( argvs, ' ', argv4, argvs ) != 1 )     cout<&l

49、t;"参数数量不正确!"<<endl<<endl;       else if( Split( argvs, ' ', argv5, argv6 ) != 1 )     cout<<"参数数量不正确!"<<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<<"添加会议失败,请检查参数正确性!"<<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<<"参数数量不正确!"<<endl<<endl;    if( Split( argvs, ' ', argv2, argvs ) != 1 )     cout<<"参数数量不正确!"<<endl<<endl;    if( Split( argvs, ' ', argv3,

54、 argv4 ) != 1 )     cout<<"参数数量不正确!"<<endl<<endl;      bool result = manager.Query( argv1, argv2, StrToDate( argv3 ), StrToDate( argv4 ), meetingList );      if( !result )  

55、0;  cout<<"查询会议失败,请检查参数正确性!"<<endl<<endl;    returnMsg = ""    int size = meetingList.size();    if( size = 0 )         returnMsg = "会议列表为空!&q

56、uot;     cout<<"IDt创建人tt被邀请人t开始时间t结束时间t标题"<<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创建人tt被邀请人t开始时间t结束时间t标题"<<endl;    cout<<GetReturnMsg().c_str()<<endl<<

60、endl;      /删除回忆记录   if(strcmp(cmd,"delete")=0)       if( Split( argvs, ' ', argv1, argvs ) != 1 )     cout<<"参数数量不正确!"<<endl<<endl;   

61、; if( Split( argvs, ' ', argv2, argv3 ) != 1 )     cout<<"参数数量不正确!"<<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、议创建者!"<<endl<<endl;      /清除某个用户所有的会议   if(strcmp(cmd,"clear")=0)       if( Split( argvs, ' ', argv1, argv2 ) != 1 )     cout<<"参数数量不正确!"<<

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<<"参数数量不正确!"<<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;"参数数量不正确!"<<endl<<endl;      bool result = manager.QueryAll( argv1, argv2, meetingList );      if( !result )     cout<<"查询会议失败,请检查参数正确性!"<<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<<"参数数量不正确!"<<endl<<endl;    if( Split( argvs, ' ', argv2, argv3 ) != 1 )     cout<<"参数数量不正确!"<<

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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论