code inspection

CSE3310-002/003/004Spring 2024
Assignment 3
Rev A 3/20/2024
This assignment requires you to perform a code inspection. Review the provided code against the
following criteria:
1. Does the code match the design requirements / state machine?
2. Is the code commented adequately and do the comments match the code?
3. Does the code meet generally understood standards regarding variable naming, declarations,
and initialization of variables?
4. Does the code have any logic errors?
Provide your findings in a table like this:
Finding
Line Number
Grading Criteria:
There are six deliberate logic defects in the code.
Each logic error you find by Inspection is worth 2 points. Max 3 errors.
Each ‘other’ finding (comment or requirements defect, coding issue) is worth 1 point.
Each False positive is –1 point.
The max points for this assignment are 5.
Example:
3 logic errors are found, and they are all valid. 6 points, limited to 5 so your score is 5/5.
2 login errors are found, and 1 requirements defect. 4+1 = 5/5
2 logic errors are found, 2 requirements defects, and one of the logic errors was not a defect. 5/5
1 logic error found. 2/5
The state diagram:
#include
#include
// The system controls 3 lights
// RED light
// YELLOW light
// GREEN light
// The system has five states:
enum state {WAITING,WAITING_XWALK_PENDING,GREEN,YELLOW,RED};
// The system has two stimuli
// 1> A timer with 1 second granularity, upon reaching 0, it creates an event
// The timer must be disabled and enabled
// 2> A crosswalk button that is pressed to request the light to stop traffic
//
// Requirements
// 1> The light initializes with the GREEN light illuminated.
// 2> The GREEN light shall stay GREEN for no less than 15 seconds.
// 3> The crosswalk button can be pressed at any time.
// 4> The light shall transition from GREEN to YELLOW when the crosswalk button is
// pressed (and it has been green for the set amount of time)
// 5> The light shall transition from YELLOW to RED after 10 seconds has elapsed.
// 6> The light shall transition from RED to GREEN after 30 seconds have elapsed.
// 7> Only one output light can be illuminated at a time. This shall be
// checked by the system for safety
// 8> Only one stimulus becomes active at a time. They are prioritized, the cross
// walk button occurs first
//
char* debugString;
state stopLight ( state currentState, int *timer, bool crossButton, bool *timerEnabled, bool *redLight,
bool *yellowLight, bool *greenLight)
{
// given the current state, and the value of the two incoming stimulus, this
// function determines the next state.
// It also returns the value of the systems outputs
// All pointer arguments must be valid
assert ( timerEnabled );
assert ( redLight );
assert ( yellowLight );
assert ( greenLight );
assert ( timer );
// If the timer is active, check for an event
bool timerFired = (*timerEnabled && *timer< 0); // Determine the next state state nextState = currentState; // default is no change // The only way for a state transition to occur, is for an event to happen. if ( timerFired || crossButton) { switch (currentState) { case WAITING: if (crossButton) nextState = WAITING_XWALK_PENDING; else if (timerFired) nextState = GREEN; break; case WAITING_XWALK_PENDING: if (timerFired) nextState = GREEN; break; case GREEN: debugString = malloc (15); strcpy(debugString,"GREEN\n"); if (crossButton) nextState = YELLOW; case YELLOW: if (timerFired) nextState = RED; break; case RED: debugString = malloc (15); strcpy(debugString,"RED\n"); if (timerFired) nextState = WAITING; break; default: exit(1); } } // The only time the state entry or exit actions have to execute is when the state changes if (currentState != nextState) { // lets do the exit actions // currently, none are needed. switch (currentState) { case WAITING: case WAITING_XWALK_PENDING: case GREEN: case YELLOW: case RED: break; default: exit(1); } // and now the entry actions switch (nextState) { case WAITING: *redLight = false; *yellowLight = false; *greenLight = true; *timer = 15; *timerEnabled = true; case WAITING_XWALK_PENDING: break; case GREEN: *timerEnabled = false; break; case YELLOW: *redLight = false; *yellowLight = true; *timer = 10; *timerEnabled = true; break; case RED: *redLight = true; *yellowLight = false; *greenLight = false; *timer = 29; *timerEnabled = true; break; default: exit(1); } } // check for only one lit int numLit = 0; if (*redLight) numLit++; if (*yellowLight) numLit++; if (numLit>1) exit(1);
return nextState;
}
void dumpState (bool print,int elapsedTime, bool R, bool Y, bool G)
{
static bool Rprev,Yprev,Gprev;
if (print || R!=Rprev || Y!=Yprev || G!=Gprev)
{
printf (“%5d %d %d %d\n”,elapsedTime,R,Y,G);
}
Rprev = R;
Yprev = Y;
Gprev = Y;
}
int main()
{
// variables for the model
state CS; // current state
bool G,Y,R; // lights
int T;
// timer
bool Tenable; // timer enable
bool XB; // crosswalk button
// variables to set up the situation
int elapsedTime = 0;
// Demonstrate the system works as designed
// Initial conditions
CS = GREEN;
G = true;
Y = false;
R = false;
Tenable = false;
T = 0;
XB = false;
printf (“ET R Y G\n”);
dumpState ( true, elapsedTime, R, Y, G );
// run for 10 seconds
for (int i=0;i

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Are you stuck with your online class?
Get help from our team of writers!

Order your essay today and save 20% with the discount code RAPID