C++极简租车系统(setw()实现可变数据整齐化)

先看效果:
在这里插入图片描述

下面代码只实现了查看车辆信息、客户租车(可选择车型、数量、租用天数)两个功能。

#include<string>
#include<iostream>
#include<iomanip>
#include<windows.h>
using namespace std;

//基类:车
class Vehicle
{
public:
	int veh_count = 0;//车的编号
	double veh_money = 0;//车的日费用
	int veh_hiredays = 0;//车的租用时长
	string veh_kind ;//车的种类
	int car_limitnum = 0;//限载人数
	int car_limitkilo = 0;//限载货重
};
Vehicle passenger_car;
Vehicle truck_car;
Vehicle pickup_car;
int i, j, k;
void init()
{
	//客车
	passenger_car.veh_count = 1;
	passenger_car.veh_money = 200;
	passenger_car.veh_kind = "客车";
	passenger_car.car_limitnum = 20;
	passenger_car.car_limitkilo = 0;
	//货车
	truck_car.veh_count = 2;
	truck_car.veh_money = 300;
	truck_car.veh_kind = "货车";
	truck_car.car_limitnum = 0;
	truck_car.car_limitkilo = 1;
	//皮卡车
	pickup_car.veh_count = 3;
	pickup_car.veh_money = 400;
	pickup_car.veh_kind = "皮卡车";
	pickup_car.car_limitnum = 15;
	pickup_car.car_limitkilo = 1;
}
void check(int a,int car_count)//a用于判断是否有租用该车,为输入的租用的车的数量;car_count为车的编号
{
	if (a > 0)
	{
		switch (car_count)
		{
		case 1:cout << "客车  "; break;
		case 2:cout << "货车  "; break;
		case 3:cout << "皮卡车  "; break;
		}
	}
}
void clearscreen()//清除界面
{
	system("cls");
}
void mainorder() //主界面
{
	cout << "---------------------------------" << endl;
	cout << "    欢迎使用***极简租车系统        " << endl;
	cout << "---------------------------------" << endl;
	cout << "        按1查询车辆信息" << endl;
	cout << "        按2进行租车流程" << endl;
}
void press_one_order()
{
	cout << "编号    车辆种类    日费用(元)    限载人数    限载货重(吨)" << endl;
	//客车
	cout << " " << passenger_car.veh_count << "      " << passenger_car.veh_kind << "        " << passenger_car.veh_money
		<< "           " << passenger_car.car_limitnum << "          " << passenger_car.car_limitkilo<<endl;
	//货车
	cout << " " << truck_car.veh_count << "      " << truck_car.veh_kind << "        " << truck_car.veh_money
		<< "           " << truck_car.car_limitnum << "           " << truck_car.car_limitkilo << endl;
	//皮卡车
	cout << " " << pickup_car.veh_count << "      " << pickup_car.veh_kind << "      " << pickup_car.veh_money
		<< "           " << pickup_car.car_limitnum << "          " << pickup_car.car_limitkilo << endl;

	cout << "按任意整数返回" << endl;
}
void display_bill()//用setw()来使数据整齐
{
	cout << "编号    车辆种类    费用(元)    载人数    载重量(吨)" << endl;
	//客车
	cout << " " << passenger_car.veh_count << "      " << passenger_car.veh_kind << "    " << setw(12)<<i*passenger_car.veh_money* passenger_car.veh_hiredays
		<< setw(10) << i*passenger_car.car_limitnum << setw(14) << i*passenger_car.car_limitkilo<<endl;
	//货车
	cout << " " << truck_car.veh_count << "      " << truck_car.veh_kind << "    " << setw(12) << j*truck_car.veh_money* truck_car.veh_hiredays
		<< setw(10) << j*truck_car.car_limitnum <<  setw(14) << j*truck_car.car_limitkilo << endl;
	//皮卡车
	cout << " " << pickup_car.veh_count << "      " << pickup_car.veh_kind << "  " << setw(12) << k*pickup_car.veh_money* pickup_car.veh_hiredays
		<< setw(10) << k*pickup_car.car_limitnum <<  setw(14) << k*pickup_car.car_limitkilo << endl;
	//总计
	cout << "总计    " << "--------" <<setw(12)<<i * passenger_car.veh_money * passenger_car.veh_hiredays 
		+ j * truck_car.veh_money * truck_car.veh_hiredays + k * pickup_car.veh_money*pickup_car.veh_hiredays
		<< setw(10) << i * passenger_car.car_limitnum + j * truck_car.car_limitnum + k * pickup_car.car_limitnum
		<<  setw(14) << i * passenger_car.car_limitkilo + j * truck_car.car_limitkilo + k * pickup_car.car_limitkilo<<endl;
	//所租车的种类
	cout << "您租用的车型为:";
	check(i, 1);//检测客车
	check(j, 2);//检车货车
	check(k, 3);//检测皮卡车
	cout << endl;
	cout << "按任意整数返回" << endl;
}

int main()
{
	int num;
	init();
	while (1)
	{
		clearscreen();
		mainorder();
		cin >> num;
		if (num == 1)
		{
			clearscreen();
			press_one_order();
			cin >> num;
			if (num == 3)
			{
				clearscreen();
				mainorder();
			}
			num = 0;
		}
		if (num == 2)
		{
			clearscreen();
			cout << "请依次输入要租用客车、货车、皮卡车的数量:";
			cin >> i;
			cin >> j;
			cin >> k;
			cout << endl;
			cout << "请依次输入要租用客车、货车、皮卡车的天数:";
			cin >> passenger_car.veh_hiredays;
			cin >> truck_car.veh_hiredays;
			cin >> pickup_car.veh_hiredays;
			cout << endl;
			cout << "您的租车清单为:" << endl;
			display_bill();
			cin >> num;
			if (num == 3)
			{
				clearscreen();
				mainorder();
			}		
			num = 0;
		}
	}
}

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
一个简单的汽车租赁管理系统C++控制台程序): 利用C++实现对汽车和客户信息的增、删、改等操作,并保存。 部分代码: // CarRent.cpp : 定义控制台应用程序的入口点。 // #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 << "每日租金为(不足一天按一天计算):" <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 << "该汽车已经归还!" << endl; break; } cout << "您成功归还一辆"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

F l e

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值