網站首頁 編程語言 正文
交通燈信號控制是交通工具現代化的產物,在平面交叉口,為了把可能發生沖突的車流從時空上分離,必須通過交通信號對交通流進行有效的引導和調度。
設計要求:
(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
相關推薦
- 2022-12-28 golang?gin?監聽rabbitmq隊列無限消費的案例代碼_Golang
- 2023-02-10 C++?deque與vector對比的優缺點_C 語言
- 2023-07-14 react實現拖拽功能
- 2023-11-20 帶寬單位是什么?帶寬單位詳解?帶寬單位如何換算?
- 2022-09-02 Docker下Redis集群(主從+哨兵)安裝配置的實現步驟_docker
- 2022-08-11 boost字符串處理函數format的用法_C 語言
- 2023-01-07 Android?RecyclerLineChart實現圖表繪制教程_Android
- 2022-07-23 asp.net6?blazor?文件上傳功能_實用技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支