A microcontroller has checked 40 manufactured parts and accepted 25 of them. It executes this C++ fragment:
int accepted = 25; int checked = 40; float percent = 100.0f * accepted / checked;
What value is stored in percent? Answer in percent, to one decimal place. Enter only the number.
Unlock full course notes by signing up
Tracing a compartment-count array
An Arduino-controlled assembly station stores the number of screws in each of four tray compartments. The following code runs once inside setup():
Complete the table with the value read from the array and the total after each iteration. Enter exact integers in screws. Record each total after the addition has executed.
Finding a counter that restarts
A detector produces one HIGH interval per object and reads LOW between objects. Every interval and intervening LOW is sampled, and the detector initially reads LOW. An indicator should turn on after four objects have been counted and remain on. The test ends before the count reaches 1000.
The sketch below never accumulates the required total:
Which single change fixes the cumulative counting behavior while preserving detection of each new HIGH interval?
Updating a stored comparison
A controller stores a cumulative item count. Before the first pass shown, count is 9. The output on pin 7 should be HIGH exactly when the count at the end of a pass is at least 10. Pin 7 is configured as OUTPUT.
The following fragment runs once per pass. newItem is a Boolean flag supplied by other code that identifies a newly detected item for that pass; resetRequested is another supplied flag. Both flags already have their stated values before this fragment begins.
On the first pass, newItem is true and resetRequested is false. On the second pass, both flags are false. Which statement correctly identifies the two values written by the original code and repairs the output for changes caused by either counting or resetting?
Following local copies through helper calls
A student tests an inventory helper for an Arduino parts dispenser. The helper returns the number of parts left after a requested removal, limiting the removal to the available stock. Trace the sketch exactly as written:
Immediately after the assignment to finalStock, while the variables are still in scope, what values do afterFirst, afterSecond, finalStock and the stock declared inside setup() contain? Enter each quantity in parts as an exact integer.