Assignment One PRLD5121
Assignment One PRLD5121
Start
Declarations // declaration of variables
String learnername
String names[ ]
Num learnermarks
Num marks[ ]
Num classaverage
totalmarks=0
highestmark=0
lowestmark=100
for I = 1 to 10 do // A loop is used to capture the 10 student’s name and mark
Output “Please Enter you name”
Input learnername
Names[i]=learnername
Output “Please enter your mark “
Input learnermarks
If learnermarks <0 OR >100 then // check performed to ensure valid mark is entered
Output “Invalid mark entered , please enter in your CORRECT mark”
Output “Please enter your mark “ // user is re-prompted to enter their mark
Input learnermarks
endwhile
else
marks[i]= learnermarks
totalmarks= totalmarks + learnermarks
if learnermarks >=75 then
Output “Distincton” + learnermarks // Check performed to see whether student achieved a
distinction
Else if learnermarks <50 then // Check performed to see whether a student failed
Ouput “Fail” + learnermarks
Else Output “Pass” + learnermarks
if learnermarks>highestmark then
highestmark= learnermarks // How the highest mark is detected
tempname=names[j]
names[j]=names[j+1]
names[j+1]= tempname
Output “Highest Mark” + names[1]
// so over here in order to determine which student had the highest mark I used a simple
sort method (bubble sort). The first index will give me the learner that has the highest mark.
Arrays are arranged in ascending order over here.
tempname=names[j]
names[j]=names[j+1]
names[j+1]= tempname
Output “Lowest Mark” + names[1]
// Once again pretty much the same thing as above(Module High) , the only difference here
is that the mark and name array are arranged in descending order(mark dependant). Again
the first index has to give me the student with the lowest mark.
end
Question two
Bubble sort is a technique that is usually used to switch or re-arange adjacent components if
they were to be in the wrong order or position. Bubble sort is known to be the simplest
sorting algorithm.
-Let’s look at an example that demonstrates just how bubble sort works
(productplan.com)
So in this diagram we have the numbers [6,2,8,4,10], now they’re definitely in the wrong
order , so through Bubble Sort the numbers ca be arranged in their right order.
First Pass – The algorithm will compares the number’s 6 and 2 and thereafter puts them in
the right order, we’re now left with[2,6,8,4,10]
Second Pass – In the second pass the algorithm will compare the numbers 8 and 4 and
thereafter put them in the correct order, we’re now left with [2,6,4,8,10]
Third Pass – In the final pass the algorithm will compare the numbers 6 and 4 and once
again put them in the correct order, this leaves us with the sequence [2,4,6,8,10], this is
indeed the correct order of numbers and this was achieved through bubble sort.
Question Three
An array is copied and transmitted to the module as a whole when it is supplied as a
parameter. To receive the array, the module must first have a declared argument. A variable
that is declared in the module and used to receive the provided array is known as a
parameter. The provided array's data type must match that of this parameter. The array is
then passed to the module using an argument. The actual value of the array that is being
supplied is referred to as an argument. When the module is called in the main program, this
parameter is provided.(esona.2023).
Pseudocode:
module DivideArray(dividearray)
for i from 0 to dividearray.length - 1 do // the loop
// Over here we are going to call (myArray), this links our DividedArray to (myArray)
myArray = [8, 16, 32, 64, 128]
DivideArray(myArray)
References
esona (2023). Explain how an array is passed to a module. Your explanation must include an
example with. [online] Questions LLC. Available at:
https://questions.llc/questions/2011091/explain-how-an-array-is-passed-to-a-module-your-
explanation-must-include-an-example-with. [Accessed on the 6th of June 2023].
www.productplan.com. (n.d.). What is Bubble Sort? | Definition and Overview |
ProductPlan. [online] Available at: https://www.productplan.com/glossary/bubble-sort/.
[Accessed on the 5th of June 2023].