Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Computer Science

2023-2024

Homework - Algorithms

Question 1

A delivery company sends parcels across the UK, and charges on the following basis:

• Parcels that smaller than 0.3 m3 and lighter than 4 kg cost £5 to send.

• All other parcels cost £20 per m3 or £2 per kg, whichever is greater.

Write a pseudocode that takes in the volume and weight of a parcel as input and then outputs the correct cost. Sample input and outputs:

Weight: 2.5, Volume = 0.1, Sample output 5

Weight: 6, Volume = 0.2, Sample output 12

Weight: 6, Volume = 0.8, Sample output: 16

Question 2

Sally is a classroom teacher. She would like a program to be able to organise where students will sit in her classroom.

A plan of her class is shown in Fig 1.

a) State two ways that Sally has made use of abstraction in Fig. 1.

b) Explain one benefits to Sally of using abstraction before creating the programming code.

c) Sally written the following pseudocode to increase the security of her program by adding a password to enter the program.  

01 CorrectPassword ß "ComputerScience12"

02 Check ß FALSE

03 WHILE Check = FALSE

04 INPUT EnteredPassword

05 IF EnteredPassword = CorrectPassword

06 THEN

07 Check ß TRUE

08 ENDIF

09 ENDWHILE

Rewrite above line of pseudocodes using a post-conditional loop.

Question 3

A meteorologist sets up a weather station to monitor temperatures throughout the year. She classifies temperatures in one of four bands:

 

The weather station records the temperature every day of the year as an integer. At the end of the year the temperatures are stored in an array called temperatures. Assume that there are 365 days in a year. An example of the array temperatures will be similar to:

5, 7, 8, 10, 9, 12, 15, 18, 17, 17, 14……

An example of such an output is shown below:

Band A: 93

Band B: 143

Band C: 98

Band D: 31

Write a pseudocode that reads through this array and produces an output which shows the total number of days within each band.

Question 4

A 2-dimensional (2D) array called data holds numeric data that Kari has entered. The declaration for the array is:

DECLARE data: ARRAY [0:15,0:10] OF INTEGER

 

The data in each ‘row’ is in ascending numerical order.

a)   Karl needs to output the median value of each ‘row’ of the array. The median is found by having all the numbers in a row in ascending numerical order and taking the middle value. For example, in Fig 1.2 below, the median element in the row is the third element, so the median value is 7.

 

a) Write an algorithm in the form of pseudocode to output the median value of each ‘row’ of the 2D data.

b)  Karl needs to find the mean average of each ‘column’ of the array. The mean value is calculated by adding together the numbers in the column and then dividing by the quantity of numbers in the column. For example, in Fig. 1.3 the first ‘column’ mean value would be: (1+3+0+12)/4 = 4

Write an algorithm to output the mean value of each ‘column’ in the array data.

Question 5

FOR I ß 1 to Number 

OUTPUT I * I 

NEXT I 

Draw a flowchart to represent the algorithm above

Draw shapes neatly, write statements clearly to avoid losing marks.