日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C++實現路口交通燈模擬系統_C 語言

作者:KC-馮世傑 ? 更新時間: 2022-05-24 編程語言

交通燈信號控制是交通工具現代化的產物,在平面交叉口,為了把可能發生沖突的車流從時空上分離,必須通過交通信號對交通流進行有效的引導和調度。

設計要求:

(1) ?設計一個十字路口的交通燈控制電路,要求南北方向和東西方向兩個交叉路口的車輛交替運行,每個方向綠燈亮30秒,兩個方向能根據車流量的大小自動調節通行時間,車流量大,通行時間增加30秒,車流量小,通行時間仍然是30秒。

(2) ?在路燈轉為紅燈時,要求黃燈先亮3秒鐘,才能變換運行車道。

系統算法設計圖:

#include ?
#include ?
using namespace std; ?
??
void way1(int a,int y); ? ? //交通燈的函數
void way2(int b);
?
int green1, green2; ? ?//定義交通燈的紅,黃,綠燈的變量和賦初值
int yellow1, yellow2;
int red1, red2;
int green[2] = {31,61};
int yellow = 4;
int red[3] = {34,64};
?
int main()
{
?? ?int car1, car2, car3, car4; ? ? //車輛數變量
?? ?int i = 0, j;
?? ?char d;
?? ?cout<>car1;
?? ??? ?cout<<"請設置西車道車輛數:";
?? ??? ?cin>>car2;
?? ??? ?cout<<"請設置北車道車輛數:";
?? ??? ?cin>>car3;
?? ??? ?cout<<"請設置南車道車輛數:";
?? ??? ?cin>>car4;
?? ??? ?cout<10) ? ? //根據車輛數來選擇交通燈計時函數
?? ??? ?{
?? ??? ??? ?j = i+1;
?? ??? ??? ?way1(j, i);
?? ??? ?}
?? ??? ?else if(((car1+car2)-(car3+car4)>=0)&&((car1+car2)-(car3+car4)<=10))
?? ??? ?{
?? ??? ??? ?way2(i);
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?j = i+1;
?? ??? ??? ?way1(i, j);
?? ??? ?}
?? ??? ?cout<<"若想重新設置車輛數請按Y,若退出請按N。";
?? ??? ?cin>>d;
?? ??? ?if(d == 'Y'||d == 'y')
?? ??? ?{
?? ??? ??? ?cout<0;c--)
?? ??? ?{ ?
?? ??? ??? ?cout<0)
?? ??? ??? ?{
?? ??? ??? ??? ?if(green1==green[a])
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?green1--;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<" ? >>> 綠燈 <<< "<0) ?
?? ??? ??? ?{ ?
?? ??? ??? ??? ?if(yellow1==4) ?
?? ??? ??? ??? ??? ?yellow1--; ? ?
?? ??? ??? ??? ?else ?
?? ??? ??? ??? ?{ ?
?? ??? ??? ??? ??? ?cout<<" ? >>> 黃燈 <<< "<0) ?
?? ??? ??? ?{ ?
?? ??? ??? ??? ?if(red1==red[y]) ?
?? ??? ??? ??? ??? ?red1--; ?
?? ??? ??? ??? ?else ??
?? ??? ??? ??? ?{?
?? ??? ??? ??? ??? ?cout<<" ? >>> 紅燈 <<< "<0)
?? ??? ??? ?{
?? ??? ??? ??? ?if(red2==red[a])
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?red2--;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<" ? >>> 紅燈 <<< "<0) ?
?? ??? ??? ?{ ?
?? ??? ??? ??? ?if(green2==green[y]) ?
?? ??? ??? ??? ??? ?green2--; ? ?
?? ??? ??? ??? ?else ?
?? ??? ??? ??? ?{ ?
?? ??? ??? ??? ??? ?cout<<" ? >>> 綠燈 <<< "<0) ?
?? ??? ??? ?{ ?
?? ??? ??? ??? ?if(yellow2==4) ?
?? ??? ??? ??? ??? ?yellow2--; ?
?? ??? ??? ??? ?else ??
?? ??? ??? ??? ?{ ?
?? ??? ??? ??? ??? ?cout<<" ? >>> 黃燈 <<< "<>d;
?? ??? ?if(d == 'C'||d == 'c')
?? ??? ?{
?? ??? ??? ?cout<0;c--)
?? ??? ?{ ?
?? ??? ??? ?cout<0)
?? ??? ??? ?{
?? ??? ??? ??? ?if(green1==green[b])
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?green1--;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<" ? >>> 綠燈 <<< "<0) ?
?? ??? ??? ?{?? ??
?? ??? ??? ??? ?if(yellow1==4) ?
?? ??? ??? ??? ??? ?yellow1--; ? ?
?? ??? ??? ??? ?else ?
?? ??? ??? ??? ?{ ?
?? ??? ??? ??? ??? ?cout<<" ? >>> 黃燈 <<< "<0) ?
?? ??? ??? ?{ ?
?? ??? ??? ??? ?if(red1==red[b]) ?
?? ??? ??? ??? ??? ?red1--; ?
?? ??? ??? ??? ?else ??
?? ??? ??? ??? ?{?
?? ??? ??? ??? ??? ?cout<<" ? >>> 紅燈 <<< "<0)
?? ??? ??? ?{
?? ??? ??? ??? ?if(red2==red[b])
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?red2--;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<" ? >>> 紅燈 <<< "<0) ?
?? ??? ??? ?{ ?
?? ??? ??? ??? ?if(green2==green[b]) ?
?? ??? ??? ??? ??? ?green2--; ? ?
?? ??? ??? ??? ?else ?
?? ??? ??? ??? ?{ ?
?? ??? ??? ??? ??? ?cout<<" ? >>> 綠燈 <<< "<0) ?
?? ??? ??? ?{ ?
?? ??? ??? ??? ?if(yellow2==4) ?
?? ??? ??? ??? ??? ?yellow2--; ?
?? ??? ??? ??? ?else ??
?? ??? ??? ??? ?{ ?
?? ??? ??? ??? ??? ?cout<<" ? >>> 黃燈 <<< "<>d;
?? ??? ?if(d == 'C'||d == 'c')
?? ??? ?{
?? ??? ??? ?cout<

原文鏈接:https://blog.csdn.net/u013930494/article/details/33070443

欄目分類
最近更新