排气量

排气量:气缸工作容积是指活塞从上止点到下止点所扫过的气体容积,又称为单缸排量,它取决于缸径和活塞行程。发动机排量是各缸工作容积的总和,一般用于升 (l)来表示。发动机排量是最重要的结构参数之一,它比缸径和缸数更能代表发动机的大小,发动机的许多指标都同排气量密切相关。
应该是每分钟的排气量.
 
#include<iostream> #include<string> #include<time.h> #include<fstream> #include<list> using namespace std; #pragma warning(disable:4996) #define CAR_NUMBER 3 typedef struct node { string strCarCode; string strCarStyle; time_t t1, t2; bool bFull; }Node; class Park{ public: int nCount; Node arrCarLocation[CAR_NUMBER]; bool Full(); bool Empty(); Park(); }; bool Park::Full() { return nCount >=CAR_NUMBER ? true : false; } bool Park::Empty() { return nCount == 0 ? true : false; } Park::Park() { nCount = 0; for (int i=0;i<CAR_NUMBER;i++) { arrCarLocation[i].strCarCode=""; arrCarLocation[i].strCarStyle=""; arrCarLocation[i].bFull = false; arrCarLocation[i].t1 = 0; arrCarLocation[i].t2 = 0; } } class Automblie:public Pack { public: string strCarcode; string strCarStyle; Autblie(); virtual void Show()const; virtual void Pay()const; float TL()const; bool Enter(); bool Leave; } bool Automobile::Leave() { if (Empty()) { cout << "车位已空" << endl; cout << "返回请按任意键" << endl; return false; } else { cout << "请输入离开的车牌号: " << endl; cin >> strCarCode; for (int i = 0; i < CAR_NUMBER; i++) { if (strCarCode == arrCarLocation[i].strCarCode) // 找到离开的车了 { arrCarLocation[i].t2 = time(0); // 记录离开时间 char tmp[16]; strftime(tmp, sizeof(tmp), "%X", localtime(&arrCarLocation[i].t2)); cout << "离开时间: " << tmp << endl; cout << "离开车辆类型: " << arrCarLocation[i].strCarStyle << endl; cout << "离开车辆车牌: " << arrCarLocation[i].strCarCode << endl; arrCarLocation[i].strCarCode-; arrCarLocation[i].bFull = false; nCount--; return true; } } cout << "该车不在停车场中!!!" << endl; cout << "返回请按任意键" << endl; return false; } } float Automobile::TL() const { float f; for (int i = 0; i < CAR_NUMBER; i++) { if (arrCarLocation[i].strCarCode == strCarCode) // 找到要离开的车辆,通过车牌号 { // 系统参数,为方便显示结果在此利用秒来结算 f = arrCarLocation[i].t2 - arrCarLocation[i].t1; arrCarLocation[i].strCarCode = ""; arrCarLocation[i].strCarStyle = ""; arrCarLocation[i].bFull = false; arrCarLocation[i].t1 = 0; arrCarLocation[i].t2 = 0; cout << "总停车时间:" << f << endl; break; } } return f; } bool Automobile::Enter() { if (Full()) //判断车位是否停满 { cout << "车位已满,请等候" << endl; return false; } else { cout << "请输入车辆类型:" << endl; cin >> strCarStyle; cout << "请输入车牌号:" << endl; cin >> strCarCode; for (int i = 0; i < CAR_NUMBER; i++) { if (arrCarLocation[i].bFull == false) { arrCarLocation[i].strCarStyle = strCarStyle; arrCarLocation[i].strCarCode = strCarCode; arrCarLocation[i].bFull = true; arrCarLocation[i].t1 = time(0); nCount++; char tmp[16]; strftime(tmp, sizeof(tmp), "%X", localtime(&arrCarLocation[i].t1)); cout << "停车时间:" << tmp << endl; return true; } } } cout << "车位已满" << endl; return false; } void Automobile::Show() const { for (int i = 0; i < CAR_NUMBER; i++) { if (arrCarLocation[i].bFull == true) // 代表当前车位有车 { cout << "车辆类型:" << arrCarLocation[i].strCarStyle << endl; cout << "车辆车牌:" << arrCarLocation[i].strCarCode << endl; } } } class Truck:public Automblie { public: mutable float arrKio[CAR_NUMBER]; virtual void Show()const; virtual void Pay()const: Truck(); void Enter1(); }; Truck::Truck() { for (int i=0;i<CAR_NUMBER;i++) { arrKio[i]=0; } } void Truck::Pay()const { cout<<"收费:"<<TL()"元"<<endl; for(int i=0;i<CAR_NUMBER;i++) { if((arrCarLocation[i].bFull==false)&&(arrKio[i]!=0)) { cout<<"载重:"<<arrKio[i]<<"吨"<<endl; arrKio[i]=0; break; } } } void Truck::Show()const { for(int t=0;i<CAR_NUMBER;i++) { if (arrCarLocation[i].bFull==true) { cout<<"车辆类型:"<<arrCarLocation[i].strCarStyle<<endl; cout<<"车辆车牌:"<<arrCarLocation[i].strCarStyle<<endl; char tmp[16]; strftime(tmp,sizeof(tmp),"&X,localtime(&arrCarLocation[i].t1)); cout<<"停车时间:"<<tmp<<end1; cout<<"载重:"<arrKio[i]<<"吨"<<endl; } } } void Truck::Enter() { if (enter()) { cout<<"请输入载重:"<<endl; for (int i=0;i<CAR_NUMBER;i++) { arrKio[i]=0; cin>>arrKio[i]; break; } } } class Truck:public Automblie { public: mutable float arrKio[CAR_NUMBER]; virtual void Show()const; virtual void Pay()const: Truck(); void Enter1(); }; Truck::Truck() { for (int i=0;i<CAR_NUMBER;i++) { arrKio[i]=0; } } void Truck::Pay()const { cout<<"收费:"<<TL()"元"<<endl; for(int i=0;i<CAR_NUMBER;i++) { if((arrCarLocation[i].bFull==false)&&(arrKio[i]!=0)) { cout<<"载重:"<<arrKio[i]<<"吨"<<endl; arrKio[i]=0; break; } } } void Truck::Show()const { for(int t=0;i<CAR_NUMBER;i++) { if (arrCarLocation[i].bFull==true) { cout<<"车辆类型:"<<arrCarLocation[i].strCarStyle<<endl; cout<<"车辆车牌:"<<arrCarLocation[i].strCarStyle<<endl; char tmp[16]; strftime(tmp,sizeof(tmp),"&X,localtime(&arrCarLocation[i].t1)); cout<<"停车时间:"<<tmp<<end1; cout<<"载重:"<arrKio[i]<<"吨"<<endl; } } } void Truck::Enter() { if (enter()) { cout<<"请输入载重:"<<endl; for (int i=0;i<CAR_NUMBER;i++) { arrKio[i]=0; cin>>arrKio[i]; break; } } } //------------------------------客车类--------------------------------// // 特有属性:乘坐人数 class Carriage : public Automobile { public: mutable float arrNum[CAR_NUMBER]; // 乘坐人数 virtual void Show()const; virtual void Pay()const; Carriage(); void Enter1(); // 在父类的基础上输入乘坐人数 }; Carriage::Carriage() { for (int i = 0; i < CAR_NUMBER; i++) { arrNum[i] = 0; } } void Carriage::Pay()const { cout << "收费:" << TL() << "元" << endl; for (int i = 0; i < CAR_NUMBER; i++) { if ((arrCarLocation[i].bFull == false) && (arrNum[i]!= 0)) { cout << "人数:" << arrNum[i] << "位" << endl; arrNum[i] = 0; break; } } } void Carriage::Show()const { for (int i = 0; i < CAR_NUMBER; i++) { if (arrCarLocation[i].bFull == true) // 代表当前车位有车 { cout << "车辆类型:" << arrCarLocation[i].strCarStyle << endl; cout << "车辆车牌:" << arrCarLocation[i].strCarCode << endl; char tmp[16]; strftime(tmp, sizeof(tmp), "%X", localtime(&arrCarLocation[i].t1)); cout << "停车时间:" << tmp << endl; cout << "乘坐人数:" << arrNum[i] << "人" << endl; } } } void Carriage::Enter1() { if (Enter()) // 说明停车类型和车牌号已经存完了 { cout << "请输入乘坐人数:" << endl; for (int i = 0; i < CAR_NUMBER; i++) { if (arrNum[i] == 0) { cin >> arrNum[i]; break; } } } } //------------------------------轿车类--------------------------------// // 特有属性:排量 class Car : public Automobile { public: mutable float arrGas[CAR_NUMBER]; // 排气量 virtual void Show()const; virtual void Pay()const; Car(); void Enter1(); // 在父类的基础上输入排量 }; Car::Car() { for (int i = 0; i < CAR_NUMBER; i++) { arrGas[i] = 0; } } void Car::Pay()const { cout << "收费:" << TL() << "元" << endl; for (int i = 0; i < CAR_NUMBER; i++) { if ((arrCarLocation[i].bFull == false) && (arrGas[i]!= 0)) { cout << "排量:" << arrGas[i] << "L" << endl; arrGas[i] = 0; break; } } } void Car::Show() const { for (int i = 0; i < CAR_NUMBER; i++) { if (arrCarLocation[i].bFull == true) { cout << "车辆类型:" << arrCarLocation[i].strCarStyle << endl; cout << "车辆车牌:" << arrCarLocation[i].strCarCode << endl; char tmp[16]; strftime(tmp, sizeof(tmp), "%X", localtime(&arrCarLocation[i].t1)); cout << "停车时间:" << tmp << endl; cout << "排气量:" << arrGas[i] << "L" << endl; } } } void Car::Enter1() { if (Enter()) { cout << "请输入排气量:" << endl; for (int i = 0; i < CAR_NUMBER; i++) { if (arrGas[i] == 0) { cin >> arrGas[i]; break; } } } } int main() { Truck truck; Carriage carriage; Car car; int cKey1; char cKey2; char cKey3; fstream flie("park system,txt",ios::out); if(!file) { cerr<<"open error!!"<<endl; exit(1); } do { system("cls"); cout<<"请选择!"<<endl; cin>>cKey1; switch(cKey1) { case 1: system("cls"); cout<<"进入停车场"<<endl; cout<<"输入a----Truck"<<endl; cout<<"输入b--- Carriage"<<endl; cout<<"输入c---Car"<<endl; cout<<"输入n---返回上个界面"<<endl; cin>>cKey2; case 'a': system("cls"); if (truck.Leave()) truck.Pay(); cout << "按任意键返回" << endl; cin >> cKey3; break; case 'b': system("cls"); if (carriage.Leave()) carriage.Pay(); cout << "按任意键返回" << endl; cin >> cKey3; break; case 'c': system("cls"); if (car.Leave()) car.Pay(); cout << "按任意键返回" << endl; cin >> cKey3; break; case'n': break; default: break; } break; case 2: system("cls"); cout<<"跳转到停车场界面"<<endl; case 3: char cKey; do { system("cls"); if(truck.Empty()) cout<<"停车场暂无停车"<<endl; truck.Show(); car.Show(); cout<<"返回上一级请按n"<<endl; cin>>ckey; } case 4: system("cls"); // 清屏 for(int i=0; i<CAR_NUMBER; i++) { if (truck.arrCarLocation[i].strCarStyle == "a") { file<<"车辆类型:"<<truck.arrCarLocation[i].strCarStyle<<endl; file<<"车牌号:"<<truck.arrCarLocation[i].strCarCode<<endl; file<<"载重:"<<truck.arrKio[i]<<endl; char tmp[16]; strftime(tmp, sizeof(tmp), "%X", localtime(&truck.arrCarLocation[i].t1)); file<<"停车时间:"<<tmp<<endl; file<<"-----------------------------"<<endl; } } while(ckey1 !=5); flie.close(); system("pause"; break; 对以上代码修改,优化利用函数减少冗余函数,优化包括计费公式利用,数组优化,界面优化,可以开发新功能
06-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值