2017中山大学软件工程初级实训

3 篇文章 0 订阅
2 篇文章 0 订阅

这次,还是一样,初级实训需要完成一个Agenda系统,同样的,需求我们可以参考wiki
用户名与密码均为guest
简述:
1。 阶段一实现Date类,Meeting类,User类,Storage类。
2。 阶段二实现AgendaService类,简易的UI类。
3。 阶段三实现扩展内容

简述各阶段:
1。 阶段一:做Agenda的最底层,其中最应该注意的是Date类与Storage类,都有一定的坑。
2。 阶段二:做AgendaService类,这里就是各种边界值的考虑,UI类基本就是码字,没有什么难的。
3。 阶段三:这里就是发挥自己的想象力的时候,我是写shell脚本,用dialog工具做图形化界面,用txt文件作为shell脚本与c++中互相”通信”的跳板。并通过并行处理来做背景音乐的效果,播放音乐用的是sox,最后修改bashrc文件,来将Agenda作为系统命令。这里舍友想参加,我就让他写了一个系统信息的展示栏作为菜单选项。
由于阶段二还有一两个小bug,现在没有时间去处理,所以阶段二代码不展示。
阶段三做完,已经满分了,所以阶段二也没有修改。
话不多说,熟悉我的博客的人会知道。代码是主要组成部分。

相关代码,测试文件,脚本下载
传送门

//Date.hpp
#ifndef DATE_H
#define DATE_H

#include <initializer_list>
#include <string>

class Date {
 public:
  /**
  * @brief default constructor
  */
  Date();

  /**
  * @brief constructor with arguments
  */
  Date(int t_year, int t_month, int t_day, int t_hour, int t_minute);

  /**
  * @brief constructor with a string
  */
  Date(const std::string &dateString);
  /**
  * @brief return the year of a Date
  * @return   a integer indicate the year of a date
  */
  int getYear(void) const;

  /**
  * @brief set the year of a date
  * @param a integer indicate the new year of a date
  */
  void setYear(const int t_year);

  /**
  * @brief return the month of a Date
  * @return   a integer indicate the month of a date
  */
  int getMonth(void) const;

  /**
  * @brief set the month of a date
  * @param a integer indicate the new month of a date
  */
  void setMonth(const int t_month);

  /**
  * @brief return the day of a Date
  * @return   a integer indicate the day of a date
  */
  int getDay(void) const;

  /**
  * @brief set the day of a date
  * @param a integer indicate the new day of a date
  */
  void setDay(const int t_day);

  /**
  * @brief return the hour of a Date
  * @return   a integer indicate the hour of a date
  */
  int getHour(void) const;

  /**
  * @brief set the hour of a date
  * @param a integer indicate the new hour of a date
  */
  void setHour(const int t_hour);

  /**
  * @brief return the minute of a Date
  * @return   a integer indicate the minute of a date
  */
  int getMinute(void) const;

  /**
  * @brief set the minute of a date
  * @param a integer indicate the new minute of a date
  */
  void setMinute(const int t_minute);

  /**
  *   @brief check whether the date is valid or not
  *   @return the bool indicate valid or not
  */
  static bool isValid(const Date &t_date);

  /**
  * @brief convert a string to date, if the format is not correct return
  * 0000-00-00/00:00
  * @return a date
  */
  static Date stringToDate(const std::string &t_dateString);

  /**
  * @brief convert a date to string, if the date is invalid return
  * 0000-00-00/00:00
  */
  static std::string dateToString(const Date &t_date);

  /**
  *  @brief overload the assign operator
  */
  Date &operator=(const Date &t_date);

  /**
  * @brief check whether the CurrentDate is equal to the t_date
  */
  bool operator==(const Date &t_date) const;

  /**
  * @brief check whether the CurrentDate is  greater than the t_date
  */
  bool operator>(const Date &t_date) const;

  /**
  * @brief check whether the CurrentDate is  less than the t_date
  */
  bool operator<(const Date &t_date) const;

  /**
  * @brief check whether the CurrentDate is  greater or equal than the t_date
  */
  bool operator>=(const Date &t_date) const;

  /**
  * @brief check whether the CurrentDate is  less than or equal to the t_date
  */
  bool operator<=(const Date &t_date) const;

 private:
  int m_year;
  int m_month;
  int m_day;
  int m_hour;
  int m_minute;
};

#endif
//Date.cpp
#include<iostream>
#include"Date.hpp"
#include<math.h>
#include<string>
#include<vector>
using namespace std;
bool isLeap(int testYear){
  if(testYear % 4 == 0 && testYear % 100 != 0)
     return true;
  if(testYear % 400 == 0)
     return true;
  return false;
}
void push_str_int(string& str , int num){
  int temp = num ;
  if(num == 0)
  {
    str.push_back('0');
  }
  vector<int> v;
  while(temp != 0){
    int doc = temp % 10;
    v.push_back(doc);
    temp /= 10;
  }
  int len = v.size();
  for(int index = 0 ; index < len ; index++)
  {
    str.push_back('0' + v[len-1-index]);
  }
}
void initial(string& str , int num , int s){
  if(s == 4){
     int count = 3;
    while(pow(10,count--) > num)
      str.push_back('0');
     push_str_int(str,num);
  }
  if(s == 2){
    if(num < 10)
      str.push_back('0');
    push_str_int(str,num);
  }
}
int str_int(string& str){
    int len = str.size();
    int count = 0;
    for(int index = 0 ; index < len ; index++)
    {
      count += (str[index] - '0');
      if(index != len - 1)
         count *= 10;
    }
    return count;
}

bool valid(int y , int m , int d )
{
  if(y < 1000 || y > 9999)
  {  //cout<<y<<" "<<m<<" "<<d<<endl;
//  cout<<"wrong"<<endl;
  return false;}
  bool flag = isLeap(y);
  int array1[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
  int array2[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
  if(flag == false){
   if(m > 0 && m < 13 && d <= array1[m-1] && d > 0)
      return true;
   else
    {  
//    cout<<"wrong"<<endl;
    return false;}
  }
  else{
   if(m > 0 && m < 13 && d <= array2[m-1] && d > 0)
      return true;
   else
      return false;

  }
}
Date::Date(){
   m_year = 0;
   m_month = 0;
   m_day = 0;
   m_hour = 0;
   m_minute = 0;
}
Date::Date(int t_y, int t_mo , int t_d , int t_h , int t_mi)
{
   m_year = t_y;
   m_month = t_mo;
   m_day = t_d;
   m_hour = t_h;
   m_minute = t_mi;
}
bool valid_str(const string& str)
{
  int len = str.size();
   if(len != 16)
    return false;
  if(str[4] != '-')
    return false;
  if(str[7] != '-')
    return false;
  if(str[10] != '/')
    return false;
  if(str[13] != ':')
    return false;
//    cout<<"no"<<str<<endl;
  for(int index = 0 ; index < 4 ; index++)
  {
    if(str[index] < '0' || str[index] > '9')
    return false;
  }
 // cout<<"1no "<<str<<endl;
  for(int index = 5 ; index < 7 ; index++)
  {
    if(str[index] < '0' || str[index] > '9')
    return false;
  }
  //cout<<"2no "<<str<<endl;
  for(int index = 8 ; index < 10 ; index++)
  {
    if(str[index] < '0' || str[index] > '9')
    return false;
  }
  //cout<<"3no "<<str<<endl;
  for(int index = 11 ; index < 13 ; index++)
  {
    if(str[index] < '0' || str[index] > '9')
    return false;
  }
  //cout<<"4no "<<str<<endl;
  for(int index = 14 ; index < 16 ; index++)
  {
    if(str[index] < '0' || str[index] > '9')
    return false;
  }
//  cout<<"5no "<<str<<endl;
  return true;
}
Date::Date(const string& data){
   string str;
   if(valid_str(data) == false)
   {
      this->m_year = 0;
      this->m_month = 0;
      this->m_day = 0;
      this->m_hour = 0;
      this->m_minute = 0;

   }
   else{
   for(int index = 0 ; index < 4 ; index++)
     str.push_back(data[index]);
   m_year = str_int(str);
   str.clear();

   for(int index = 5 ; index <= 6 ; index++)
     str.push_back(data[index]);
   m_month = str_int(str);
   str.clear(); 

   for(int index = 8 ; index <= 9 ; index++)
     str.push_back(data[index]);
   m_day = str_int(str);
   str.clear();

   for(int index = 11 ; index <= 12 ; index++)
     str.push_back(data[index]);
   m_hour = str_int(str);
   str.clear();

   for(int index = 14 ; index <= 15 ; index++)
     str.push_back(data[index]);
   m_minute = str_int(str);
   str.clear();
}
}

int Date::getYear(void) const
{
  return m_year;
}

void Date::setYear(const int t_y){
  m_year = t_y;
}

int Date::getMonth(void) const
{
  return m_month;
}

void Date::setMonth(const int t_m)
{
  m_month = t_m;
}

int Date::getDay(void) const
{
  return m_day;
}

void Date::setDay(const int t_d)
{
  m_day = t_d;
}

int Date::getHour(void) const
{
  return m_hour;
}

void Date::setHour(const int t_h)
{
  m_hour = t_h;
}

int Date::getMinute(void) const
{
  return m_minute;
}

void Date::setMinute(const int t_m)
{
  m_minute = t_m;
}


bool Date::isValid(const Date& test)
{
  bool flag1 = valid(test.m_year , test.m_month, test.m_day);
  if(flag1 == false)
    {
//    cout<<"year wronf"<<endl;
    return false;}
  if(test.m_hour < 0 || test.m_hour >= 24 )
    return false;
  if(test.m_minute < 0 || test.m_minute >= 60)
    return false;
  return true;
}

Date Date::stringToDate(const string& str)
{ bool flag = valid_str(str);
  if(flag == false)
  {
//    string ptr = "0000-00-00/00:00";
    Date temp(0,0,0,0,0);
    return temp;
  }
  Date temp(str);
  return temp;
}

string Date::dateToString(const Date& data)
{ if(data.isValid(data) ==false)
  {
    string str = "0000-00-00/00:00";
    return str;
  }
  string str;
  initial(str,data.m_year,4);
  str.push_back('-');
  initial(str,data.m_month,2);
  str.push_back('-');
  initial(str,data.m_day,2);
  str.push_back('/');
  initial(str,data.m_hour,2);
  str.push_back(':');
  initial(str,data.m_minute,2);
  return str;
}

Date& Date::operator=(const Date &other)
{
  m_year = other.m_year;
  m_month = other.m_month;
  m_day = other.m_day;
  m_hour = other.m_hour;
  m_minute = other.m_minute;
  return *this;
}

bool Date::operator==(const Date& other) const
{
  if(m_year != other.m_year || m_month != other.m_month)  
    return false;
  if(m_day != other.m_day || m_hour != other.m_hour)  
    return false;
  if(m_minute != other.m_minute)  
    return false;
  return true;
}
bool Date::operator<(const Date& other) const
{
  if(m_year < other.m_year)
    return true;
  if(m_year > other.m_year)
    return false;

  if(m_month < other.m_month)
    return true;
  if(m_month > other.m_month)
    return false;

  if(m_day < other.m_day)  
    return true;
  if(m_day > other.m_day)
    return false;

  if(m_hour < other.m_hour)  
    return true;
  if(m_hour > other.m_hour)  
    return false;

  if(m_minute < other.m_minute)  
    return true;
  return false;
}

bool Date::operator>(const Date& other) const
{
  bool flag1 = (*this == other);
  bool flag2 = (*this < other);
  if(flag1 == false && flag2 == false)
    return true;
  return false;
}

bool Date::operator>=(const Date& other) const
{
  bool flag1 = (*this < other);
  if(flag1 == false) 
    return true;
  return false;
}

bool Date::operator<=(const Date& other) const
{
  bool flag1 = (*this > other);
  if(flag1 == false)  
    return true;
  return false;
}























//User.hpp
#ifndef USER_H
#define USER_H

#include <initializer_list>
#include <string>
class User {
 public:
  /**
  * @brief the default constructor
  */
  User() = default;

  /**
  * constructor with arguments
  */
  User(const std::string &t_userName, const std::string &t_userPassword,
       const std::string &t_userEmail, const std::string &t_userPhone);

  /**
  * @brief copy constructor
  */
  User(const User &t_user);

  /**
  * @brief get the name of the user
  * @return   return a string indicate the name of the user
  */
  std::string getName() const;

  /**
  * @brief set the name of the user
  * @param   a string indicate the new name of the user
  */
  void setName(const std::string &t_name);

  /**
  * @brief get the password of the user
  * @return   return a string indicate the password of the user
  */
  std::string getPassword() const;

  /**
  * @brief set the password of the user
  * @param   a string indicate the new password of the user
  */
  void setPassword(const std::string &t_password);

  /**
  * @brief get the email of the user
  * @return   return a string indicate the email of the user
  */
  std::string getEmail() const;

  /**
  * @brief set the email of the user
  * @param   a string indicate the new email of the user
  */
  void setEmail(const std::string &t_email);

  /**
  * @brief get the phone of the user
  * @return   return a string indicate the phone of the user
  */
  std::string getPhone() const;

  /**
  * @brief set the phone of the user
  * @param   a string indicate the new phone of the user
  */
  void setPhone(const std::string &t_phone);

 private:
  std::string m_name;
  std::string m_password;
  std::string m_email;
  std::string m_phone;
};

#endif
//User.cpp
#include"User.hpp"
//#include"Date.hpp"
#include<iostream>
#include<string>
using namespace std;

User::User(const string& t_name , const string& t_pass , const string& t_e, const string& t_p )
{
  m_name = t_name;
  m_password = t_pass;
  m_email = t_e;
  m_phone = t_p;
}

User::User(const User& other)
{
  m_name = other.m_name;
  m_password = other.m_password;
  m_email = other.m_email;
  m_phone = other.m_phone;
}

string User::getName() const
{
  return m_name;
}
void User::setName(const string& str)
{ 
  m_name = str;
}

string User::getPassword() const
{
  return m_password;
}

void User::setPassword(const string& str)
{
  m_password = str;
}

string User::getEmail() const
{
  return m_email;
}

void User::setEmail(const string& str)
{
  m_email = str;
}

string User::getPhone() const
{
  return m_phone;
}

void User::setPhone(const string& str)
{
  m_phone = str;
}
//Meeting.hpp
#ifndef MEETING_H
#define MEETING_H

#include <vector>
#include "Date.hpp"

class Meeting {
 public:
  /**
  * @brief default constructor
  */
  Meeting() = default;

  /**
  *   @brief constructor with argument
  */
  Meeting(const std::string &t_sponsor,
          const std::vector<std::string> &t_participator,
          const Date &t_startTime, const Date &t_endTime,
          const std::string &t_title);

  /**
  * @brief copy constructor of left value
  */
  Meeting(const Meeting &t_meeting);

  /**
  *   @brief get the meeting's sponsor
  *   @return a string indicate sponsor
  */
  std::string getSponsor(void) const;

  /**
  * @brief set the sponsor of a meeting
  * @param  the new sponsor string
  */
  void setSponsor(const std::string &t_sponsor);

  /**
  * @brief  get the participators of a meeting
  * @return return a string vector indicate participators
  */
  std::vector<std::string> getParticipator(void) const;

  /**
  *   @brief set the new participators of a meeting
  *   @param the new participators vector
  */
  void setParticipator(const std::vector<std::string> &t_participators);

  /**
  * @brief add a new participator to the meeting
  * @param the new participator
  */
  void addParticipator(const std::string &t_participator);

  /**
  * @brief remove a participator of the meeting
  * @param the participator to be removed
  */
  void removeParticipator(const std::string &t_participator);

  /**
  * @brief get the startDate of a meeting
  * @return return a string indicate startDate
  */
  Date getStartDate(void) const;

  /**
  * @brief  set the startDate of a meeting
  * @param  the new startdate of a meeting
  */
  void setStartDate(const Date &t_startTime);

  /**
  * @brief get the endDate of a meeting
  * @return a date indicate the endDate
  */
  Date getEndDate(void) const;

  /**
  * @brief  set the endDate of a meeting
  * @param  the new enddate of a meeting
  */
  void setEndDate(const Date &t_endTime);

  /**
  * @brief get the title of a meeting
  * @return a date title the endDate
  */
  std::string getTitle(void) const;

  /**
  * @brief  set the title of a meeting
  * @param  the new title of a meeting
  */
  void setTitle(const std::string &t_title);

  /**
  * @brief check if the user take part in this meeting
  * @param t_username the source username
  * @return if the user take part in this meeting
  */
  bool isParticipator(const std::string &t_username) const;

 private:
  std::string m_sponsor;
  std::vector<std::string> m_participators;
  Date m_startDate;
  Date m_endDate;
  std::string m_title;
};

#endif
//Meeting.cpp
#include"Meeting.hpp"
#include<iostream>
#include<string>
#include<vector>
using namespace std;
Meeting::Meeting(const string& t_sp , const vector<string>& t_p ,const Date& t_st, const Date& t_e, const string& t_t)
{
   m_sponsor = t_sp;
   int len = t_p.size();
   for(int index = 0 ; index < len ; index++)
     m_participators.push_back(t_p[index]);
   m_startDate = t_st;
   m_endDate = t_e;
   m_title = t_t;
}

Meeting::Meeting(const Meeting& t_m)
{
   m_sponsor = t_m.m_sponsor;
   int len = t_m.m_participators.size();
   for(int index = 0 ; index < len ; index++)
      m_participators.push_back(t_m.m_participators[index]);
   m_startDate = t_m.m_startDate;
   m_endDate = t_m.m_endDate;
   m_title = t_m.m_title;
}

string Meeting::getSponsor(void) const
{
  return m_sponsor;
}
void Meeting::setSponsor(const string& str)
{
  m_sponsor = str;
}
vector<string> Meeting::getParticipator(void) const
{
//  vector<string> str;
  //int len = m_participators.size();
  //for(int index = 0 ; index < len ; index++)
    // str.push_back(m_participators[index]);
  //return str;
  return m_participators;
}
void Meeting::setParticipator(const std::vector<std::string> &t_pa)
{
   m_participators.clear();
  int len = t_pa.size();
  for(int index = 0 ; index < len ; index++)
    m_participators.push_back(t_pa[index]);
}
void Meeting::addParticipator(const string& str)
{
  m_participators.push_back(str);
}

void Meeting::removeParticipator(const string& str)
{
  vector<string>::iterator it, itor;
  for(it = m_participators.begin() ; it != m_participators.end();)
  {
    if(*it == str)
    {
     itor = it;
     it = m_participators.erase(itor);
    }
    else
      it++;
  }
}

Date Meeting::getStartDate(void) const
{
   return m_startDate;
}

void Meeting::setStartDate(const Date& str)
{
   m_startDate = str;
}

Date Meeting::getEndDate(void) const
{
  return m_endDate;
}

void Meeting::setEndDate(const Date& str) 
{
  m_endDate = str;
}


string Meeting::getTitle(void) const
{
  return m_title;
}

void Meeting::setTitle(const string& str)
{
  m_title = str;
}

bool Meeting::isParticipator(const string& str) const
{
  int len = m_participators.size();
  for(int index = 0 ; index < len ; index++)
   {
     if(m_participators[index] == str)
       return true;
   }
  return false;
}

























//Storage.hpp
#ifndef AGENDA_STORAGE_H
#define AGENDA_STORAGE_H

#include <functional>
#include <list>
#include <memory>
#include <string>
#include "Meeting.hpp"
#include "User.hpp"

class Storage {
 private:
  /**
  *   default constructor
  */
  Storage();

  /**
  *   disallow the copy constructor and assign operator
  */
  Storage(const Storage &t_another) = delete;
  void operator=(const Storage &t_another) = delete;

  /**
  *   read file content into memory
  *   @return if success, true will be returned
  */
  bool readFromFile(void);

  /**
  *   write file content from memory
  *   @return if success, true will be returned
  */
  bool writeToFile(void);

 public:
  /**
  * get Instance of storage
  * @return the pointer of the instance
  */
  static std::shared_ptr<Storage> getInstance(void);

  /**
  *   destructor
  */
  ~Storage();

  // CRUD for User & Meeting
  // using C++11 Function Template and Lambda Expressions

  /**
  * create a user
  * @param a user object
  */
  void createUser(const User &t_user);

  /**
  * query users
  * @param a lambda function as the filter
  * @return a list of fitted users
  */
  std::list<User> queryUser(std::function<bool(const User &)> filter) const;

  /**
  * update users
  * @param a lambda function as the filter
  * @param a lambda function as the method to update the user
  * @return the number of updated users
  */
  int updateUser(std::function<bool(const User &)> filter,
                 std::function<void(User &)> switcher);

  /**
  * delete users
  * @param a lambda function as the filter
  * @return the number of deleted users
  */
  int deleteUser(std::function<bool(const User &)> filter);

  /**
  * create a meeting
  * @param a meeting object
  */
  void createMeeting(const Meeting &t_meeting);

  /**
  * query meetings
  * @param a lambda function as the filter
  * @return a list of fitted meetings
  */
  std::list<Meeting> queryMeeting(
      std::function<bool(const Meeting &)> filter) const;

  /**
  * update meetings
  * @param a lambda function as the filter
  * @param a lambda function as the method to update the meeting
  * @return the number of updated meetings
  */
  int updateMeeting(std::function<bool(const Meeting &)> filter,
                    std::function<void(Meeting &)> switcher);

  /**
  * delete meetings
  * @param a lambda function as the filter
  * @return the number of deleted meetings
  */
  int deleteMeeting(std::function<bool(const Meeting &)> filter);

  /**
  * sync with the file
  */
  bool sync(void);

 private:
  static std::shared_ptr<Storage> m_instance;
  std::list<User> m_userList;
  std::list<Meeting> m_meetingList;
  bool m_dirty;
};

#endif
//Storage.cpp
#include"Path.hpp"
#include"User.hpp"
#include"Meeting.hpp"
#include"Date.hpp"
#include"Storage.hpp"
#include<functional>
#include<string>
#include<iostream>
#include<list>
#include<fstream>
#include<memory>
#include<vector>
#include<functional>
using namespace std;
#define SIGNAL1
#define P
shared_ptr<Storage> Storage::m_instance = nullptr;
//int
Storage::Storage()
{ 
 // if(m_instance == nullptr)
   // m_instance(new Storage);
  m_dirty = false;
  readFromFile();
}

bool Storage::readFromFile(void) 
{
  ifstream fout(Path::meetingPath);
  ifstream foutu(Path::userPath);
  if(fout.is_open() == false)
   {
//    cout<<"wrong"<<endl;
   return false;}
  if(foutu.is_open() == false) 
    {
  //  cout<<"wrong"<<endl;
    return false;}
  string name;
  string pass;
  string mail;
  string phone;
  char ch;
//  int dc = 0;
  //while(!foutu.eof())
    while(1)
  {
/*    foutu>>ch;

    getline(foutu,name,'"');
    foutu>>ch;

    foutu>>ch;

    getline(foutu,pass,'"');
    foutu>>ch;

    foutu>>ch;

    getline(foutu,mail,'"');
    foutu>>ch;

    foutu>>ch;

    getline(foutu,phone,'"');

    foutu>>ch;

    if(!foutu.eof())
      foutu>>ch;
    User u(name,pass,mail,phone);
    m_userList.push_back(u);
    //cout<<dc++<<endl;
  */
  string str;
  getline(foutu,str);
  //cout<<str<<endl;
  vector<int> sign;
  int len = str.size();
  for(int index = 0; index < len ; index++)
  {
    if(str[index] == '"')
    sign.push_back(index);
  }
  if(sign.size() != 8)
    break;
   string name;
   string pass;
   string email;
   string phone;

   for(int index = sign[0]+1 ; index < sign[1] ; index++)
    name.push_back(str[index]);
   for(int index = sign[2]+1 ; index < sign[3] ; index++)
    pass.push_back(str[index]);
   for(int index = sign[4]+1 ; index < sign[5] ; index++)
    email.push_back(str[index]);
   for(int index = sign[6]+1 ; index < sign[7] ; index++)
    phone.push_back(str[index]);
  User u(name,pass,email,phone);
  m_userList.push_back(u);


  }
  //cout<<"break"<<endl;
  foutu.close();

  string spon;
  string temp_v;
  vector<string> v;
  string start;
  string end;
  string title;
  //while(!fout.eof())
  while(1)
  {
    /*fout>>ch;

    getline(fout,spon,'"');
    foutu>>ch;
    foutu>>ch;
    getline(fout,temp_v,'"');
    foutu>>ch;
    foutu>>ch;
    getline(fout,start,'"');
    foutu>>ch;
    foutu>>ch;
    getline(fout,end,'"');
    foutu>>ch;
    foutu>>ch;
    getline(fout,title,'"');
    vector<int> data;
    int len = temp_v.size();
    for(int index = 0 ; index < len ; index++ )
       if(temp_v[index] == '&')
         data.push_back(index);
    int leng = data.size()+1;
    for(int index = 0 ; index < leng ; index++ )
    {
      if(index == 0)
      {
      string str;
        for(int jndex = 0 ;jndex <= temp_v[index]-1; jndex++)
   str.push_back(temp_v[jndex]);
      v.push_back(str);
      continue;
      }
      if(index == leng - 1)
      { string str;
        for(int jndex = data[leng-2]+1 ; jndex < len ; jndex++)
   str.push_back(temp_v[jndex]);
 v.push_back(str);
 continue;


      }
      string str;
       for(int jndex = data[index-1]+1 ; jndex < data[index]; jndex++)
      str.push_back(temp_v[jndex]);
      v.push_back(str);

    }
    Date s(start), e(end);
    Meeting m(spon,v,s,e,title);
    m_meetingList.push_back(m);
    if(!fout.eof())
      fout>>ch;
    */
    vector<int> sign;
    vector<int> sep;
    //vector<int> par;
    string str;
    getline(fout,str);
    //cout<<str<<endl;
    vector<string> par;
    string spon;
    string startDate;
    string endDate;
    string title;
    int len = str.size();
    if(len<=2) break;
    //if(sign.size() != 10)
      //break;
    for(int index = 0 ; index < len ; index++)
    {
      if(str[index] == '"')
        sign.push_back(index);
      if(str[index] == '&')
        sep.push_back(index);
    }
    if(sign.size() < 2)
    break;
    for(int index = sign[0]+1 ; index < sign[1] ; index++)
      spon.push_back(str[index]);
    for(int index = sign[4]+1 ; index < sign[5] ; index++)
      startDate.push_back(str[index]);
    for(int index = sign[6]+1 ; index < sign[7] ; index++)
      endDate.push_back(str[index]);
    for(int index = sign[8]+1 ; index < sign[9] ; index++)
      title.push_back(str[index]);
    len = sep.size()+1;
    if(len != 1){
    for(int index = 0 ; index < len ; index++)
    {
      if(index == 0)
      {
        string ptr;
        for(int jndex = sign[2]+1 ; jndex < sep[index]; jndex++)
          ptr.push_back(str[jndex]);
        par.push_back(ptr);
        continue;
      }
      if(index == len - 1)
      {
        string ptr;
        for(int jndex = sep[index-1]+1 ; jndex < sign[3] ; jndex++)
          ptr.push_back(str[jndex]);
        par.push_back(ptr);
        continue;
      }
      string ptr;
      for(int jndex = sep[index-1]+1 ; jndex < sep[index] ; jndex++)
        ptr.push_back(str[jndex]);
      par.push_back(ptr);

    }}
    else
    {
       string htr;
       for(int jndex = sign[2]+1 ; jndex < sign[3] ; jndex++)
          htr.push_back(str[jndex]);
        par.push_back(htr);
    }
    Date b(startDate);
    Date e(endDate);
    Meeting m(spon,par,b,e,title);
    m_meetingList.push_back(m);
  }
  fout.close();
  return true;
}

bool Storage::writeToFile(void) 
{ // m_dirty = false;  

    m_dirty = false;
   fstream foutu(Path::userPath,ios::out);
   fstream fout(Path::meetingPath,ios::out);
  if(!fout.is_open())
{    
  // cout<<"wrong"<<endl;
return false;}
   if(!foutu.is_open())
 {
 // cout<<"fun"<<endl;
 return false;}
   int len1 = m_userList.size();
   int len2 = m_meetingList.size();
   //cout<<len1<<endl<<len2<<endl;
   if(len1 == 0 && len2 == 0)
       return false;

   //cout<<len1<<endl;
   auto it = m_userList.begin();
   //int count = 0;
   for(it ; it != m_userList.end(); it++)
   {
    //cout<<count++<<endl;
    foutu<<"\""<<(*it).getName()<<"\""<<','<<"\""<<(*it).getPassword()<<"\"";
    foutu<<','<<"\""<<(*it).getEmail()<<"\""<<','<<"\""<<(*it).getPhone()<<"\"";
  //  foutu<<"yes"<<endl;
  //  cout<<'"'<<(*it).getName()<<'"'<<','<<'"'<<(*it).getPassword()<<'"';
   // cout<<','<<(*it).getEmail()<<'"'<<','<<'"'<<(*it).getPhone()<<'"';
    auto itor = it;
    itor++;
    if(itor != m_userList.end())
      foutu<<"\n";
   }
   foutu.close();
   auto ft = m_meetingList.begin();
   for(ft; ft != m_meetingList.end() ; ft++)  
     {
       fout<<'"'<<(*ft).getSponsor()<<'"'<<','<<'"';
       vector<string> lenn = (*ft).getParticipator();
       int len = lenn.size();
       for(int index = 0 ; index < len ; index++)
       {
         fout<<lenn[index];
  if(index != len-1)
  fout<<'&';
       }
       fout<<'"'<<',';
       fout<<'"'<<(*ft).getStartDate().dateToString((*ft).getStartDate())<<'"';
       fout<<','<<'"'<<(*ft).getEndDate().dateToString((*ft).getEndDate())<<'"'<<','<<'"'<<(*ft).getTitle()<<'"';
       auto ftor = ft;
       ftor++;
       if(ftor != m_meetingList.end())
         fout<<"\n";
     }
     fout.close();
     return true;
}
shared_ptr<Storage> Storage::getInstance(void) 
{    if(m_instance == nullptr)
        m_instance =  shared_ptr<Storage> (new Storage());
     //cout<<"fun"<<endl;
     return m_instance;
}
Storage::~Storage()
{
     sync();
}

void Storage::createUser(const User& other)
{
    m_userList.push_back(other);
   // auto it = m_userList.begin();
    //for(it ; it != m_userList.end() ; it++)
    //{
      //cout<<it->getName()<<" "<<it->getPassword()<<" "<<it->getPhone()<<" "<<it->getEmail()<<endl;
    //}
    m_dirty = true;
}
list<User> Storage::queryUser(std::function<bool(const User &)> filter) const
{   list<User> v;
    auto itor = m_userList.begin();
    for(itor;itor!= m_userList.end() ; itor++)
    {
      if(filter(*itor))
        v.push_back(*itor);
    }
    return v;
}
int Storage::updateUser(function<bool (const User &)> filter, function<void(User &)> switcher)
{  int count = 0;
   auto itor = m_userList.begin();
   for(itor ; itor != m_userList.end() ; itor++)  
     {
       if(filter(*itor))
       {
         switcher(*itor);
  count++;
       }
     }
     if(count != 0)
     m_dirty = true;
   return count;
}

int Storage::deleteUser(function<bool(const User &)> filter)
{
  auto itor = m_userList.begin();
  int count = 0;
  for(itor;itor != m_userList.end() ; )
  {
    if(filter(*itor))  
    {
     auto it = itor;
     itor = m_userList.erase(it);
     count++;
     continue;
    }
    itor++;
  }
  if(count != 0)
  m_dirty = true;
  return count;
}

list<Meeting> Storage::queryMeeting(function<bool(const Meeting&)> filter) const
{
  list<Meeting> m;
  auto itor = m_meetingList.begin();
  for(itor ; itor != m_meetingList.end(); itor++)
  {
    if(filter(*itor))
      m.push_back(*itor);
  }
  return m;
}
int Storage::updateMeeting(function<bool (const Meeting&)> filter, function<void(Meeting&)> switcher)
{
  int count = 0;
  auto itor = m_meetingList.begin();
  for(itor;itor != m_meetingList.end(); itor++)
    {
      if(filter(*itor))
      {
        switcher(*itor);
 count++;
      }
    }
    if(count != 0)
    m_dirty = true;
  return count;
}
void Storage::createMeeting(const Meeting& t_m)
{
    m_meetingList.push_back(t_m);
    m_dirty=true;
}
int Storage::deleteMeeting(function<bool(const Meeting&)> filter)
{
    int count = 0;
    auto itor = m_meetingList.begin();
    for(itor;itor!= m_meetingList.end(); )
    {
       if(filter(*itor))
       {
        count++;
        auto it = itor;
        //it++;
        itor = m_meetingList.erase(it);
        continue;
       }
       itor++;
    }
    if(count != 0)
    m_dirty = true;
    return count;
}
bool Storage::sync()
{ //  cout<<boolalpha<<m_dirty<<endl;
    if(m_dirty == false) return false;
    if(m_dirty == true)
    {

      bool flag1 = writeToFile();
      if(flag1 == false)
        return false;
    }
    //m_dirty = false; 
    return true;
}















阶段三:
1。 辅助c++文件

//addParticipator.cpp
#include<iostream>
#include<fstream>
#include<string>
#include"AgendaService.hpp"
using namespace std;

int main()
{
  fstream in("addParticipator.txt");
  string str1 , str2 , str3;
  in>>str1>>str2>>str3;
  in.close();
  AgendaService now;
  now.addMeetingParticipator(str1,str2,str3);
  return 0;
}
//clearText.cpp
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
  fstream in("secure.txt",ios::out);

      in<<"";
        in.close();
    }

//createMeeting.cpp
#include<iostream>
#include<fstream>
#include"AgendaService.hpp"
#include<vector>
#include<string>
using namespace std;
int main()
{
  AgendaService now;
  fstream in1("createMeeting1.txt");
  fstream in2("createMeeting2.txt");
  string str1 , str2 , str3 , str4;
  in1>>str1>>str2>>str3>>str4;
  vector<string> v;
  int num;
  in2>>num;
  string str;
  cout<<num<<endl;  
  while(num--)
  {
    in2>>str;
    cout<<str<<endl;
    v.push_back(str);
  }
  now.createMeeting(str1,str4,str2,str3,v);
  in1.close();
  in2.close();
  return 0;
}
//deleteMeeting.cpp
#include<iostream>
#include<fstream>
#include<string>
#include"AgendaService.hpp"
using namespace std;

int main()
{
  fstream in("deleteMeeting.txt");
  string str1 , str2;
  in>>str1>>str2;
  AgendaService now;
  now.deleteMeeting(str1,str2);
  in.close();
  return 0;
}
//deleteParticipator.cpp
#include<iostream>
#include<fstream>
#include<string>
#include"AgendaService.hpp"
using namespace std;

int main()
{
  fstream in("deleteParticipator.txt");
  string str1 , str2 , str3;
  in>>str1>>str2>>str3;
  in.close();
  AgendaService now;
  now.removeMeetingParticipator(str1,str2,str3);
  return 0;
}

//login.cpp
#include<iostream>
#include<fstream>
#include<string>
#include"AgendaService.hpp"
using namespace std;

int main()
{
  fstream in("deleteParticipator.txt");
  string str1 , str2 , str3;
  in>>str1>>str2>>str3;
  in.close();
  AgendaService now;
  now.removeMeetingParticipator(str1,str2,str3);
  return 0;
}

//register.cpp
#include<fstream>
#include<iostream>
#include"AgendaService.hpp"
#include<string>
using namespace std;

int main()
{
  AgendaService now;
  string str1 , str2 , str3 , str4;

  fstream in("register.txt");
  fstream out("register1.txt",ios::out);
  if(!in)
  {
    in.close();
    out.close();
    return 0;
  }
  if(!out)
  {
    in.close();
    out.close();
    return 0;
  }
  in>>str1>>str2>>str3>>str4;
  bool flag = now.userRegister(str1,str2,str3,str4);
  if(flag == true)
    out<<"true";
  else
    out<<"false";
  in.close();
  out.close();
}

2。 正式脚本内容

//mmh 作为主要引导
#!/bin/bash
gnome-terminal  --maximize -x bash -c -t "cd data ; play *mp3" &
wait
gnome-terminal  --maximize -x bash -c "cd data ; /bin/bash sh" &

//sh 作为整个系统的对外主体  
#!/bin/bash
dialog --title "welcome" --msgbox " welcome to the Agenda System \n created by the Ralph Haides \n copyright 2017.06.21" 20 40
dialog --title "please check" --yesno "are you ready" 20 40
signal=$?
if [ $signal == 1 ]
then
    dialog --msgbox "sorry maybe we are not good enough" 20 40 
    exit 0
fi
for i in {1..100} ;do echo $i;done | dialog --title "installation " --gauge "loading" 10 30
#dialog --title "login" --inputbox " please enter the name and password \n with the form XXXX XXX "  20 40 2>login.txt
dialog  --title "login"  --form "information" 12 50 4  \
"name " 1  1 "" 1  20  20  0  \
"password" 2  1 "" 2  20  20  0  2>login.txt

./login.out
SIGNAL=`cat ~/data/login1.txt`
if [ $SIGNAL == "false" ]
then 
   dialog --msgbox "sorry , failed" 20 40
   dialog --msgbox "maybe you can register" 20 40
   dialog --title "register" --inputbox " please enter the name password email and phone \n with the form xX XX XX XX" 20 40 2>register.txt
   ./register.out
   SIGNAL1=`cat ~/data/register1.txt`
   while [ $SIGNAL1 == "false" ]
   do 
        dialog --msgbox "sorry failed" 20 40
    dialog --title "register" --inputbox " please enter the name password email and phone \n with the form xX XX XX XX" 20 40 2>register.txt
    ./register.out
        SIGNAL1=`cat ~/data/register1.txt`
   done
fi
dialog --msgbox "welcome to your space" 20 40
IN="1"
while [ $IN == "1" ]
do
    dialog --title "Pick a choice" --menu "Choose one" 20 50 15 1 "create meeting" 2 "delete meeting" 3 "add participator" 4 "remove participator" 5 "list meeting" 6 "list user" 7 "trick"   8 "administrator" 9 "information" 10 "quit" 2>menu.txt
    OPTION=`cat ~/data/menu.txt`
    case $OPTION in
      "1")

     dialog --title "create meeting" --form "information" 12 50 4  \
     "Sponsor: " 1  1 "" 1  20  20  0  \
     "begin date:" 2  1 "" 2  20  20  0  \
     "end date:" 3  1 "" 3  20  20  0  \
      "title:"    4   1 "" 4  20  20  0 2>createMeeting1.txt;
     dialog --title "create meeting" --inputbox "please enter the number of the participator then the name seperated by space " 20 40 2>createMeeting2.txt;
     ./createMeeting.out;
     dialog --msgbox "finished" 20 40

     ;;
      "2")
         dialog --title "delete meeting" --form "information" 12 50 4  \
     "sponsor " 1  1 "" 1  20  20  0  \
     "title" 2  1 "" 2  20  20  0  2>deleteMeeting.txt;
     ./deleteMeeting.out;
     dialog --msgbox "finished" 20 40
         ;;
      "3")
         dialog --title "add participator" --form "information" 12 50 4  \
     "sponsor " 1  1 "" 1  20  20  0  \
     "title" 2  1 "" 2  20  20  0  \
     "new participator" 3 1 "" 3 20 20 0 2>addParticipator.txt;
     ./addParticipator.out;
     dialog --msgbox "finished" 20 40

     ;;
      "4")
         dialog --title "remove participator" --form "information" 12 50 4  \
     "sponsor " 1  1 "" 1  20  20  0  \
     "title" 2  1 "" 2  20  20  0  \
     "delete participator" 3 1 "" 3 20 20 0 2>deleteParticipator.txt;
     ./deleteParticipator.out;
     dialog --msgbox "finished" 20 40

     ;;
      "13")
         play 1.mp3;
     dialog --msgbox "finished" 20 40
     ;;
      "6")
         dialog --textbox ~/data/users.csv 20 120
     ;;
      "7")
         ;;
      "5")
         dialog --textbox ~/data/meetings.csv 20 120
         ;;
      "10")
         IN="0"
     ;;
      "9")
         python3 test1.py
         ;;
      "7")
         dialog --msgbox "i am kidding" 20 40
         ;;
      "8")
         dialog --insecure --passwordbox "enter the password" 20 40 2>secure.txt
     PASS=`cat ~/data/secure.txt`
     while [ $PASS != "FUNGKYIA" ]
     do 
        dialog --msgbox "sorry you failed" 20 40; 
        dialog --insecure --passwordbox "enter the password again" 20 40 2>secure.txt;
        PASS=`cat ~/data/secure.txt`;
         done
     ./clearText.out
     dialog --textbox sh 100 200 
         ;;
      *)
        ;;
    esac
done
//test1.py python系统信息展示栏  
from tkinter import *
class SystemMessage:
    def __init__(self):
        window = Tk()
        window.title("SystemMessage")


        self.canvas = Canvas(window, width = 1366, height = 650, bg = "black")
        self.canvas.pack()
        self.logo1 = PhotoImage(file = "~/data/images.gif")
        self.color = "red"
        self.canvas.create_image(650, 300, image = self.logo1, tag = "logo")
        self.canvas.create_text(650, 100, text = "Ralph Haides", tags = "Mess", fill = self.color, font = "Times 75 bold underline")

        frame1 = Frame(window)
        frame1.pack()
        btLogo = Button(frame1, text = "LOGO", command = self.displayLogo, cursor = "circle", bg = "yellow")
        btMessage = Button(frame1, text = "MESSAGE", command = self.displayMess, cursor = "circle", bg = "purple")
        btIntro = Button(frame1, text = "INTRODUCTION", command = self.displayIntro, cursor = "circle", bg = "red")

        btLogo.grid(row = 1, column = 1)
        btMessage.grid(row = 1, column = 2)
        btIntro.grid(row = 1, column = 3)

        self.canvas.bind("<Button-1>", self.changeBlue)
        self.canvas.bind("<Button-3>", self.changeRed)

        window.mainloop()

    def displayLogo(self):
        self.canvas.delete("logo", "Mess", "Intro")
        self.canvas.create_image(650, 300, image = self.logo1, tags = "logo")
        self.canvas.create_text(650, 100, text = "Ralph Haides", tags = "Mess", fill = "red", font = "Times 75 bold underline")

    def displayMess(self):
        self.canvas.delete("logo", "Mess", "Intro")
        self.canvas.create_text(650, 300, text = "This is an Agenda system", tags = "Mess", fill = "red", font = "Times 75 bold underline")


    def displayIntro(self):
        self.canvas.delete("logo", "Mess", "Intro")
        self.canvas.create_text(650, 300, text = "It is created by \nMr.He and Mr.Huang", tags = "Intro", fill = "red", font = "Times 75 bold underline")

    def changeBlue(self, event):
        if self.color == "red":
            self.color = "blue"
        self.canvas.delete("Mess")
        self.canvas.create_text(650, 100, text = "Ralph Haides", tags = "Mess", fill = self.color, font = "Times 75 bold underline")

    def changeRed(self, event):
        if self.color == "blue":
            self.color = "red"
        self.canvas.delete("Mess")
        self.canvas.create_text(650, 100, text = "Ralph Haides", tags = "Mess", fill = self.color, font = "Times 75 bold underline")


SystemMessage()

之后将上传实训完整资料,cpp,hpp,脚本,测试文件。
地址
资料包

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CSDN是中国领先的技术社区和垂直门户网站,提供了丰富的IT技术资源和交流平台。中山大学2020考研是指在2020年中山大学的研究生招生考试。以下是有关CSDN中山大学2020考研的回答。 中山大学是一所位于广州市的著名综合性大学,拥有杰出的教学和研究实力。每年,中山大学都会组织研究生招生考试,吸引了全国各地的优秀学子前来报考。CSDN作为国内知名的IT技术社区,也为考研学子们提供了相关的学习资料、经验分享和讨论交流的平台。 在CSDN中山大学2020考研板块,你可以找到大量关于中山大学招生政策、专业介绍、历年真题、备考资料以及考研心得等信息。在这里,考研学子可以与其他考生进行交流和沟通,分享备考心得和应试经验,互相帮助和鼓励。同时,也可以得到在中山大学研究生阶段学习的经验和建议,了解研究生生活和科研环境。 在CSDN中山大学2020考研板块中,你可以获取到与中山大学2020考研相关的重要信息,比如招生计划、报名时间、考试科目、考试形式等内容。这些信息对于考生制定备考计划、选择研究方向和准备考试都非常有帮助。 总之,CSDN中山大学2020考研板块是一个为考研学子提供信息交流和资源共享的平台。通过在CSDN上参与讨论和获取相关信息,考研学子们可以更好地备考中山大学2020考研,提高自己的竞争力,实现自己的研究生梦想。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值