182k views
2 votes
The county clerk's office is writing a program to search their database for citizen records based on information about that citizen such as first name, last name, age, etc. Given below is a segment of pseudocode that should find the record of every citizen over the age of 50 in the county. The code makes use of the functions GetAgeOf and GetNameOf, which are used to retrieve the age and name of a citizen from a record which is inputted.

FOR EACH person IN citzlist
{
age = GetAgeOf(person)
name = GetNameOf(person) IF(age < 50)
{
DISPLAY(name)
}
There is a mistake in this pseudocode. Which of the following is the correct pseudocode to find the records of all citizens over the age of 50?
1) FOR EACH person IN citzlist
{
age = GetAgeOf(person)
name = GetNameOf(person) IF(age > 50)
{
DISPLAY(name)
}
2) FOR EACH person IN citzlist
{
age = GetAgeOf(person)
name = GetNameOf(person) IF(age = 50)
{
DISPLAY(name)
}
3) FOR EACH person IN citzlist
{
age = GetAgeOf(person)
name = GetNameOf(person) IF(age > 50)
{
DISPLAY(age)
}
4) FOR EACH person IN citzlist
{
age = GetAgeOf(person)
name = GetNameOf(person) IF(age < 50)
{
DISPLAY(age)
}

User Bayram
by
6.4k points

1 Answer

5 votes

Final answer:

The original pseudocode incorrectly displays the name of individuals under 50, while it should display those over 50. Option 1) is correct by using 'IF(age > 50)' to correctly sieve and display the names of citizens over the age of 50.

Step-by-step explanation:

The mistake in the original pseudocode is that it displays the name of a person who is younger than 50 years old, while the intent is to find and display records of citizens over the age of 50. Therefore, the correct pseudocode should compare the age of the person to 50 and display the name only if the age is greater than 50. Thus, the correct pseudocode is:

FOR EACH person IN citzlist {
age = GetAgeOf(person)
name = GetNameOf(person)
IF(age > 50) {
DISPLAY(name)
}
}

Option 1) is the correct version of pseudocode to achieve this task, as it checks whether the age is greater than 50 and, if so, displays the person's name.The correct pseudocode to find the records of all citizens over the age of 50 is:FOR EACH person IN citzlist {

age = GetAgeOf(person)

name = GetNameOf(person)

IF(age > 50) {

DISPLAY(name)

}

In the given pseudocode, the condition is incorrect as it states 'IF(age < 50)', which would display the names of citizens under the age of 50. To find the records of citizens over the age of 50, the correct condition should be 'IF(age > 50)'.

User Wzso
by
8.7k points