CSCI 3080 - Discrete Structures

Lab 1 - Traffic Light Control System Simulation

1. Objective

The goal of this lab is to develop a C++ program to simulate a traffic light control system using propositional logic. The system will take input conditions such as the presence of a car, pedestrian crossing, and timer status to determine whether the traffic light should turn green or remain red. Students will learn how to apply logical expressions to solve real-world problems and optimize decision-making.

2. Problem Statement

A traffic light system is required to control the flow of vehicles and pedestrians efficiently. The system should allow vehicles to pass only if they meet specific conditions. The traffic light should turn green if:

(1) Propositional Variables

In the traffic light system, the conditions can be represented as propositional variables:

(2) Logical Expression for Decision Making

The well-formed formula to determine if the traffic light should turn green: (C ∨ T) ∧ ¬P

Explanation of the formula:

(3) Truth Table Representation

We can represent the decision-making process using a truth table, which is a key characteristic of propositional logic.

C T P C ∨ T ¬P (C ∨ T) ∧ ¬P
T T T T F F
T T F T T T
T F T T F F
T F F T T T
F T T T F F
F T F T T T
F F T F F F
F F F F T F

Key Observations from the Truth Table:

The traffic light turns green when (Final Column = True):

3. Requirements

4. Sample Input/Output

Traffic Light Control System Simulation
-------------------------------------------------------------
Is a car detected? (1 for Yes, 0 for No): 1
Is the timer condition allowing? (1 for Yes, 0 for No): 1
Is a pedestrian crossing? (1 for Yes, 0 for No): 0
Result: The traffic light is GREEN (Cars can go)
Do you want to try again? (y/n): y

Is a car detected? (1 for Yes, 0 for No): 1
Is the timer condition allowing? (1 for Yes, 0 for No): 0
Is a pedestrian crossing? (1 for Yes, 0 for No): 0
Result: The traffic light is GREEN (Cars can go)
Do you want to try again? (y/n): y

Is a car detected? (1 for Yes, 0 for No): 0
Is the timer condition allowing? (1 for Yes, 0 for No): 1
Is a pedestrian crossing? (1 for Yes, 0 for No): 0
Result: The traffic light is GREEN (Cars can go)
Do you want to try again? (y/n): y

Is a car detected? (1 for Yes, 0 for No): 0
Is the timer condition allowing? (1 for Yes, 0 for No): 0
Is a pedestrian crossing? (1 for Yes, 0 for No): 1
Result: The traffic light is RED (Cars must stop)
Do you want to try again? (y/n): n

Simulation ended. Thank you!
-------------------------------------------------------------
    

5. Grading Criteria

Grading Criteria (Total Points: 100)
Category Criteria Points
Variable Declarations
(10 points)
Boolean variables:
  • carDetected
  • timerCondition
  • pedestrianCrossing
  • greenLight
8
Character variable:
  • choice
2
User Inputs
10 points
Reads input from standard input and stores it in the variable correctly. 10
trafficLightControl Function Implementation
(30 points)
Function Prototype: bool trafficLightControl(bool carDetected, bool timerCondition, bool pedestrianCrossing); 5
Function Implementation: Accurately implement the logical expression (C ∨ T) ∧ ¬P. 20
Function Activation: The function is called correctly in the main function. 5
Main Function Implementation
(30 points)
Prompt the user to enter input in a clear and correct format. 5
Proper formatting of program output for readability and clarity. 5
do-while loop is implemented correctly. 20
Code Readability & Comments
(10 points)
Maintain consistent indentation and spacing throughout the code. 5
Include comments that explain the purpose of key sections and logic. 5
Test Cases & Output Accuracy
(10 points)
The output for different test cases is correct and consistent. 10
Errors
Your program has syntax errors, compiling errors, running errors, or infinite loops. -50 points

6. Comments

7. Submit

Please submit your Lab 1 source code file: lab1.cpp in D2L!

8. Jupyter Hub for Programming

Jupyter Hub for Programming
By logging in to Jupyter Hub with your MTSU credentials, you can create, compile, and run your source code there.

9. Demo Code

You can find relevant C++ demo code here: Demo Code
Congratulations! You have finished your Lab1!