#include "Badminton.h"
#include "StringTool.h"
#include <iostream>
using namespace std;
bool BookItem::SetBookStr(string s)
{
vector<string> subs;
split(s, " ", subs);
if (SetClientID(subs[0]) && SetDateAndDay(subs[1]) && SetTime(subs[2], this->GetBookday())) {
if ((subs.size() == 4 && SetBookType("Book")) || SetBookType("Cancel")) {
this->bookstr = s;
return true;
}
}
return false;
}
bool BookItem::SetClientID(string s)
{
string prttn = "[[:alnum:]]+";
regex r(prttn);
if (regex_match(s, r)) {
this->clientID = s;
return true;
}
return false;
}
bool BookItem::SetDateAndDay(string s)
{
string prttn = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)";
regex r(prttn);
if (regex_match(s, r)) {
this->date = s;
this->day = this->CaculateWeekDay(stoi(s.substr(0, 4)), stoi(s.substr(5, 2)), stoi(s.substr(8, 2)));
return true;
}
return false;
}
bool BookItem::SetTime(string s,WEEKDAY day) {
string prttn = "(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}~(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}";
regex r(prttn);
if (regex_match(s, r)) {
TimeSpan tmp = TimeSpan(s);
switch (day)
{
case sat:
case sun:
if (tmp.st_h < 9 || tmp.st_h >= 22 || tmp.ed_h <= 9 || tmp.ed_h >22 || tmp.st_h >= tmp.ed_h || tmp.ed_m != 0 || tmp.st_m != 0) return false;
this->timespan = tmp;
this->time = s;
return true;
case mon:
case tue:
case wed:
case thu:
case fri:
if (tmp.st_h < 9 || tmp.st_h >= 22 || tmp.ed_h <= 9 || tmp.ed_h >22 || tmp.st_h >= tmp.ed_h || tmp.ed_m != 0 || tmp.st_m != 0) return false;
this->timespan = tmp;
this->time = s;
return true;
}
}
return false;
}
bool BookItem::SetBookType(string s) {
this->bookOrcancel = s;
return true;
}
void BookItem::UpdateIncome(){
int st_h = this->GetBookStime().first;
int ed_h = this->GetBookEtime().first;
switch (this->GetBookday()) {
case sat:
case sun:
if (ed_h <= 12) this->income = (ed_h - st_h) * 40;
else if (st_h <12 && ed_h <= 18) this->income = (12 - st_h) * 40 + (ed_h - 12) * 50;
else if (st_h <12 && ed_h >18) this->income = (12 - st_h) * 40 + 300 + (ed_h - 18) * 60;
else if (st_h <18 && ed_h <= 18) this->income = (ed_h - st_h) * 50;
else if (st_h <18 && ed_h >18) this->income = (18 - st_h) * 50 + (ed_h - 18) * 60;
else this->income = (ed_h - st_h) * 60;
break;
case mon:
case tue:
case wed:
case thu:
case fri:
if (ed_h <= 12) this->income = (ed_h - st_h) * 30;
else if (st_h <12 && ed_h <= 18) this->income = (12 - st_h) * 30 + (ed_h - 12) * 50;
else if (st_h <12 && ed_h <= 20) this->income = (12 - st_h) * 30 + 300 + (ed_h - 18) * 80;
else if (st_h <12 && ed_h <= 22) this->income = (12 - st_h) * 30 + 460 + (ed_h - 20) * 60;
else if (st_h <18 && ed_h <= 18) this->income = (ed_h - st_h) * 50;
else if (st_h < 18 && ed_h <= 20) this->income = (18 - st_h) * 50 + (ed_h - 18) * 80;
else if (st_h < 18 && ed_h <= 22) this->income = (18 - st_h) * 50 + 160 + (22 - ed_h) * 80;
else if (st_h < 20 && ed_h <= 20) this->income = (ed_h - st_h) * 80;
else if (st_h < 20 && ed_h <= 22) this->income = (20 - st_h) * 80 + (ed_h - 20) * 60;
else this->income = (ed_h - st_h) * 60;
break;
}
if (this->GetBookType() == "Cancel") {
if(this->GetBookday()==WEEKDAY::sat || this->GetBookday()==WEEKDAY::sun)
this->income /= 4;
else
this->income /= 2;
}
}
WEEKDAY BookItem::CaculateWeekDay(int y, int m, int d)
{
if (m == 1 || m == 2) {
m += 12;
y--;
}
int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
WEEKDAY weekstr;
switch (week)
{
case 0: weekstr = mon; break;
case 1: weekstr = tue; break;
case 2: weekstr = wed; break;
case 3: weekstr = thu; break;
case 4: weekstr = fri; break;
case 5: weekstr = sat; break;
case 6: weekstr = sun; break;
}
return weekstr;
}
bool BadmintonCourt::SetBookInfo(string bookinfo) {
BookItem bkitm;
if (bkitm.SetBookStr(bookinfo))
{
//检查订单是否符合条件
if (bkitm.GetBookType() == "Book") {
bool again = false;
for (auto &itm : (this->bookinfo)[bkitm.GetBookDate()])
{
if (itm.GetBookType() == "Book")
{
if (!(bkitm.GetBookEtime().first <= itm.GetBookStime().first\
|| bkitm.GetBookStime().first >= itm.GetBookEtime().first))
{
cout << "Error: the booking conflicts with existing bookings!" << endl;
return false;
}
else
continue;
}
else
continue;
}
this->bookinfo[bkitm.GetBookDate()].push_back(bkitm);
return true;
}
else {
for (auto& itm : this->bookinfo[bkitm.GetBookDate()])
{
if (itm.GetBookType() == "Book") {
if (bkitm.GetclientID() == itm.GetclientID() && bkitm.GetBookTime() == itm.GetBookTime())
{
itm.SetBookType("Cancel");
return true;
}
else
continue;
}
}
cout << "Error: the booking being cancelled does not exist!" << endl;
return false;
}
}
cout << "Error: the booking is invalid!" << endl;
return false;
}
void BadmintonCourt::PrintIncome() {
for (auto &item : bookinfo) {
for (auto &item1 : item.second)
{
if (item1.GetBookType() == "Book")
cout << item1.GetBookDate() << " " << item1.GetBookTime() << " " << item1.GetIncome() << "元" << endl;
else
cout << item1.GetBookDate() << " " << item1.GetBookTime() << " 违约金 " << item1.GetIncome() << "元" << endl;
}
}
}
void BadmintonCourt::UpdateIncome() {
income = 0;
for (auto &item : bookinfo) {
for (auto &item1 : item.second)
{
item1.UpdateIncome();
if (item1.GetBookType() == "Book") {
double tmp = item1.GetIncome();
income += tmp;
}
else {
double tmp = item1.GetIncome();
income += tmp;
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
thoughtworks笔试作业
共55个文件
tlog:12个
obj:11个
cpp:5个
5星 · 超过95%的资源 需积分: 10 51 下载量 93 浏览量
2017-12-18
12:13:27
上传
评论 3
收藏 7.03MB RAR 举报
温馨提示
thoughtworks公司的笔试作业,用C++完成,用到了单例模式,工厂模式。
资源推荐
资源详情
资源评论
收起资源包目录
ThoughtWorks_hw.rar (55个子文件)
ThoughtWorks_hw
Debug
ThoughtWorks_hw.ilk 2.4MB
ThoughtWorks_hw.pdb 6.07MB
ThoughtWorks_hw.exe 428KB
README.html 18KB
.vs
ThoughtWorks_hw
v14
.suo 52KB
ThoughtWorks_hw.sln 1KB
ThoughtWorks_hw
Badminton.cpp 6KB
Debug
manager.obj.enc 1.82MB
vc140.pdb 1020KB
Data.obj 129KB
vc140.idb 739KB
Manager.obj 1.82MB
badminton.obj.enc 1.87MB
Badminton.obj 1.91MB
main.obj 263KB
main.obj.enc 259KB
ThoughtWorks_hw.tlog
CL.read.1.tlog 53KB
link.read.1.tlog 3KB
link.write.1.tlog 890B
CL.write.1.tlog 7KB
link.command.1.tlog 2KB
ThoughtWorks_hw.lastbuildstate 198B
CL.command.1.tlog 4KB
BadmintonCourt.obj 1.91MB
StringTool.obj 204KB
ThoughtWorks_hw.log 377B
ThoughtWorks_hw.vcxproj 8KB
Badminton.h 2KB
StringTool.h 162B
Data.cpp 244B
ThoughtWorks_hw.vcxproj.filters 2KB
main.cpp 827B
StringTool.cpp 423B
Release
vc140.pdb 804KB
Data.obj 1.2MB
Manager.obj 1.97MB
Badminton.obj 1.94MB
main.obj 1.33MB
ThoughtWorks_hw.tlog
CL.read.1.tlog 52KB
link.read.1.tlog 4KB
link.write.1.tlog 1KB
CL.write.1.tlog 2KB
link.command.1.tlog 2KB
ThoughtWorks_hw.lastbuildstate 200B
CL.command.1.tlog 3KB
StringTool.obj 970KB
ThoughtWorks_hw.log 419B
Manager.h 527B
Manager.cpp 2KB
Date.h 596B
Release
ThoughtWorks_hw.ipdb 410KB
ThoughtWorks_hw.pdb 1.43MB
ThoughtWorks_hw.exe 72KB
ThoughtWorks_hw.iobj 1.99MB
ThoughtWorks_hw.VC.db 9.58MB
共 55 条
- 1
资源评论
- 布衣小弟2019-08-06提供了一个思路
luoyanum
- 粉丝: 5
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- STM32单片机FPGA毕设电路原理论文报告汽车电动助力转向单片机控制系统设计与试验研究
- STM32单片机FPGA毕设电路原理论文报告气压传感器神经网络算法及单片机实现
- STM32单片机FPGA毕设电路原理论文报告频率的测量在单片机设计中的应用
- 音频转码工具(用于将微信语音 amr 格式转换为 mp3 格式以便在 html5 的 audio 标签中进行播放).zip
- RDK-Web-Performance-Node
- STM32单片机FPGA毕设电路原理论文报告片式电容器浪涌及老化测试系统的设计与实现
- 一个简易的贪吃蛇小游戏(C语言作业).zip
- 国家游戏防沉迷系统接口(php)
- STM32单片机FPGA毕设电路原理论文报告片剂硬度测试仪的液晶显示界面设计
- STM32单片机FPGA毕设电路原理论文报告偏磁式消弧线圈的动态调谐装置
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功