資源簡介
一個(gè)簡單的汽車租賃管理系統(tǒng)(C++控制臺程序):
利用C++實(shí)現(xiàn)對汽車和客戶信息的增、刪、改等操作,并保存。
部分代碼: // CarRent.cpp : 定義控制臺應(yīng)用程序的入口點(diǎn)。
//
#include "stdafx.h"
#include "CarData.h"
#include "Menu.h"
#include"CustomerData.h"
int main()
{
Menu::welcome();
Menu::login(); //登錄界面
char choice;
int carid, customerid;
//汽車編號,客戶編號
CustomerData CustomerDB;
//客戶庫
Customer *r;
//客戶
CarData CarDB;
//汽車庫
Car *b;
//汽車
Menu::showMenu(); //顯示菜單
cout <> choice;
while (choice != '0') {
switch (choice) {
case '1': //輸入客戶編號和要出租的汽車
cout <> customerid;
try
{
if (customerid <= 0)
throw 1;
}
catch (...)
{
cout << "輸入有誤,請重新輸入";
break;
}
cout <> carid;
try
{
if (carid <= 0)
throw 1;
}
catch (...)
{
cout << "輸入有誤,請重新輸入";
break;
}
r = CustomerDB.search(customerid);
if (NULL == r)
{
cout << "不存在該客戶!";
cout << endl;
break;
}
b = CarDB.search(carid);
if (b == NULL)
{
cout << "不存在該汽車!"; cout <borrowCar() == 0)
{
cout << "該汽車已租出!";
cout <borrowCar(b->getNo());
cout << "你在" <getBorTime()) << "成功出租一輛" <getName() << endl << "每日租金為(不足一天按一天計(jì)算):" <getPay();
break;
case '2':
//歸還操作
cout <> customerid;
try
{
if (customerid <= 0)
throw 1;
}
catch (...)
{
cout << "輸入有誤,請重新輸入";
break;
}
cout <> carid;
try
{
if (carid <= 0)
throw 1;
}
catch (...)
{
cout << "輸入有誤,請重新輸入";
break;
}
r = CustomerDB.search(customerid); //按編號查找
if (r == NULL)
{
cout << "不存在該客戶!" << endl;
break;
}
b = CarDB.search(carid);
if (b == NULL)
{
cout << "不存在該汽車!" <getOnshelf() == 1)
{
cout << "該汽車已經(jīng)歸還!" << endl;
break;
}
cout << "您成功歸還一輛"

代碼片段和文件信息
#include?“stdafx.h“
#include?“Car.h“
Car::Car()
{
}
Car::~Car()
{
}
time_t?Car::getTimer()
{
return?t;
}
time_t?Car::getTimer1()
{
return?t1;
}
struct?tm?*?Car::getBorTime()
{
t?=?time(NULL);
struct?tm?*tblock?=?localtime(&t);
return?tblock;
}
struct?tm?*?Car::getRetTime()
{
t1?=?time(NULL);
struct?tm?*tblock1?=?localtime(&t1);
return?tblock1;
}
int?Car::getPay()
{
return?pay;
}
char?*?Car::getName()
{
return?name;
}
int?Car::getOnshelf()
{
return?onshelf;
}
int?Car::getNo()
{
return?no;
}
int?Car::getTag()
{
return?tag;
}
void?Car::delCar()
{
tag?=?1;
cout?<“刪除成功“;
}
void?Car::addCar(int?n?char?*?na?int?npay)
{
tag?=?0;
no?=?n;
pay?=?npay;
strcpy(name?na);
onshelf?=?1;
}
int?Car::borrowCar()
{
if?(onshelf?==?1)
{
onshelf?=?0;
return?1;
}
return?0;
}
void?Car::retCar()
{
int?costTotal?=?(int)(getPay()*((difftime(t1?t)?/?86400?+?1)));
onshelf?=?1;
}
void?Car::print()
{
cout?<“汽車編號:“?< <(onshelf?==?1???“在車庫“?:?“已租“)?<}
void?Car::disp()
{
cout?< <(onshelf?==?1???“在車庫“?:?“已租“)?<}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????????44??2017-06-06?21:34??說明.txt
?????文件????????1325??2017-05-21?19:02??Car.cpp
?????文件?????????788??2017-05-21?18:49??Car.h
?????文件????????5499??2017-05-21?18:36??CarData.cpp
?????文件?????????616??2016-08-17?18:13??CarData.h
?????文件????????3329??2017-05-21?19:13??CarRent.cpp
?????文件????????1856??2017-05-21?18:59??Customer.cpp
?????文件?????????899??2017-05-21?18:40??Customer.h
?????文件????????5947??2017-05-24?19:07??CustomerData.cpp
?????文件?????????686??2016-08-17?18:13??CustomerData.h
?????文件????????2752??2016-08-17?18:13??Menu.cpp
?????文件??????????89??2016-08-17?18:13??Sign.cpp
?????文件?????????259??2016-08-17?18:13??Sign.h
?????文件?????????211??2016-08-17?18:13??stdafx.cpp
?????文件?????????234??2016-08-17?18:13??stdafx.h
?????文件?????????240??2016-08-17?18:13??targetver.h
評論
共有 條評論