科目三灯光模拟程序源代码c++
需要打字输入
#include <iostream>
#include<iomanip>
#include<string>
#include <math.h>
using namespace std;
void Menu()
{
cout <<"// 欢迎使用科目三灯光模拟系统 //" << endl;
cout << "下面即将开始考试模拟" << endl<<endl<<endl;
}
void Problem(int i)
{
switch (i)
{
case 1:cout << "请开启前照灯" << endl;
break;
case 2: cout << "路边临时停车"<<endl;
break;
case 3:cout << "夜间在没有路灯、照明不良条件下行驶"<<endl;
break;
case 4: cout << "夜间与机动车会车"<<endl;
break;
case 5:cout << "夜间在道上发生交通事故妨碍交通又难以移动"<<endl;
break;
case 6: cout << "夜间超越前方车辆"<<endl;
break;
case 7:cout << "夜间通过拱桥、人行横道"<<endl;
break;
case 8: cout << "夜间通过路口"<<endl;
break;
case 9:cout << "夜间通过急弯、坡路"<<endl;
break;
case 10: cout << "夜间同方向近距离跟车行驶"<<endl;
break;
case 11: cout << "夜间在有路灯、照明良好的道路上行驶" << endl;
break;
case 12: cout << "夜间通过没有交通信号灯控制的路口" << endl;
}
}
int answer(string a,int num = 0)
{
cin >> a;
if (a == "近光灯")num = 1;
else if (a == "示廓+警示灯")num = 2;
else if (a == "远光灯")num = 3;
else if (a == "远近交替")num = 4;
else
{
cout << "输入错误,请重新输入" << endl;
num = answer(a, num);
}
return num;
}
void Get_answer(int i)
{
if (i == 1)cout << "近光灯" << endl;
else if (i == 2)cout << "示廓+警示灯" << endl;
else if (i == 3)cout << "远光灯" << endl;
else if (i == 4)cout << "远近交替" << endl;
}
bool match(int a,int b)
{
if ((a==4||a == 1 || a == 8 || a == 11||a==10 ) && b == 1)return true;
else if ((a == 2 || a == 5) && b == 2)return true;
else if(a == 3 && b == 3)return true;
else if((a == 6 || a == 7 || a == 9 || a == 12) && b == 4)return true;
else return false;
}
int main()
{
int i = 0, problem[13] = { 0 };
string myanswer="0";
srand(time(0));
Menu();
for (int j = 0; j < 12; j++)
{
do
{
i = abs(rand()) % 12+1;
} while (problem[i] == 1);
problem[i] = 1;
Problem(i);
if (match(i, answer(myanswer)))cout << "答案正确"<<endl<<endl;
else
{
cout << "答案错误" << endl;
cout << "正确答案是:";
for (int h = 1; h <= 4; h++)
{
if (match(i, h))
{
Get_answer(h);
break;
}
}
cout << endl<<endl;
}
}
cout << "完成考试" << endl;
system(0);
}
|