網站首頁 編程語言 正文
交通燈信號控制是交通工具現代化的產物,在平面交叉口,為了把可能發生沖突的車流從時空上分離,必須通過交通信號對交通流進行有效的引導和調度。
設計要求:
(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-11-13 如何修改npm默認源為淘寶源
- 2023-02-27 python定時任務sched庫用法簡單實例_python
- 2022-04-29 C#實現實體類和XML的相互轉換_C#教程
- 2023-12-23 React環境安裝配置
- 2023-04-26 C語言實現數組元素排序方法詳解_C 語言
- 2022-06-01 Kubernetes集群的組成介紹_云和虛擬化
- 2022-03-20 關于數據庫系統的概述_數據庫其它
- 2022-07-11 go語言環境搭建
- 最近更新
-
- 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同步修改后的遠程分支