software engineering - urgent help needed (1 Viewer)

aanyachandel

New Member
Joined
Mar 26, 2024
Messages
9
Gender
Female
HSC
2026
i don't get this at all:

"Produce pseudocode and flowchart for the following:

Produce a function called has7or9 that will accept as input an array and return true if the array contains a 7 or a 9, otherwise it will return false."

i have the answer to only the flowchart (below), but i'm not sure how any of it came to be. why does n=0? how do i phrase the while loop????

my test is on monday and i am SCREWED

thanks in advance
IMG_7019.jpeg
 

dav53521

Well-Known Member
Joined
Mar 23, 2022
Messages
317
Gender
Male
HSC
2022
i don't get this at all:

"Produce pseudocode and flowchart for the following:

Produce a function called has7or9 that will accept as input an array and return true if the array contains a 7 or a 9, otherwise it will return false."

i have the answer to only the flowchart (below), but i'm not sure how any of it came to be. why does n=0? how do i phrase the while loop????

my test is on monday and i am SCREWED

thanks in advance
View attachment 42871
The reason why n = 0 is because in most programming languages an array is indexed from 0 to n-1 which means that to access the array at point i we will need to access the array at the Nth-1 index. So to find the 1st number we would do something like myArray[0], for the second number we would do myArray[1] and to find the last index we would do something like myArray[myArray.Length-1].

For the phrasing of the while loop we need to think of what condition should allow the loop to continue as a while loop will continue while the condition given to it is true. So in this case we would want to continue the loop while the variable n is less then the length of myArray.Length - 1 which can be expressed in multiple ways but it the way it was written in the flow chart works just fine. So in the end the while loop will look something like while(n <= myArray.Length - 1).
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top