Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

22 (b) a procedure newdata allows data for new contacts to be entered a…

Question

22
(b) a procedure newdata allows data for new contacts to be entered and stored in the 2d array contacts. a parameter, number, is used to pass values from the main algorithm to the procedure for the number of new contacts. next, four pieces of contact data for each new contact are entered and stored at the start of the array.
(i) complete the pseudocode for procedure newdata
procedure newdata(__________________________________________________)
for row 1 to __________________________________________________
for column 1 to 4
input __________________________________________________
__________________________________________________
endprocedure
4
(ii) write the pseudocode to input the number of new contacts and to use procedure newdata. a variable declaration is not required.
__________________________________________________
__________________________________________________
__________________________________________________
2
(c) an email address can be validated by checking that it contains an @ symbol.
write the pseudocode for an algorithm that will allow an email address to be input and check whether or not it contains an @ symbol.
output a suitable message with the result.
use the string function substring(emailaddress, start, 1) in your solution to return a string of length 1 character, starting at position start, where emailaddress is the identifier representing your input.
you do not need to declare any variables for this algorithm, but variables must be initialised as necessary. assume there will not be more than one @ symbol in the email address input.
__________________________________________________
__________________________________________________
__________________________________________________
__________________________________________________
__________________________________________________
6
21

  1. a school stores all the students attendance data in a file called attendance.txt

write an algorithm in pseudocode to read a line of text from the file and store this line in the variable studentattendance
__________________________________________________
__________________________________________________
4

  1. the variables seconds and minutes are used in a program. seconds holds the number of seconds as a whole number and minutes holds the number of minutes as a whole number.

(a) write pseudocode statements to declare the variables seconds and minutes

Explanation:

Define procedure parameters and array indexing

Using the Subroutines and Functions and Pseudocode knowledge points

  • The procedure NewData takes a parameter Number to specify the number of new contacts.
  • The outer loop iterates through the rows from 1 to Number.
  • The inner loop iterates through columns 1 to 4 to input data into the 2D array Contacts[Row, Column].

Call procedure with user input

Using the Pseudocode and Subroutines and Functions knowledge points

  • Prompt and input the number of new contacts into a variable, e.g., NumContacts.
  • Call the procedure NewData passing NumContacts as the argument.

Validate email address using substring search

Using the String Manipulation and Pseudocode knowledge points

  • Input the email address into EmailAddress.
  • Initialize a boolean flag Found to FALSE.
  • Loop through each character index Start from 1 to the length of EmailAddress using LENGTH(EmailAddress).
  • Extract each character using SUBSTRING(EmailAddress, Start, 1).
  • If the character is "@", set Found to TRUE.
  • After the loop, output a suitable message based on the value of Found.

Read a line from a text file

Using the File Handling and Pseudocode knowledge points

  • Open the file Attendance.txt for reading.
  • Read a line from the file into the variable StudentAttendance.
  • Close the file.

Declare integer variables

Using the Variable Declaration and Pseudocode knowledge points

  • Declare Seconds and Minutes as integer variables using the standard CIE pseudocode format: DECLARE <identifier> : <data type>.

Answer:

Question 22 (b)(i)

PROCEDURE NewData(Number : INTEGER)
    FOR Row <- 1 TO Number
        FOR Column <- 1 TO 4
            INPUT Contacts[Row, Column]
        NEXT Column
    NEXT Row
ENDPROCEDURE

Question 22 (b)(ii)

INPUT NumberOfContacts
CALL NewData(NumberOfContacts)

Question 22 (c)

INPUT EmailAddress
Found <- FALSE
FOR Start <- 1 TO LENGTH(EmailAddress)
    IF SUBSTRING(EmailAddress, Start, 1) = "@" THEN
        Found <- TRUE
    ENDIF
NEXT Start

IF Found = TRUE THEN
    OUTPUT "Email address is valid."
ELSE
    OUTPUT "Email address is invalid."
ENDIF

Question 21 (1)

OPENFILE "Attendance.txt" FOR READ
READFILE "Attendance.txt", StudentAttendance
CLOSEFILE "Attendance.txt"

Question 21 (2)(a)

DECLARE Seconds : INTEGER
DECLARE Minutes : INTEGER