SDD - Implementation Flashcards

(94 cards)

1
Q

What is the primary purpose of a 1-D Array?

A

It allows programmers to store data in a list, provided that all the data is of the same data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an “Index” in an array and what is its starting value?

A

An index is used to identify each variable in the list. The index always starts at the value 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three things you must define when creating a 1-D array?

A
  1. An appropriate name. 2. The data type for the array. 3. The number of elements (index) to be held.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Using a programming language of your choice write code to create an empty array which contains the name of 8 scottish cities.

A

Python: scottishCites = [” “]*8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The ‘scottishCities’ array is populated with city data in this order Edinburgh, Glasgow, Dundee.
Aberdeen, Inverness, Perth, Stirling, Dunfermline

What possition/index in the array are the following cities Edinburgh & Inverness

A

Edinburgh: 0

Inverness: 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

An array called ‘scottishCities’ stores the name of the all the cities in Scotland, Using a programming language of your choice write code to loop through the array and print the name of each city

A

for counter in range(len(scottishCities):
print(scottishCities[counter])

Note: print statement must be indented.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If you declare an empty array of records for 7 items, what is the index range?

A

0 to 6.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Global Variable?

A

A variable accessible by every sub-program at all times, retained in RAM throughout the entire execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Local Variable?

A

A variable declared within a specific sub-program, accessible only there, and existing in RAM only while that sub-program runs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference in Scope between a global and a local variable?

A

Global Variable - Scope: The entire program. Local Variable - Scope: Only the sub-program where it was declared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why do Global Variables place a greater demand on system resources?

A

They are retained in memory (RAM) for the entire duration of the program’s execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why are Local Variables considered more efficient for system resources?

A

They are only held in RAM during the execution of their specific sub-program (only use while the function or procedure is running).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the main danger regarding data integrity when using Global Variables?

A

They are susceptible to accidental change by any part of the code, which can cause errors elsewhere.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens when a main program “calls” a sub-program(module)?

A

The main program pauses to run the code contained within that specific sub-program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a Procedure?

A

A sub-program designed to perform a series of commands. It does not primarily exist to return a single value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the defining characteristic of a Function?

A

It is a sub-program designed to always return a single value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a Pre-defined Function?

A

A function built into the software language (e.g., Modulus, Random) that does not need to be created by the programmer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

State 2 advantages of using pre-defined functions in your code?

A

Faster Development time - programmers do not need to create code from scratch.
Reliability: Predefined functions have been thoroughly tested to preform the tasks they were created for.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the Modulus (MOD) function calculate?

A

The remainder of a division operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the output of ‘7 MOD 2’?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What symbol is used to calculate the Modulus (remainder) of 2 numbers in Python?

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

A factory manufactures tennis balls and packs them into tubes. The machine packs the tubes with a specific number of balls, but sometimes the total batch of balls doesn’t divide perfectly, leaving some “loose” balls on the conveyor belt.

For example, if the factory made 100 balls and the tubes hold 3 balls each, the machine would fill 33 tubes, and there would be 1 ball left over.

Write a program that asks for the total number of tennis balls manufactured and the capacity of the tubes, then displays how many loose balls are left over.

A
#Input: Ask for the total number of items
total_balls = int(input("Enter the total number of tennis balls made: "))

#Input: Ask for the size of the container
tube_capacity = int(input("Enter how many balls fit in one tube: "))

#Calculation: Use Modulus (%) to find the remainder
leftover_balls = total_balls % tube_capacity

#Output: Display the result
print("There are "+str(leftover_balls) + "loose balls left over.") 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the purpose of the round predefined function?

A

To round a number to the appropriate number of decimal points

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Using a programming language of your choice, write a program which:

asks the user to enter the length and breadth of a rectangle
calculates the area of the rectangle to 1 decimal place

A

The syntax is round(number, number_of_digits)

#length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))

#Calculate the area
area = length * breadth

#Round the area to 1 decimal place using the round() function
rounded_area = round(area, 1)

#Display the result
print("The area of the rectangle is:" + str(rounded_area))

This would also work :rounded_area = round((length * breadth), 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does the Substring function do?
It extracts a specific part of a string based on a starting index and length.
26
The user name is stored in a varriable called user_name. Using a programming language of your choice write code which will create a new varriable an save the 1st letter of the name:
``` #using the substring (both options work) first_letter = user_name[0] or first_letter = user_name[0:1] ```
27
The user name is stored in a varriable called user_name. Using a programming language of your choice write code which will create a new varriable an save the first 3 letter of the name:
``` #using the substring first_letters = user_name[0:3] ```
28
The user name is stored in a varriable called user_name. Using a programming language of your choice write code which will create a new varriable an save the last letter of the name:
``` #using the substring last_letter = user_name[-1] or last_letter = user_name[0:1] ```
29
The user name is stored in a varriable called user_name. Using a programming language of your choice write code which will create a new varriable an save the last 4 letters of the name:
``` #using the substring last_letters = user_name[-4:] ```
30
What is the purpose of the random predefined function
The random function returns a random number between two parameters.
31
Using a programming language of you choice write code return a random number between 10 and 30 and save it in a variable called bonus
``` # Pick a random number between 10 and 30 import random bonus = random.randint(10, 30) ```
32
What is the purpose of the length predefined function?
The length function returns the length of a string or an array
33
Using a programming language of you choice write code to save the length of the animals array and store it in a new variable called arrayLen
``` arrayLen = len(animals) ```
34
Using a programming language of you choice write code to save the length of the user name stored in the variable userName to a new variable called nameLen
``` nameLen = len(userName) ```
35
What does the 'ord()' function do?
It returns the ASCII code for a given character (e.g., ord('b') returns 98).
36
Given a variable named firstChar that contains the first character of a word, using a programming language of your choice write code that retrieves the ASCII value of this character and stores it in a new variable
``` # Store the ASCII code in a new variable asciiCode = ord(firstChar) ```
37
A program stores an integer representing an ASCII code in a variable called asciiCode. Using a programming language of your choice, write code to convert this integer back into its corresponding character and store it in a new variable called character.
character = chr(asciiCode)
38
What does the 'chr()' function do?
It returns the character corresponding to a given ASCII code (e.g., chr(98) returns 'b').
39
Explain what this code does? `x = int(3.225)`
The code converts the floating-point number 3.225 into the integer 3 and stores the result in variable x.
40
Write a program that asks the user to input the current speed of a car as a precise decimal number (e.g., 65.8 mph). The program should convert this number to an integer and store the interger'.
``` # Ask user for input as a float exact_speed = float(input("Enter the exact speed reading: ")) Convert to integer (truncates the decimal) display_speed = int(exact_speed) ```
41
What are the standard algorithms you must be able to analyze and exemplify?
1. Input validation, 2. Find minimum, 3. Find maximum, 4. Count occurrences, 5. Linear search, 6 Running Total, 7. Traversing through an array.
42
Why is it important to use meaningful identifiers (variable names) in an algorithm?
It avoids confusion and allows others to understand the code (e.g., using 'minimum' instead of 'x').
43
What is the purpose of an Input Validation algorithm?
To ensure that data entered by a user is acceptable (e.g., within a range) before processing.
44
Write the main steps of the Input Validation Standard Algorithm
The steps of this algorithm are: 1. Ask the user to input something 2. Start a while loop, while the input does not meet the condition (e.g. while age < 15) 3. Show an error message 4. Ask the user to input (again) 5. End while loop
45
Which specific type of loop is used for input validation?
A Conditional Loop (WHILE loop).
46
'WHILE score [counter] < 0 OR score [counter] > 50 DO ......', when does the loop body (DO.....) execute?
Only if the input is invalid - the current score is less than 0 or greater than 50
47
Write a program that asks the user to input a quantity. The program must validate this input to ensure it falls between 100 and 500 (inclusive). If the user enters a value outside this range, the program should ask them to re-enter the value until it is valid.
``` quantity = int(input("How many would you like") #Check (too small OR too big) while quantity < 100 or quantity > 500: quantity = int(input("You need to enter a quantity between 100 and 500: ")) ```
48
Explain why the input validation shown would not work ``` score = int(input("Please enter your score") Check (too small OR too big) while score < 0 or score > 50: print("Your score should be between 0 and 50 ")) ```
The score variable is not updated. Without it, the invalid value remains unchanged, causing an infinite loop.
49
In the Reference Language example for 5 dancers, why does the loop run 'FOR counter FROM 0 TO 4'?
Because array indexing typically starts at 0, so the 5th item is at index 4.
50
In the Python code 'for counter in range(5):', what values will 'counter' take?
0, 1, 2, 3, 4.
51
Why does Python use 'int(input(...))' instead of just 'input(...)'?
input() returns a String. It must be cast to an Integer to compare it mathematically.
52
Write the steps for the traversing a 1-D array standard algorithm
1. Start a for loop, for the number of elements in the array 2. Use the array element[counter] to perform action on array element (e.g print) or check a condtion then print 3. End the for loop
53
Using a programming language of your choice, write code which will loop through and print out every value stored in an array called names.
``` #1. Start a for loop, for the all elements in the array for counter in range (len(names)): #2. use the array element[counter] to perform action print(names[counter]) #3 End of Loop ```
54
Using a programming language of your choice, write code which will loop through and print out every value stored in an array called names.
``` #1. Start a for loop, for the all elements in the array for counter in range (len(names)): #2. use the array element[counter] to perform action print(names[counter]) #3 End of Loop ```
55
Explain, the use of counter and shopping[counter] in the code below: ``` for counter in range (len(names)): print(names[counter]) ```
counter: Represents the index number (position) in the loop/list starting from position 0 (e.g., 0, 1, 2...). names[counter]: Uses that index number to retrieve the actual item stored in the array at that position. The 1st time through the loop the counter would = 0, names[counter] would be names[0] this is printed on the screen.
56
What is the specific purpose of the "Finding Maximum" algorithm?
To iterate through an array and identify the highest value stored within it.
57
Write the steps for the find maximum standard algorithm
1)Declare a maximum variable, and set it to the first item in the array (e.g. 33) 2)Loop for each element in the array 3) If number(counter) > maximum 4) Set maximum to number(counter) 5) End if 6)End for loop
58
Write the steps for the find minimum standard algorithm
1)Declare a minimum variable, and set it to the first item in the array. 2)Loop for each element in the array 3) If number(counter) < minimum 4) Set minimum to number(counter) 5) End if 6)End for loop
59
An array called temps contains a list of temperatures using a programming language of your choice write code which will find the highest temperature in the array
set maximum = temps[0] for count in range(len(temps): if temp[counter]>maximum: maximum = temp[counter]
60
An array called prices contains a list of prices using a programming language of your choice write code which will find the lowest price in the array
set minimum = prices[0] for count in range(len(temps): if temp[counter]>minimum: minimum = temp[counter]
61
a)Explain what this line of code does in the finding max standard algorithm. 'IF testscore[counter] > maximum'? b) What would happen next?
a) Checks if the current item is larger than the value currently held in the 'maximum' variable. b) The 'maximum' variable is updated to equal the new, higher value found.
62
In Python 'maximum = testscore[0]', why initialize with the first item?
To ensure the comparison starts with a value that exists in the list (handles negative numbers correctly).
63
What assumption is made about the array before the Max algorithm runs?
That the array has already been populated with values.
64
What is the specific purpose of the "Finding Minimum" algorithm?
To iterate through an array and identify the lowest value stored within it.
65
Why is 'minimum' initialized to 'testscore[0]' rather than a number like 0?
If the array has numbers > 0, initializing to 0 gives the wrong answer. Using the first item is safer.
66
What is the key difference in the conditional statement between Finding Max and Finding Min?
Max uses > (greater than). Min uses < (less than).
67
What is the purpose of the "Count Occurrences" algorithm?
To iterate through an array and count how many times a specific value appears.
68
Write the steps for the count occurrence standard algorithm.
1)Set count to 0 2)Input target 3)For counter/index from 0 to length of Array 4) If names(counter/index) == target then 5) Set count to count + 1 6) End if 7)End for loop 8)Display count
69
An array named firstNames contains the names of students in a school. Using a programming language of your choice, write code that asks the user to enter a name. The program must count how many times that name appears in the array and output a message in the following format: "There are 10 students called Sam"
# 2 Input target count = 0 target = input("Enter a search Name: ") for index in range(len(firstNames)): if firstName[index] == target: count = count + 1 print("There are "+str(count)+ " students called "+target)
70
An array named firstNames contains the names of students in a school. Using a programming language of your choice, write code that asks the user to enter a name. The program must count how many times that name appears in the array and output a message in the following format: "There are 10 students called Sam"
# 2 Input target count = 0 target = input("Enter a search Name: ") for index in range(len(firstNames)): if firstName[index] == target: count = count + 1 print("There are "+str(count)+ " students called "+target)
71
What is the purpose of a Linear Search algorithm?
To search through an array one item at a time to find a specified value.
72
Write the step to the linear search standard algorithm.
1)Set found to false 2)Input target 3)FOR counter FROM 0 TO length(array) 4) IF array [counter] = choice: 5) found = TRUE 6) position = counter (optional) 7) END IF 8) END FOR Note after the linear search has been run and If else statement is used to output the results (found/not found)
73
Using a programming language of your choice write code to see if, the name Bob is stored in the firstNames array. Then confirm if the name is stored in the array
found = False target = "Bob" for counter in range(len(firstNames)): if firstName[counter] == target: found = True if found is False: #(boolean value) print(target + " was found in the array") else: print(target + " was not found in the array")
74
Describe what a Record
A record is a programmer defined data structure which is used to combine multiple data objects of different types.
75
Create a basic record structure template using python
``` from dataclasses import dataclass @dataclass class recordName: field category 1: datatype ' 'field category 2: datatype ' 'field category 3: datatype ect..```
76
Create a basic record structure template using python
from dataclasses import dataclass @dataclass class recordName: field category 1: datatype field category 2: datatype field category 3: datatype ect..
77
StreamBeat is an app that allows users to manage their music library and view song details. The app stores the following details about each song: Song title Artist name Duration (in seconds) Genre Is Explicit (True/False) Question: Using a programming language of your choice, define a suitable record structure to store the data for a song.
from dataclasses import dataclass @dataclass class song: title : str ArtistName : str Duration: int genre : str explicit: bool Note: Any sensible names would be acceptable
78
AutoLot is a system used by a car dealership to keep track of vehicles currently for sale on the lot. The system stores the following details about each vehicle: Manufacturer (e.g., Ford) Model name Year of manufacture Mileage Selling price A: Using a programming language of your choice, define a suitable record structure to store the data for a vehicle. B: Using a programming language of your choice, declare an array of 5000 vehicles using the record structure from (a)
A) from dataclasses import dataclass @dataclass class vehicle: manufacturer : str model : str year: int mileage : intB price: float Note: Any sensible names would be acceptable B) vehicles = [vehicle() for x in range (5000)] Note: Any sensible names would be acceptable: class name must match name() used to create the array of records
79
StayFinder is a website that lets users browse available hotel rooms and see their specifications. The website stores the following details about each room: Room number Floor number Bed type (e.g., "King", "Twin") Nightly rate (cost per night) Has sea view (True/False) Question: Using a programming language of your choice, define a suitable record structure to store the data for a room.
from dataclasses import dataclass @dataclass class room: roomNum : int floorNum : int bedType: str rate : float seaview: bool Note: Any sensible names would be acceptable
80
Using a programming language of your choice, declare an array which can store 50 rooms using the room record structure.
rooms = [room() for x in range (50)] Note: room() was give in this question, in the exam you are likely to have created the record structure in the part of the question before this step
80
Using a programming language of your choice, declare an array which can store 20 tracks using the song record structure.
tracks = [song() for x in range (20)] Note: song() was give in this question, in the exam you are likely to have created the record structure in the part of the question before this step. Any sensible wording choice could replace tracks
81
What is the syntax/code used to create a variable which will store an array of records
arrayName = [recordName() for x in range (numRecords)]
82
What is the general syntax pattern used to access a specific piece of data within an Array of Records?
ArrayName[Index].FieldName It combines the name of the array, the specific position (index) of the record, and the specific field you want to retrieve.
83
Question: In the example Games[0].title, what does the 0 represent?
Answer: It refers to the 1st game in the array. Remember: Array indexing starts at 0. So, Index 0 is Position 1.
84
Using the syntax rules, how would you write the code to access the Rating of the 3rd game in an array named Games?
Games[2].rating
84
What will the following code snippet output? for index in range(len(games)): print(games[index].title)
It will print the Title of every game in the entire games array of records
85
A records structure about book as the following fields - title, author, category and price. An array of records called books has been created. Using a programming language of your choice write code which will output the name of all history(category) books where this price is £9.99 or less.
for x in range(len(books): if books[x].category =="history" and books[x].price <= 9.99: print(books[x].title)
86
What are the 3 steps which you need to perform when using a file
1)Open a connection to the file 2)Read or write from the file, as desired 3)Close the file
87
a program has calculated a quote for a job and stored it in a varriable called estimate, the program should then save this variable into a file called quote.txt, using a design techique of your choice write the steps to enable this to happen
open file quote.txt write estimate to file quote.txt close file quote.txt
88
using a programming language of your choice write code save the information currently stored in the highScore variable to a file called score.txt
file = open("score.txt", "w") file.write(highScore) file.close()
89
using a programming language of your choice write code save the information currently stored in the score.txt file to a variable called highScore.
file = open("score.txt", "r") highScore =file.read() file.close()
89
A variable named user_password holds a string entered by a user. Write an algorithm using pseudocode to read a stored password from a text file named psw.txt. Compare the file contents with user_password and output a message indicating whether the passwords match or not.
OPEN file "psw.txt" READ stored_pass from file CLOSE file IF user_password = stored_pass THEN OUTPUT "Password Match" ELSE OUTPUT "Password Incorrect" END IF
90
Using a programming language of you choice create code which will read data from a file called data.csv, then allow each line of data to be splint into parts. After this step the data parts could be stored into either a parallel array or an array of records
1st Step read data from the file #open file file = open("gameData.csv", "r") #store each line in an array called line lines = file.readlines() file.close() #loop through each line in the lines array for i in range(0, len(lines)): #split each line by (,) and store in parts array parts = lines[i].split(",")
91