0% found this document useful (0 votes)
33 views3 pages

S 23 42

The document provides instructions for a programming assignment asking the student to: 1. Declare a string array to store 10 animal names 2. Store given animal names in the array 3. Write a procedure to sort the array alphabetically by first character 4. Amend the main program to call the sorting procedure and output the results

Uploaded by

aghaqasimali13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

S 23 42

The document provides instructions for a programming assignment asking the student to: 1. Declare a string array to store 10 animal names 2. Store given animal names in the array 3. Write a procedure to sort the array alphabetically by first character 4. Amend the main program to call the sorting procedure and output the results

Uploaded by

aghaqasimali13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Open the document evidence.

doc

Make sure that your name, centre number and candidate number will appear on every page of this
document. This document must contain your answers to each question.

Save this evidence document in your work area as:

evidence_ followed by your centre number_candidate number, for example: evidence_zz999_9999

1 A 1D array needs to store the names of 10 animals.

(a) Write program code to declare the global string array Animals to store 10 items.

Save your program as Question1_J2023.

Copy and paste the program code into part 1(a) in the evidence document.
[3]

(b) The main program needs to store the following animals in the array:

horse
lion
rabbit
mouse
bird
deer
whale
elephant
kangaroo
tiger

Write program code to store these animal names in the array.


The names must be in lower case and stored in the order given in the list.

Save your program.

Copy and paste the program code into part 1(b) in the evidence document.
[2]
(c) The following pseudocode procedure sorts the array into a descending alphabetical order
using only the first character in each animal name.

The function LENGTH(DataArray) returns the number of elements in the array DataArray.

The function MID(String, Start, Quantity) returns Quantity number of characters


from String starting at index Start. The first character in the string is index 0, for example:

MID("tiger", 0, 2) will return "ti"

There are four incomplete statements in the procedure.

PROCEDURE SortDescending()

DECLARE ArrayLength : INTEGER

DECLARE Temp : STRING

ArrayLength LENGTH(Animals)

FOR X 0 TO ArrayLength - 1

FOR Y ……………… TO ArrayLength - X - 1

IF MID(Animals[Y], 0, 1) < MID(Animals[………………], 0, 1) THEN

Temp Animals[………………]

Animals[Y] Animals[Y + 1]

Animals[Y + 1] ………………

ENDIF

NEXT Y

NEXT X

ENDPROCEDURE

Write program code for the procedure SortDescending().

Save your program.

Copy and paste the program code into part 1(c) in the evidence document.
[6]
(d) (i) Write program code to amend the main program to:

• call the procedure SortDescending()


• output the sorted contents of the array with each animal name on a new line.

Save your program.

Copy and paste the program code into part 1(d)(i) in the evidence document.
[3]

(ii) Test your program.

Take a screenshot of the output.

Save your program.

Copy and paste the screenshot into part 1(d)(ii) in the evidence document.
[1]

You might also like