0% found this document useful (0 votes)
25 views

Assignment 3

Uploaded by

hassanahmed1206
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Assignment 3

Uploaded by

hassanahmed1206
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Science

Assignment 3
Instructions:
 This assignment will assess how well you have understood these topics. Make sure you
have read through the course materials for these topics before attempting this assignment.
o 9.1 - Computational Thinking Skills
o 9.2 - Introduction To Algorithms
o 10.1 - Introduction To Programming Theory
o 10.2 - Introduction To Abstract Data Types
o 11.1 - Pseudocode Basics
o 11.2 - Pseudocode – Selection
o 11.3 - Pseudocode – Iteration
o 11.4 - Pseudocode - Arrays and Records
o 11.5 - Pseudocode - Procedures and Functions
o 11.6 - Pseudocode – Files
o 12.1 - Program Development Life Cycles
o 12.2 - Program Design
o 12.3 - Program Testing and Maintenance

 You should answer all questions.

 Write your answers in a separate document such as a Microsoft Word file.

 If required, make sure you show all of your working out.

 You must not use a calculator.

 The total mark for this assignment is 75.

 You must ensure that the work you submit for this assignment is your own. Your tutor may
use plagiarism checkers if they are concerned that your work has been copied from another
source.

 Upon completion of this assignment, you will need to submit your work to your tutor by
following the instructions in the study guide. When marked, you will receive both your final
score and feedback from your tutor.

 If you have any questions or need help, please contact your personal tutor for Computer
Science.
1 (a) Program variables have values as follows:

Variable Value

Today "Tuesday"

WeekNumber 37

Revision 'C'

MaxWeight 60.5

LastBatch TRUE

(i) Give an appropriate data type for each variable.

Variable Data type

Today

WeekNumber

Revision

MaxWeight

LastBatch

Q1ai [5]

(ii) Evaluate each expression in the following table. If an expression is invalid then write ERROR.

Expression Evaluates to

MID(Today, 3, 2) & Revision & "ape"

INT(Maxweight + 4.2)

LENGTH(MaxWeight)

MOD(WeekNumber, 12)

(Revision <= 'D') AND (NOT LastBatch)

Q1aii [5]
(b) Simple algorithms usually consist of input, process and output.

Complete the table to show if each statement is an example of input, process or output.

Place one or more ticks (✔) for each statement.

Item Statement Input Process Output

1 SomeChars ← "Hello World"

2 OUTPUT RIGHT(SomeChars,5)

3 READFILE MyFile, MyChars

4 WRITEFILE MyFile, "Data is " & MyChars

Q1b [4]

(c) Write pseudocode to show how a repeat loop can be used to output all the odd numbers between 100
and 200.
Q1c [4]

2 Roberta downloads music from an online music store. The diagram shows part of a structure chart
for the online music store program.

(a) State three items of information that the diagram shows about the design of the program.

Q2a [3]
(b) Examples of the data items that correspond to the arrows are given in the table.

Arrow Data item

A 234.56

B "Ms Roberta Smith"

C TRUE

Use pseudocode to write the function header for the Card payment module.

Q2b [3]

3 A stack is created using a high-level language. The following diagram represents the current state of the
stack. The TopOfStack pointer points to the last item added to the stack.

Pointer
Address Value

99

100

101 E ⇐ TopOfStack

102 D

103 C

104 B

105 A

(a) Two operations associated with this stack are PUSH()and POP().

These two operations are carried out in this order.

Describe these operations with reference to the diagram.

MyVar = POP()

PUSH('Z')

Q3a [4]
(b) Two programs use a stack to exchange data.

Program AddString pushes a string of characters onto the stack one character at a time.

Program RemoveString pops the same number of characters off the stack, one character at a time.

The string taken off the stack is different from the string put on the stack.

Explain why the strings are different.


Q3b [2]

4 (a) Parameter x is used to pass data to procedure MyProc in the following pseudocode:

x ←4
CALL MyProc(x)
OUTPUT x

PROCEDURE MyProc(x : INTEGER)


x ←x + 1
OUTPUT x
ENDPROCEDURE

There are two parameter passing methods that could be used.

Complete the table for each of the two methods:

Name of parameter Value


passing method output Explanation

Q4a [6]

(b) The pseudocode includes the use of parameters.

State two other features in the pseudocode that support a modular approach to programming.

Q4b [2]
5 A company keeps details of its product items in a 1D array, Stock.

The array consists of 1000 elements of type StockItem.

The record fields of StockItem are:


Field Typical value

ProductCode "BGR24-C"

Price 102.76

NumberInStock 15

(a) Write pseudocode to declare the record structure StockItem.


Q5a [3]

(b) Write pseudocode to declare the Stock array.


Q5b [3]

(c) Write pseudocode to modify the values to element 20 as follows:

• set the price to 105.99


• increase the number in stock by 12
Q5c [2]

(d) A stock report program is developed.

Write pseudocode to output the information for each stock item that has a price of at least 100.

Output the information as follows:

Product Code: BGR24-C Number in Stock: 15


Q5d [4]
6 Members of a family use the same laptop computer. Each family member has their own password.

To be valid, a password must comply with the following rules:

1. At least two lower-case alphabetic characters


2. At least two upper-case alphabetic characters
3. At least three numeric characters
4. Alpha-numeric characters only

A function, ValidatePassword, is needed to check that a given password follows these rules. This
function takes a string, Pass, as a parameter and returns a boolean value:

• TRUE if it is a valid password


• FALSE otherwise

(a) Write pseudocode to implement the function ValidatePassword.

Refer to the Insert for the list of pseudocode functions.


Q6a [9]

(b) The ValidatePassword function will be tested.

(i) Give a valid password that can be used to check that the function returns TRUE under the correct
conditions.
Q6bi [1]

(ii) The password entered is modified to test each rule separately so that the function results FALSE.

Give four modified passwords and justify your choice.


Q6bii [4]

(iii) When testing the ValidatePassword function a module it is necessary to test all possible paths
through the code including all internal structures.

State the name given to this type of validation testing.


Q6biii [1]

(iv) A program consisting of several functions can be tested using a process known as ‘stub testing’

Explain this process.


Q6biv [2]
7 LogArray is a 1D array containing 500 elements of type STRING.

A procedure, LogEvents, is required to add data from the array to the end of the existing text file
LoginFile.txt

Unused array elements are assigned the value "Empty". These can occur anywhere in the array and should
not be added to the file.

Write pseudocode for the procedure LogEvents.

Refer to the Insert for the list of pseudocode functions.


Q7 [8]

The total mark for this assignment is 75

END OF ASSIGNMENT
Please submit your work to your tutor by following the instructions in the study guide. When marked, you
will receive both your final score and feedback from your tutor.

You might also like