Discover the best answers at Westonci.ca, where experts share their insights and knowledge with you. Explore thousands of questions and answers from knowledgeable experts in various fields on our Q&A platform. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.

A programmer for a weather website needs to display the proportion of days with freezing temperatures in a given month.


Their algorithm will operate on a list of temperatures for each day in the month. It must keep track of how many temperatures are below or equal to 32. Once it's done processing the list, it must display the ratio of freezing days over total days.
Which of these correctly expresses that algorithm in pseudocode?
A.
numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp ≤ 32) {

numFreezing ← numFreezing + 1

}

numDays ← numDays + 1

DISPLAY(numFreezing/numDays)

}

B.
numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp ≤ 32) {

numFreezing ← numFreezing + 1

}

numDays ← numDays + 1

}

DISPLAY(numFreezing/numDays)

C.
numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp < 32) {

numFreezing ← numFreezing + 1

}

numDays ← numDays + 1

}

DISPLAY(numFreezing/numDays)

D.
numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp ≤ 32) {

numFreezing ← numFreezing + 1

numDays ← numDays + 1

}

}

DISPLAY(numFreezing/numDays)

Sagot :

Answer:

B.

Explanation:

The correct Pseudocode for this scenario would be B. This code makes two variables for the number of total days (numDays) and number of freezing days (numFreezing). Then it loops through the entire data set and checks if each temp is less than or equal to 32 degrees. If it is, it adds it to numFreezing, if it is not then it skips this step, but still adds 1 to the total number of days after each loop. Once the entire loop is done it prints out the ratio, unlike answer A which prints out the ratio for every iteration of the loop.

numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp ≤ 32) {

numFreezing ← numFreezing + 1

}

numDays ← numDays + 1

}

DISPLAY(numFreezing/numDays)

Thank you for trusting us with your questions. We're here to help you find accurate answers quickly and efficiently. Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. We're glad you chose Westonci.ca. Revisit us for updated answers from our knowledgeable team.