473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Reading Pseudocode

1
Hello, I have to take a test for my job. I am not a programmer but a teacher. They want me to teach computer science to elementary school kids. Unfortunately, the test is also based on content from the computer science taught in high school. I will have to read a lot of pseudocode on the test. I just need to pick up the convention of reading the code. I have a math and science background.

I need help with the following problem. I would love an explanation. Also, is there a site in which I can connect to live programmers for tutoring.

The pseudocode procedure assignGrade is intended to return the String representing the letter grade associated with a given integer parameter score as defined in the given table. Which of the following pseudocode procedures correctly implement the assignGrade procedure?

Select all that apply.

A
String assignGrade ( int score )
String result ← "F"
if ( score ≥ 90 )
result ← "A"
end if
if ( score ≥ 80 )
result ← "B"
end if
if ( score ≥ 70 )
result ← "C"
end if
return result
end assignGrade

B
String assignGrade ( int score )
if ( score < 70 )
return "F"
end if
if ( score < 80 )
return "C"
end if
if ( score < 90 )
return "B"
end if
return "A"
end assignGrade

C
String assignGrade ( int score )
if ( score < 70 )
return "F"
if ( score < 80 )
return "C"
if ( score < 90 )
return "B"
end if
end if
end if
return "A"
end assignGrade

This is the explanation that I get. I do not understand why B is the answer. When I wrote the code in Pycharm it did work. However, I am thinking that if I write 64 as the score that since the last thing in the B function is return A. so it will always be A. I am thinking the as it goes down the function that the 64 is less than 70 so you will get an F, but the 64 is less than 80 in the next if statement so you will get a C, so on and so on.

Explanation that I need elaboration on. Thank you so much for helping me
Option (B) is correct. It correctly returns "F" for scores below 70, and then "C", "B", or "A" for progressively higher scores. Option (A) is incorrect. It fails for any score greater than 80, since result would be assigned "C" before being returned. Option (C) is also incorrect. It returns a letter grade of "F" for a score less than 70 and a letter grade of "A" for a score greater than or equal to 70. The statements that come after the first return statement are never executed.
Jan 26 '22 #1
1 7636
dev7060
636 Expert 512MB
This is the explanation that I get. I do not understand why B is the answer. When I wrote the code in Pycharm it did work. However, I am thinking that if I write 64 as the score that since the last thing in the B function is return A. so it will always be A.
The last executed thing in option (B) would be the return statement of the 'if' body that satisfies the condition.

I am thinking the as it goes down the function that the 64 is less than 70 so you will get an F, but the 64 is less than 80 in the next if statement so you will get a C, so on and so on.
Once a return statement is executed, the program control moves back to the caller function.

In option (A); for any score >= 70, all the 'if' conditions would evaluate to true hence all the if blocks would be executed. The latest assignment would always be C, hence the return value.

In option (C); the nested second and third if blocks would never be executed. There is no way to return "B" or "C".
Jan 28 '22 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: bearophileHUGS | last post by:
The free wikipedia is adopting a standard pseudocode: http://en.wikipedia.org/wiki/Wikipedia_talk:Wikicode/Specification MShonle says something nice: I support the idea of wikicode. Basically I...
2
by: Krisitne | last post by:
I need to use a for statement to write some pseudocode. I am not sure how to actually write it - using a for loop. Could someone please give me an example of what a for statment would look like...
10
by: HK | last post by:
With VB.NET 2005, and a Windows Form, running on a dual CPU box, I need to take a recordset (e.g. 100,000 records) and spawn a thread to handle an internet XML transaction routine for each of the...
5
by: cybersangeeth | last post by:
Hi, I need to read 1KB each time from multiple files in a folder and pass it to a byte array in a struct to be sent through a socket. I'm a C++ newbie. I managed to read 1KB each time from one...
1
by: une | last post by:
hey guys, I have this program to do, but I kind of started forst just te read things from the file and then I would go and make the calculation but it is showing some wierd funnky resualts, I dont...
2
by: Joah Senegal | last post by:
Hello all, I;m a beginner C++ and I;m trying to convert some pseudocode into C++. Its pseudo code of the peterson algorithm for N-processes. I almost converted the whole code. But the last...
10
by: HardySpicer | last post by:
I have a cvs data file orbit.csv and found this code. function ReadFile() { var fso, f1, ts, s; var ForReading = 1; fso = new ActiveXObject("Scripting.FileSystemObject"); f =...
7
by: popeyerayaz | last post by:
I want run this by the group for correctness. The question is as follows: 9. Present an example of a logic bug using pseudocode and explain your answer. (10 points) Temperature = 70 if...
2
by: Zeewa19921992 | last post by:
Hi, Could you please help me convert the following pseudocode to C? Any help would be appreciated #include <stdio.h> int main(void) { #...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.