汽车仪表模拟器
Car Instrument Simulator
所以我正在编写一个代码来编写汽车仪表模拟器,我应该有一个菜单的开关语句:显示仪表,询问它们到驾驶有多远,询问要添加多少汽油,然后退出。我让它显示菜单,但是当我按下其中一个选项时,它什么也没做。我希望有人帮助我弄清楚我错过了什么,而不是说帮助我做到这一点,因为我想学习,所以下次我不会遇到同样的问题,已经工作了一段时间,甚至查找了一些关于 switch 语句的视频,但我只是不明白。
#include <iostream>
#include <string>
using namespace std;
void printmenu();
class FuelGauge
{
private:
int CurrentFuel;
public:
FuelGauge();
~FuelGauge();
FuelGauge(int g)
{
CurrentFuel = g;
}
int getCurrentFuel()
{
return CurrentFuel;
}
void IncrementFuel()
{
int gas;
cout << "How much fuel are you putting in? " << endl;
cin >> gas;
for (int fuel = gas; gas > 0; gas--) {
CurrentFuel++;
}
}
void DecrementFuel()
{
if (CurrentFuel > 0)
CurrentFuel--;
}
};
FuelGauge::FuelGauge()
{
}
FuelGauge::~FuelGauge()
{
}
class Odometer
{
private:
int CurrentMileage;
FuelGauge* fuel;
public:
Odometer();
~Odometer();
Odometer(int miles, FuelGauge* f)
{
CurrentMileage = miles;
fuel = f;
}
int getCurrentMileage()
{
return CurrentMileage;
}
void incrementCurrentMileage()
{
if (CurrentMileage < 999999)
CurrentMileage++;
else
CurrentMileage = 0;
}
void decrementCurrentMileage()
{
if (CurrentMileage > 24)
CurrentMileage--;
(*fuel).DecrementFuel();
}
};
Odometer::Odometer()
{
}
Odometer::~Odometer()
{
}
int main()
{
FuelGauge fuel(15);
Odometer odo(0, &fuel);
int n = 0;
while (n != 5) {
printmenu();
cin >> n;
switch (n) {
case 1:
fuel.getCurrentFuel();
break;
case 2:
odo.getCurrentMileage();
break;
case 3:
break;
case 4:
fuel.IncrementFuel();
break;
default:
break;
}
return 0;
}
}
void printmenu() {
cout << "1. Show current fuel " << endl;
cout << "2. Show current status of the odometer " << endl;
cout << "3. How far are you going? " << endl;
cout << "4. How much gass are you putting in? " << endl;
}
你打算观察什么?你调用一些返回值而没有任何副作用的方法,并且你不对这些值做任何事情:你会立即丢失它们。您可能应该输出它们:
cout << fuel.getCurrentFuel();
相关文章:
- 如何在c++中实现处理器调度模拟器
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 询问在设计我的手臂模拟器功能表示格式1
- 在模拟器中使用并集来模拟CPU寄存器有多合适
- 汽车仪表模拟器
- 键盘模拟器
- 用GTK创建逻辑门模拟器,如何制作放置区域
- 如何在 ns2 模拟器中修改节点的行为?
- opengl 飞行模拟器应用程序中的文本呈现问题
- PHP 中的实时仪表板,可从C++共享数据
- Arduino立体声VU仪表
- 使用模拟器C++从RISC-V裸机程序调用printf系统调用时失败
- 如何创建和分发 SteamVR 仪表板叠加层
- 具有原生C++库的 Android 免安装应用不会发布到运行 Android N 的设备/模拟器
- 使用 Qt 链接到 iOS 模拟器上的静态库时不兼容的架构
- 彩票模拟器正在返回垃圾价值,而不是用户乐透数字和获胜数字
- Clion Cmake项目不编译:Dyld Mach-O,而是为模拟器构建(不是MacOS)
- Opencv 功能匹配在 iPhone 上中断,但在模拟器上不会中断
- 如何在Android模拟器上显示垫子图像?使用NDK
- c++汽车仪表模拟器.我一直收到这些错误信息