中山大学软件工程专业初级实训-会议议程管理Agenda

刚刚经历了两个星期的中级实训,那么这次实训的话毫无疑问地比大一初级实训简单了。在这里的话呢,还要感谢许多前辈给的神器。这里首先感谢@卡帕kalper前辈和@jayjiahua前辈。下面给出两个中级实训的神器。那么经历了一次相对来说比较轻松的实训之后呢,感觉大一时候的初级实训真是太辛苦了,而且的话缺少神器。所以决定向以上两位大神学习,给迷茫中的学弟学妹们一些指引,这里借用前辈的一句话,因为平时在完成一些任务的时候,深刻感受到前人经验带给自己的便利,在此我也分享下自己的东西,希望能给后人乘荫吧~!

http://blog.csdn.net/zkp0601/article/details/38564501

https://github.com/jayjiahua/GridWorld

我们初级实训主要使用C++语言写出一个会议议程管理系统Agenda。由于时间过去比较久了记忆不太清楚了,而且写码时间不长(只写了一天),因为写的比较仓促,所以声明和实现都写在一个文件里了,可能的话会还有一些些的Bug,而且没有什么注释,大家阅读起来可能比较困难,如果对源码有疑问或者有帮我找出Bug的同学,欢迎给我发邮件,邮箱:[email protected]

想自己学习代码的同学请直接往下滑,或者戳下面的链接:

https://github.com/yang20150928/Agenda/tree/master/src

下面给出会议议程管理系统Agenda需求文档和三层架构介绍,github链接中给出了本次实训所有头文件。

http://my.ss.sysu.edu.cn/wiki/download/attachments/304840949/xuqiu.pdf?version=1&modificationDate=1404036510000

http://blog.csdn.net/hanxuemin12345/article/details/8544957

https://github.com/ss14agenda/Agenda/tree/master/src

接下来我们来说第一阶段。那么第一阶段的话呢我们就是要完成Date 类,User 类,Meeting 类,Storage类的代码实现,下面给出这其中几个类的UML图(缺少Date类的UML图)和需求链接和Date类的需求,这里的Storage类我按照当时大一的要求,使用的是JSON的存储格式,由于C++没有JSON的库,所以这部分代码写起来比较麻烦(也花了我很多时间)。

http://my.ss.sysu.edu.cn/wiki/download/attachments/167936064/%E5%8F%82%E9%98%85%E8%B5%84%E6%96%99_User+class+diagram+and+code.pdf?version=1&modificationDate=1343288053000

http://my.ss.sysu.edu.cn/wiki/download/attachments/167936064/%E5%8F%82%E9%98%85%E8%B5%84%E6%96%99_Meeting+class+diagram.pdf?version=1&modificationDate=1343617818000

http://my.ss.sysu.edu.cn/wiki/download/attachments/304840949/Storage.png?version=3&modificationDate=1403996090000

http://my.ss.sysu.edu.cn/wiki/download/attachments/167936064/%E5%AF%B9%E4%BA%8E%E4%BC%9A%E8%AE%AE%E6%97%B6%E9%97%B4%E6%98%BE%E7%A4%BA%E7%9A%84%E9%A2%9D%E5%A4%96%E8%A1%A5%E5%85%85.pdf?version=2&modificationDate=1378093428000

我们这一阶段主要实现三层架构中的数据访问层。首先来看User类,User类的话有四个私有属性name, password, email, phone, User类的方法就是对这些属性的set和get。Meeting类也是类似。Date类的话还有三个静态函数实现起来比较麻烦,而且还需要运算符重载。

Storage类中通过操作系统文件的读写完成数据的存储。Storage类采用单例模式设计,只有一个实例,也就是所谓的Singonton。他有一个instance指针实例变量,而且构造函数就是私有的,只能通过getInstance()方法取回实例,所以getInstance()方法思路大致如下:如果属性instance为空,instance就new一个Storage实例,否则返回instance。Storage还有两个list属性用于存储user和meeting。由于在会议议程管理系统Agenda启动时,要从文件中读取数据,所以Storage类的构造函数中调用readFromFile()方法,readFromFile()方法从文件中读取数据,sync是同步的缩写,所以在sync()方法中我们进行数据的同步,也是将内存中的数据写入磁盘中的文件,所以调用writeToFile()方法。其余的query,update,delete方法就是根据传入filter函数进行处理。由于我们不需要在Storage类中进行逻辑判断,所以在create方法中我们直接调用list中的push_back()方法。query方法遍历整个list,如果filter返回值为真,就插入新list中,最好返回新list。update方法也是遍历整个list,如果filter返回值为真,就用switcher函数进行更新,返回更新的数目。delete方法也是遍历整个list,如果filter返回值为真,调用list中erase()方法删除,返回删除的数目。

下面给出实现这四个类的代码:

#ifndef __USER_H__
#define __USER_H__
#include <string>
using namespace std;
class User {
    public:
        User() {}
        User(string userName, string userPassword,
             string userEmail, string userPhone) {
            name_ = userName;
            password_ = userPassword;
            email_ = userEmail;
            phone_ = userPhone;
        }
        string getName() const {
            return name_;
        }
        void setName(string name) {
            name_ = name;
        }
        string getPassWord() const {
            return password_;
        }
        void setPassword(string password) {
            password_ = password;
        }
        string getEmail() const {
            return email_;
        }
        void setEmail(string email) {
            email_ = email;
        }
        string getPhone() const {
            return phone_;
        }
        void setPhone(string phone) {
            phone_ = phone;
        }
    private:
        string name_;
        string password_;
        string email_;
        string phone_;
};

#endif
#ifndef __DATE_H__
#define __DATE_H__
#include <string>
#include <sstream>
using namespace std;
class Date {
    public:
        Date() {}
        Date(int y, int m, int d, int h, int mi) {
            year_ = y;
            month_ = m;
            day_ = d;
            hour_ = h;
            minute_ = mi;
        }
        int getYear(void) const {
            return year_;
        }
        void setYear(int year) {
            year_ = year;
        }
        int getMonth(void) const {
            return month_;
        }
        void setMonth(int month) {
            month_ = month;
        }
        int getDay(void) const {
            return day_;
        }
        void setDay(int day) {
            day_ = day;
        }
        int getHour(void) const {
            return hour_;
        }
        void setHour(int hour) {
            hour_ = hour;
        }
        int getMinute(void) const {
            return minute_;
        }
        void setMinute(int minute) {
            minute_ = minute;
        }
        static bool isValid(Date date) {
            if (!(date.getYear() >= 1000 && date.getYear() <= 9999))
                return false;
            if (!(date.getMonth() >= 1 && date.getMonth() <= 12))
                return false;
            if (date.getMonth() != 2) {
                switch (date.getMonth()) {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:
                        if (!(date.getDay() >= 1 && date.getDay() <= 31))
                            return false;
                        break;
                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        if (!(date.getDay() >= 1 && date.getDay() <= 30))
                            return false;
                        break;
                    default:
                        break;
                }
            }
            else if (Isleap(date)) {
                if (!(date.getDay() >= 1 && date.getDay() <= 29))
                    return false;
            }
            else {
                if (!(date.getDay() >= 1 && date.getDay() <= 28))
                    return false;
            }
            if (!(date.getHour() >= 0 && date.getHour() <= 23))
                return false;
            if (!(date.getMinute() >= 0 && date.getMinute() <= 59))
                return false;
            return true;
        }
        static Date stringToDate(std::string dateString) {
            stringstream ss;
            int y, m, d, h, mi;
            char t;
            ss << dateString;
            ss >> y >> t >> m >> t
               >> d >> t >> h >> t >> mi;
            return Date(y, m, d, h, mi);
        }
        static std::string dateToString(Date date) {
            stringstream ss;
            ss << date.getYear() << "-"
               << supplyZero(date.getMonth()) << "-"
               << supplyZero(date.getDay()) << "/"
               << supplyZero(date.getHour()) << ":"
               << supplyZero(date.getMinute());
            return ss.str();
        }
        Date &operator=(const Date& date) {
            setYear(date.getYear());
            setMonth(date.getMonth());
            setDay(date.getDay());
            setHour(date.getHour());
            setMinute(date.getMinute());
            return *this;
        }
        bool operator==(const Date& date) const {
            return getYear() == date.getYear() &&
                   getMonth() == date.getMonth() &&
                   getDay() == date.getDay() &&
                   getHour() == date.getHour() &&
                   getMinute() == date.getMinute();
        }
        bool operator>(const Date& date) const {
            return getYear() > date.getYear() ? true :
                   getMonth() > date.getMonth() ? true :
                   getDay() > date.getDay() ? true :
                   getHour() > date.getHour() ? true : false;
        }
        bool operator<(const Date& date) const {
            return !(*this > date) && !(*this == date);
        }
        bool operator>=(const Date& date) const {
            return !(*this < date);
        }
        bool operator<=(const Date& date) const {
            return !(*this > date);
        }
    private:
        int year_;
        int month_;
        int day_;
        int hour_;
        int minute_;
        static bool Isleap(Date date) {
            return (date.getYear() / 4 == 0 && date.getYear() / 100 != 0)
                   || date.getYear() / 400 == 0;
        }
        static string supplyZero(int arg) {
            stringstream ss;
            if (arg < 10) {
                ss << "0" << arg;
            }
            else {
                ss << arg;
            }
            return ss.str();
        }
};
#endif
#ifndef __MEETING_H__
#define __MEETING_H__

#include "Date.h"
using namespace std;

class Meeting {
    public:
        Meeting() {}
        Meeting(std::string sponsor, std::string participator,
                Date startTime, Date endTime, std::string title) {
            sponsor_ = sponsor;
            participator_ = participator;
            startDate_ = startTime;
            endDate_ = endTime;
            title_ = title;
        }
        std::string getSponsor(void) const {
            return sponsor_;
        }
        void setSponsor(std::string sponsor) {
            sponsor_ = sponsor;
        }
        std::string getParticipator(void) const {
            return participator_;
        }
        void setParticipator(std::string participator) {
            participator_ = participator;
        }
        Date getStartDate(void) const {
            return startDate_;
        }
        void setStartDate(Date startTime) {
            startDate_ = startTime;
        }
        Date getEndDate(void) const {
            return endDate_;
        }
        void setEndDate(Date endTime) {
            endDate_ = endTime;
        }
        std::string getTitle(void) const {
            return title_;
        }
        void setTitle(std::string title) {
            title_ = title;
        }

    private:
        std::string sponsor_;
        std::string participator_;
        Date startDate_;
        Date endDate_;
        std::string title_;
};

#endif
#ifndef __STORAGE_H__
#define __STORAGE_H__

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
  TypeName(const TypeName&);   void operator=(const TypeName&)

#include <list>
#include <string>
#include <functional>
#include <fstream>
#include <iostream>

#include "User.h"
#include "Meeting.h"
using namespace std;

class Storage {
    private:
        static Storage *instance_;
        DISALLOW_COPY_AND_ASSIGN(Storage);
        Storage() {
            readFromFile("agenda.data");
        }
        // storage structure with list, or you have better structures
        // e.g. balanced tree
        std::list<User> userList_;
        std::list<Meeting> meetingList_;
        // File IO
        bool readFromFile(const char *fpath) {
            ifstream fin(fpath);
            if (!fin.is_open())
                return false;
            int userCount, meetingCount;
            string str;
            stringstream ss;
            fin >> str;
            str = str.substr(str.find("total:") + 6);
            ss << str;
            ss >> userCount;
            ss.str("");
            for (int i = 0; i < userCount; i++) {
                fin >> str;
                userList_.push_back(JSONToUser(str));
            }

            fin >> str;
            str = str.substr(str.find("total:") + 6);
            ss << str;
            ss >> meetingCount;
            for (int i = 0; i < meetingCount; i++) {
                fin >> str;
                meetingList_.push_back(JSONToMeeting(str));
            }
            return true;
        }
        bool writeToFile(const char *fpath) {
            ofstream fout(fpath);
            if (!fout.is_open())
                return false;
            fout << "{colletion:\"User\",total:" << userList_.size() << "}\n";
            for (auto itr = userList_.begin(); itr != userList_.end(); itr++) {
                fout << UserToJSON(*itr) << endl;
            }
            fout << "{colletion:\"Meeting\",total:" << meetingList_.size() << "}\n";
            for (auto itr = meetingList_.begin(); itr != meetingList_.end(); itr++) {
                fout << MeetingToJSON(*itr) << endl;
            }
            return true;
        }
        string UserToJSON(const User& user) {
            stringstream ss;
            ss << "{name:" << "\"" << user.getName() << "\","
               << "password:" << "\"" << user.getPassWord() << "\","
               << "email:" << "\"" << user.getEmail() << "\","
               << "phone:" << "\"" << user.getPhone() << "\"}";
            return ss.str();
        }
        string MeetingToJSON(const Meeting& meeting) {
            stringstream ss;
            ss << "{sponsor:" << "\"" << meeting.getSponsor() << "\","
               << "partipator:" << "\"" << meeting.getParticipator() << "\","
               << "sdate:" << "\"" << Date::dateToString(meeting.getStartDate()) << "\","
               << "edate:" << "\"" << Date::dateToString(meeting.getEndDate()) << "\","
               << "title:" << "\"" << meeting.getTitle() << "\"}";
            return ss.str();
        }
        User JSONToUser(const string& json) {
            string name, password, email, phone;
            int pos, len;
            pos = json.find("name:\"") + 6;
            len = json.find("\",password") - pos;
            name = json.substr(pos, len);
            pos = json.find("password:\"") + 10;
            len = json.find("\",email") - pos;
            password = json.substr(pos, len);
            pos = json.find("email:\"") + 7;
            len = json.find("\",phone") - pos;
            email = json.substr(pos, len);
            pos = json.find("phone:\"") + 7;
            len = json.find("\"}") - pos;
            phone = json.substr(pos, len);
            return User(name, password, email, phone);
        }
        Meeting JSONToMeeting(const string& json) {
            string sponsor, partipator, sdate, edate, title;
            int pos, len;
            pos = json.find("sponsor:\"") + 9;
            len = json.find("\",partipator") - pos;
            sponsor = json.substr(pos, len);
            pos = json.find("partipator:\"") + 12;
            len = json.find("\",sdate") - pos;
            partipator = json.substr(pos, len);
            pos = json.find("sdate:\"") + 7;
            len = json.find("\",edate") - pos;
            sdate = json.substr(pos, len);
            pos = json.find("edate:\"") + 7;
            len = json.find("\",title") - pos;
            edate = json.substr(pos, len);
            pos = json.find("title:\"") + 7;
            len = json.find("\"}") - pos;
            title = json.substr(pos, len);
            return Meeting(sponsor, partipator,
                Date::stringToDate(sdate), Date::stringToDate(edate), title);
        }
    public:
        // singleton
        static Storage *getInstance(void) {
            if (instance_ == nullptr)
                instance_ = new Storage();
            return instance_;
        }
        ~Storage() {}
        // CRUD for User & Meeting
        // using C++11 Function Template and Lambda Expressions
        void createUser(const User& user) {
            userList_.push_back(user);
        }
        std::list<User> queryUser(std::function<bool(const User&)> filter) {
            list<User> returnList;
            for (auto itr = userList_.begin(); itr != userList_.end(); itr++) {
                if (filter(*itr)) {
                    returnList.push_back(*itr);
                }
            }
            return returnList;
        }
        // return found users
        int updateUser(std::function<bool(const User&)> filter,
                       std::function<void(User&)> switcher) {
            int count = 0;
            for (auto itr = userList_.begin(); itr != userList_.end(); itr++) {
                if (filter(*itr)) {
                    switcher(*itr);
                    count++;
                }
            }
            return count;
        }
        // return the number of updated users
        int deleteUser(std::function<bool(const User&)> filter) {
            int count = 0;
            for (auto itr = userList_.begin(); itr != userList_.end(); itr++) {
                if (filter(*itr)) {
                    userList_.push_back(*itr);
                    count++;
                }
            }
            return count;
        }
        // return the number of deleted users
        void createMeeting(const Meeting& meeting) {
            meetingList_.push_back(meeting);
        }
        std::list<Meeting> queryMeeting(
                       std::function<bool(const Meeting&)> filter) {
            list<Meeting> returnList;
            for (auto itr = meetingList_.begin(); itr != meetingList_.end(); itr++) {
                if (filter(*itr)) {
                    returnList.push_back(*itr);
                }
            }
            return returnList;
        }
        // return found meetings
        int updateMeeting(std::function<bool(const Meeting&)> filter,
            std::function<void(Meeting&)> switcher) {
            int count = 0;
            for (auto itr = meetingList_.begin(); itr != meetingList_.end(); itr++) {
                if (filter(*itr)) {
                    switcher(*itr);
                    count++;
                }
            }
            return count;
        }
        // return the number of updated meetings
        int deleteMeeting(std::function<bool(const Meeting&)> filter) {
            int count = 0;
            for (auto itr = meetingList_.begin(); itr != meetingList_.end(); itr++) {
                if (filter(*itr)) {
                    meetingList_.erase(itr);
                    count++;
                }
            }
            return count;
        }
        // return the number of deleted meetings
        // File IO
        bool sync(void) {
            return writeToFile("agenda.data");
        }
};
Storage* Storage::instance_ = nullptr;
#endif

那么阶段二的话呢,我们就要完成完成AgendaService类(应用逻辑实体)和AgendaUI类(终端交互界面)的实现了。下面给出代码实现。这里要注意的是lambda函数的运用还有就是

1会议的title是唯一的。

2不允许创建会议为一个时间点,比如从8点到8点

3关于找出一个时间段内的会议,只要有时间点重叠,都要算上去。

AgendaService类中的私有属性是Storage的实例,所有在startAgenda()方法中取回实例,那么在quitAgenda()进行数据更新,所以分别在构造函数和析构函数中调用他们。至于其他的list, query, create, delete等的方法我们通过lambda函数给定自己的filter,然后调用Storage类中相关方法就行了。

下面先给出Agenda的接口约束:

http://my.ss.sysu.edu.cn/wiki/pages/viewpage.action?pageId=431849490

AgendaUI类中,有三个私有属性,userName, userPassword, 和一个AgendaService对象,userName和userPassword应该就是当前用户的姓名和密码了,所以我们在userLogIn()和userRegister()方法中对他们复制,由于只有用户登录之后才能进行管理操作,所以我们在userLogIn()和userRegister()中加入以下的这个语句while(executeOperation(getOperation()));

用来循环处理管理操作,由于用户登出以及用户删除自己之后不能在进行管理操作,所以在executeOperation()方法中调用这些行为并且返回false。这样的话我们在OperationLoop()方法中只处理登录前的循环操作就可以了。其余的方法大致就是先向用户请求输入,然后调用AgendaService中的方法就行了。

#ifndef __AGENDASERVICE_H__
#define __AGENDASERVICE_H__

#include "Storage.h"
#include <list>
#include <string>
using namespace std;

class AgendaService {
    public:
        AgendaService() {
            startAgenda();
        }
        ~AgendaService() {
            quitAgenda();
        }
        bool userLogIn(std::string userName, std::string password) {
            auto filter = [userName, password](const User& user) {
                return user.getName() == userName && user.getPassWord() == password;
            };
            return storage_->queryUser(filter).size() > 0;
        }
        bool userRegister(std::string userName, std::string password,
                          std::string email, std::string phone) {
            auto filter = [userName, password, email, phone](const User& user) {
                return user.getName() == userName || user.getEmail() == email
                    || user.getPhone() == phone;
            };
            if (storage_->queryUser(filter).size() == 0) {
                storage_->createUser(User(userName, password, email, phone));
                return true;
            }
            return false;
        }
        bool deleteUser(std::string userName, std::string password) {
            auto filter = [userName, password](const User& user) {
                return user.getName() == userName && user.getPassWord() == password;
            };
            if (storage_->deleteUser(filter) > 0) {
                deleteAllMeetings(userName);
                return true;
            }
            return false;
        }
        // a user can only delete itself
        std::list<User> listAllUsers(void) {
            auto filter = [](const User& user) {
                return true;
            };
            return storage_->queryUser(filter);
        }

        bool createMeeting(std::string userName, std::string title,
                           std::string participator,
                           std::string startDate, std::string endDate) {
            if (!Date::isValid(Date::stringToDate(startDate))
                || !Date::isValid(Date::stringToDate(endDate))) {
                return false;
            }
            auto filter1 = [participator](const User& user) {
                return user.getName() == participator;
            };
            if (storage_->queryUser(filter1).size() <= 0) {
                return false;
            }
            auto filter2 = [title](const Meeting& meeting) {
                return meeting.getTitle() == title;
            };
            if (storage_->queryMeeting(filter2).size() > 0) {
                return false;
            }
            if (meetingQuery(userName, startDate, endDate).size() > 0
                || meetingQuery(participator, startDate, endDate).size() > 0) {
                return false;
            }
            storage_->createMeeting(Meeting(userName, participator,
                Date::stringToDate(startDate), Date::stringToDate(endDate), title));
            return true;
        }
        std::list<Meeting> meetingQuery(std::string userName, std::string title) {
            auto filter = [userName, title](const Meeting& meeting) {
                return (meeting.getSponsor() == userName ||
                        meeting.getParticipator() == userName) &&
                        meeting.getTitle() == title;
            };
            return storage_->queryMeeting(filter);
        }
        std::list<Meeting> meetingQuery(std::string userName, std::string startDate,
                                        std::string endDate) {
            auto filter = [userName, startDate, endDate](const Meeting& meeting) {
                return (meeting.getSponsor() == userName || meeting.getParticipator() == userName) &&
                       ((meeting.getStartDate() >= Date::stringToDate(startDate) &&
                         meeting.getStartDate() <= Date::stringToDate(endDate) ||
                        (meeting.getEndDate() >= Date::stringToDate(startDate) &&
                         meeting.getEndDate() <= Date::stringToDate(endDate)) ||
                        (meeting.getStartDate() <= Date::stringToDate(startDate) &&
                         meeting.getEndDate() >= Date::stringToDate(endDate))));
            };
            return storage_->queryMeeting(filter);
        }
        std::list<Meeting> listAllMeetings(std::string userName) {
            auto filter = [userName](const Meeting& meeting) {
                return meeting.getSponsor() == userName ||
                       meeting.getParticipator() == userName;
            };
            return storage_->queryMeeting(filter);
        }
        std::list<Meeting> listAllSponsorMeetings(std::string userName) {
            auto filter = [userName](const Meeting& meeting) {
                return meeting.getSponsor() == userName;
            };
            return storage_->queryMeeting(filter);
        }
        std::list<Meeting> listAllParticipateMeetings(std::string userName) {
            auto filter = [userName](const Meeting& meeting) {
                return meeting.getParticipator() == userName;
            };
            return storage_->queryMeeting(filter);
        }
        bool deleteMeeting(std::string userName, std::string title) {
            auto filter = [userName, title](const Meeting& meeting) {
                return (meeting.getSponsor() == userName ||
                        meeting.getParticipator() == userName) &&
                        meeting.getTitle() == title;
            };
            return storage_->deleteMeeting(filter) > 0;
        }
        bool deleteAllMeetings(std::string userName) {
            auto filter = [userName](const Meeting& meeting) {
                return meeting.getSponsor() == userName ||
                       meeting.getParticipator() == userName;
            };
            return storage_->deleteMeeting(filter) > 0;
        }

        void startAgenda(void) {
            storage_ = Storage::getInstance();
        }
        void quitAgenda(void) {
            storage_->sync();
        }

    private:
        Storage *storage_;
};

#endif
#ifndef __AGENDAUI_H__
#define __AGENDAUI_H__

#include "AgendaService.h"
#include <iostream>
#include <string>

class AgendaUI {
    public:
        AgendaUI() {
            startAgenda();
        }
        void OperationLoop(void) {
            string operation;
            do {
                cout << "________________________________Agenda________________________________\n"
                     << "Action :\n"
                     << "l   - log in Agenda by user name and password\n"
                     << "r   - register an Agenda account\n"
                     << "q   - quit Agenda\n"
                     << "______________________________________________________________________\n"
                     << "\n" << "Agenda : ~$ ";
                cin >> operation;
                switch(operation[0]) {
                    case ‘l‘:
                        userLogIn();
                        break;
                    case ‘r‘:
                        userRegister();
                        break;
                    case ‘q‘:
                        quitAgenda();
                        break;
                    default:
                        break;
                }
            } while(operation[0] != ‘q‘);
        }

    private:
        // task functions
        void startAgenda(void) {
            agendaService_.startAgenda();
        }
        std::string getOperation() {
            string operation;
            cout << "________________________________Agenda________________________________\n"
                 << "Action :\n"
                 << "o   - log out Agenda\n"
                 << "dc  - delete Agenda account\n"
                 << "lu  - list all Agenda user\n"
                 << "cm  - create a meeting\n"
                 << "la  - list all meetings\n"
                 << "las - list all sponsor meetings\n"
                 << "lap - list all participate meetings\n"
                 << "qm  - query meeting by title\n"
                 << "qt  - query meeting by time interval\n"
                 << "dm  - delete meeting by title\n"
                 << "da  - delete all meetings\n"
                 << "______________________________________________________________________\n"
                 << "\n" << "[email protected]" << userName_ << " :# ";
            cin >> operation;
            return operation;
        }
        bool executeOperation(std::string op) {
            if (op == "o") {
                userLogOut();
                return false;
            }
            else if (op == "dc") {
                deleteUser();
                return false;
            }
            else if (op == "lu") {
                listAllUsers();
                return true;
            }
            else if (op == "cm") {
                createMeeting();
                return true;
            }
            else if (op == "la") {
                listAllMeetings();
                return true;
            }
            else if (op == "las") {
                listAllSponsorMeetings();
                return true;
            }
            else if (op == "lap") {
                listAllParticipateMeetings();
                return true;
            }
            else if (op == "qm") {
                queryMeetingByTitle();
                return true;
            }
            else if (op == "qt") {
                queryMeetingByTimeInterval();
                return true;
            }
            else if (op == "dm") {
                deleteMeetingByTitle();
                return true;
            }
            else if (op == "da") {
                deleteAllMeetings();
                return true;
            }
            return true;
        }
        void userLogIn(void) {
            string userName, password;
            cout << "[log in] [user name] [password]\n"
                 << "[log in] ";
            cin >> userName >> password;
            if (agendaService_.userLogIn(userName, password)) {
                userName_ = userName;
                userPassword_ = password;
                cout << "[log in] succeed!\n";
                while(executeOperation(getOperation()));
            }
            else {
                cout << "[error] log in fail!\n";
            }
        }
        void userRegister(void) {
            string userName, password, email, phone;
            cout << "[register] [user name] [password] [email] [phone]\n"
                 << "[register] ";
            cin >> userName >> password >> email >> phone;
            if (agendaService_.userRegister(userName, password, email, phone)) {
                userName_ = userName;
                userPassword_ = password;
                cout << "[register] succeed!\n";
                while(executeOperation(getOperation()));
            }
            else {
                cout << "[error] register fail!\n";
            }
        }
        void quitAgenda(void) {
            agendaService_.quitAgenda();
        }
        void userLogOut(void) {
            userName_.clear();
            userPassword_.clear();
        }
        void deleteUser(void) {
            agendaService_.deleteUser(userName_, userPassword_);
            userLogOut();
        }
        void listAllUsers(void) {
            printUsers(agendaService_.listAllUsers());
        }
        void createMeeting(void) {
            string title, participator, startDate, endDate;
            cout << "[create meeting] [title] [participator] [start time(yyyy-mm-dd/hh:mm)] [end time(yyyy-mm-dd/hh:mm)]\n"
                 << "[create meeting] ";
            cin >> title >> participator >> startDate >> endDate;
            if (agendaService_.createMeeting(userName_, title, participator, startDate, endDate)) {
                cout << "[create meeting] succeed!\n";
            }
            else {
                cout << "[error] create meeting fail!\n";
            }
        }
        void listAllMeetings(void) {
            printMeetings(agendaService_.listAllMeetings(userName_));
        }
        void listAllSponsorMeetings(void) {
            printMeetings(agendaService_.listAllSponsorMeetings(userName_));
        }
        void listAllParticipateMeetings(void) {
            printMeetings(agendaService_.listAllParticipateMeetings(userName_));
        }
        void queryMeetingByTitle(void) {
            string title;
            cout << "[query meeting] [title]\n"
                 << "[query meeting] ";
            cin >> title;
            printMeetings(agendaService_.meetingQuery(userName_, title));
        }
        void queryMeetingByTimeInterval(void) {
            string startDate, endDate;
            cout << "[query meetings] [start time(yyyy-mm-dd/hh:mm)] [end time(yyyy-mm-dd/hh:mm)]\n"
                 << "[query meetings] ";
            cin >> startDate >> endDate;
            printMeetings(agendaService_.meetingQuery(userName_, startDate, endDate));
        }
        void deleteMeetingByTitle(void) {
            string title;
            cout << "[delete meeting] [title]\n"
                 << "[delete meeting] ";
            cin >> title;
            if (agendaService_.deleteMeeting(userName_, title)) {
                cout << "[delete meeting by title] succeed!\n";
            }
            else {
                cout << "[error] delete meeting fail!\n";
            }
        }
        void deleteAllMeetings(void) {
            agendaService_.deleteAllMeetings(userName_);
            cout << "[delete all meetings] succeed!\n";
        }
        void printMeetings(std::list<Meeting> meetings) {
            cout << "title\t" << "sponsor\t" << "participator\t"
                 << "start time\t" << "end time\n";
            for (auto itr = meetings.begin(); itr != meetings.end(); itr++) {
                cout << itr->getTitle() << "\t"
                     << itr->getSponsor() << "\t"
                     << itr->getParticipator() << "\t"
                     << Date::dateToString(itr->getStartDate()) << "\t"
                     << Date::dateToString(itr->getEndDate()) << "\n";
            }
        }
        void printUsers(std::list<User> users) {
            cout << "name\t" << "email\t" << "phone\n";
            for (auto itr = users.begin(); itr != users.end(); itr++) {
                cout << itr->getName() << "\t"
                     << itr->getEmail() << "\t"
                     << itr->getPhone() << "\n";
            }
        }
        // dates
        std::string userName_;
        std::string userPassword_;
        AgendaService agendaService_;
};

#endif

最后给出cpp文件的源码

#include "AgendaUI.h"
AgendaUI aui;

int main() {
    aui.OperationLoop();
    return 0;
}

由于这次写码和写文时间比较仓促,有很多代码没有经过测试,所以仅供大家参考,不过正常的run还是可以的,而且可能有代码可读性差的问题。另外我最后测试也没能解决的一个Bug,就是创建会议的时候参与者是不存在的用户也能成功创建,希望有大神同学能帮我解决。

时间: 2024-10-08 06:18:11

中山大学软件工程专业初级实训-会议议程管理Agenda的相关文章

Java实训项目--影碟管理软件

一.项目名称 影碟管理软件 二.软件描述 该影碟管理程序可以只在控制台上运行,可以不需要界面.该软件的功能有如下功能: A:可以查看该店铺的所有影碟的信息: B:可以添加新的影碟信息: C:可以修改现有影碟信息: D:可以删除某个影碟信息: E:所有影碟的数据都保存在硬盘的某个txt文件中,在修改完信息后,硬盘中的该文件也能同步改变. 三.代码 1 import java.util.Scanner; 2 import java.util.LinkedList; 3 import java.uti

山西高平地域文化导入美术设计实训项目的实践

地域文化,是指某个地域的人们在特定的范围内,在自然环境的基础上,在长期的生产生活中创造的.人类活动的产物.山西高平是神农炎帝的故里,长平之战的发生地,是一个有着很深文化积淀的新兴城市,行政区域是国土面积的万分之一,却浓缩了中国五千年文化的精髓.本文通过对山西高平丰富的历史文化资源的调查研究,探讨如何将地域文化元素导入中职美术设计专业的实训项目教学过程,论证典型地域文化元素在中职美术设计教育中的独特作用,并以此作为教学实训素材,依托带有典型地域文化特征的企业真实案例,结合教育教学实践,探索中职美术

2016年秋季软件工程专业实训分组及选题情况

实训意义 综合实训旨在为学生提供参与完整软件开发过程的实践经历,并对所涉及的应用领域进行初步了解,培养面向领域的工程能力.项目来源主要是学校或相关合作企业在校内设立专门的学生研究开发项目,可以聘请企业专家组织和指导学生模拟企业环境进行项目开发,给学生带来真实的企业研发的环境和流程.     实训目标 (1)训练学生软件开发流程和规范:体会企业开发流程:熟悉常用开发工具.模板和表格的使用: (2)体会企业中的团队合作规范:培养团队开发和协同工作的能力:熟悉团队成员在软件开发项目中的角色分工及沟通协

专业实训8.29

1.本日任务 确定专业实训题目,并查相关学习资料进行学习. 2.题目确定 通过在中国大学生软件设计大赛网站:http://www.cnsoftbei.com/所给出的相关题目中选出自己所看重的题目——基于web的3D模型浏览与交互系统. 3.选题图片 4.选题心路历程 根据所给题目中大多数含有和涉及到硬件操作,鉴于本人分组只是一人一组,操作硬件起来会更加苦难,所以选择一个多为软件操作目:选题结果跟姜中希组相同,但保证只会在大体思路上回有所相同但不会出现代码上的冲突和相似. 5.8月29日任务完成

软件工程实训总结

转眼间实训已过去一段时间,之前的兴奋.喜悦如今已经让我熟悉,在实训的每一天都会让我有成为一名真正的财富者拥有的冲动.也许,在这期间不一定会让一个人有着翻天覆地的变化,但变化就是这样一点一点产生的.通过这一期的实训,虽然倍感折磨,但是收获却是很大的,学习中我不但有了学习成果的喜悦,而且自己也日渐成熟,有种说不出的喜悦. 在实训的过程中,我深深的体会到了自己在专业知识方面的欠缺和不足,也意识到了自己作为计算机软件专业的学生,要想在以后的职业中崭露头角,除了要有过硬的理论知识,健康的体魄之外,还必须具

专业实训9.5

1.实训时间:2016.9.5上午8:00-11:30 2.实训内容:项目在完成.x文件的固定导入后,尝试文件旋转,缩小,放大功能的开发. 3.具体实现:通过网上百度的源代码,进行阅读和修改. 具体为摄像头的处理. 阅读代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Lin

深圳软件培训-软件开发培训-汇道IT实训

"汇道"软件培训共开设16门课程:ios开发,android开发,java培训,深圳美工培训,深圳UI设计培训,php培训...时间从每周周一开始,至周五结束,共计5次课,每周的周末进行深圳软件培训免费试听(周六和周日),一节课的时长约为3个小时. 深圳软件培训招生 一.学习专业: 软件开发(安卓系统andriod运行软件.苹果系统ios运行软件) 服务器端(java语言)运行软件的开发,主要是网站开发. 二.招生目标: 招生方向培训班采用汇道教育人才培训方案,使用"汇道IT

5.你所在的学校有计算机科学专业和软件工程专业么?相关专业的教学计划和毕业出路有什么不同?阅读有关软件工程和计算机科学的区别的文章,谈谈你的看法。

问题1:你所在的学校有计算机科学专业和软件工程专业么? 答:我所在的学校有计算机学院和软件学院,所以分别有计算机科学与技术专业和软件工程专业. 问题2:相关专业的教学计划有什么不同? 答:这两个专业的教学计划如下: 软件工程课程设置: 公共必修课:思想政治理论.英语.计算机基础.文化素质课程.体育等课程. 学科基础课:数据结构.C++面向对象高级程序设计.计算机组成原理.数字逻辑.软件人员英语沟通方法1(英).数据库原理1(双语).算法设计与分析(双语).操作系统原理1.软件工程概论(双语).计

软件学院2015级软件工程专业培养方案

软件学院2015级软件工程专业培养方案   一.培养目标 本专业培养拥护党的基本路线,德.智.体.美等方面全面发展,适应新世纪计算机软件技术发展,培养适应管理.服务一线需要,具有良好的综合素质,掌握计算机软件开发和软件工程的基本理论.基本知识和基本技能,掌握软件开发模式.流行软件开发工具以及软件外包开发规范,在企事业或机关等单位从事计算机软件系统开发.运行维护.软件测试等工作的高素质应用型专门人才. 本专业主要分软件服务工程方向.金融服务工程方向.网络系统运维外包方向.软件服务工程方向是要为社会