I have just added an attachment that shows the output of the code below Perform
ID: 640879 • Letter: I
Question
I have just added an attachment that shows the output of the code below
Perform a desk check of the following code by walking thru the program and executing it like a computer would.
A complete desk check must include:
1. An evaluation of all decision logic indicating the line number of the decision replacing variable names with their values at the time of the evaluation and then indicating if it was true of false.
2. A PseudoMonitor? that shows the output
3. A memory map/table that tracks all variable values.
Be sure to have three separate areas (three sheets of paper if needed) to document the above.
State whether the algorithm represented by the code produces valid results given the obvious objective of the program. If not, explain why not.
Even if it works with the given data set, does it contain potential hazards? Explain. Can you optimize the code in any way?
You may not execute every line of code depending on the logic of the code and program inputs.
Use the following incoming data for your program desk check.
INCOMING DATA
3, 6, 9
$nbr1 = 0;
$nbr2 = 0;
$nbr3 = 0;
$total = 0;
$average = 0;
printf(" Enter a integer between 1-10: ");
fscanf(STDIN, "%d", $nbr1);
printf(" Enter a integer between 1-10: ");
fscanf(STDIN, "%d", $nbr2);
printf(" Enter a integer between 1-10: ");
fscanf(STDIN, "%d", $nbr3);
$total = $nbr1 + $nbr2 + $nbr3;
$average = $total / 3;
printf(" The total of your numbers is %d", $total);
printf(" The average of your numbers is %d", $average);
if($average < 5 )
{
printf(" The average is a touch on the small side.");
}
if($average > 5 )
{
printf(" The average is a touch on the large side.");
}
if($average == 5)
{
printf(" That's about right.");
}
fscanf(STDIN, "%s", $buster);
?>
Explanation / Answer
State whether the algorithm represented by the code produces valid results given the obvious objective of the program. If not, explain why not.
Even if it works with the given data set, does it contain potential hazards? Explain. Can you optimize the code in any way?
Yes the program produces valid results. But we must use float or double as there is division involved, so we can include that as a safe measure.
There are no checks added to see whether the integer belongs to the range between 0 and 10, so we can optimize the code by adding that:
If($nbr1>10 || $nbr1<0)
{
Printf(
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.