Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Think about these programs (A (from Question 2), B, and C) in terms of their cor

ID: 3913668 • Letter: T

Question

Think about these programs (A (from Question 2), B, and C) in terms of their correctness—which program do you prefer? Explain your choice.

If these programs made you want to change your responses to Question 2, how would you change your responses? What about the programs (B, C, or both) made you think differently about Program A from Question 2?

Version B void main(void Version C void nain(void) int button state read button ) hile1) while 1) if (button state 1) [ if(read button 1) led on() led on() while (button state 0) t while (read,button() != 0) t led off) led off) For reference, here is the program from Question 2 (which we will call Program A) // Version ??EROM PREVIOUS TESTION) void main(void) while(1) int button tate-read button(); if(button state= 1) { led on) while (button state 0) 2C): led_off 0:

Explanation / Answer

Program B is not correct since in this approach, we are just reading the initial button state and using it to switch on/off the LED. But the requirement is to continuosly read the buttom state and deicde whether to switch on/off the LED.

Whereas Program C is correct but it does not follow the best approach to solve the problem. We are trying to call the same function 'read_button()' twice inside the for loop when we know that read_button() will return the same value inside one while loop. Hence, we could initialize a variable with read_button() value and use it, as done in Program A.

Hence, in my opinion, program A is the best approach.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote