What does declarative programming focus on?
Defining what a program should achieve rather than defining the method of achieving the desired output
What does Imperative Programs define?
Exactly the steps that a computer will execute to achieve a specific result
What do programs in Prolog consist of?
Facts and Rules
What is a knowledge base?
Combination of the facts and rules in prolog
What is Recursion?
A programming technique where a sub-program repeatedly calls itself
In what type of programming languages is recursion used?
Declarative and Imperative Programming Styles
What is passing by reference?
Passing the real copy of the parameter, changes to this parameter will be proper changes
What is passing by value?
Any changes to the parameter will not be carried onto the real value
Write the pseudocode for the Fibonacci sequence
def Fibonacci(n): If n < 2: return n else return Fibonacci(n-1) + Fibonacci(n-2)
Give some advantages of recursion
Give some disadvantages of recursion
What are the operations that can performed on a sequential file?
What is a sequential file identified by?
Identified by a path and a filename
Describe a sequential file
What is the difference between append and read/write functions for sequential file?
Append allows data to be added to the file without it being read into memory first
Write pseudocode for writing (a set of string values)to a new sequential text
file from an array
Procedure writeFile(name): DECLARE myFile INITIALLY "N://myFile.txt" CREATE myFile OPEN myFile FOR counter FROM 0 to End of Array DO SEND names[counter] to myFile END FOR CLOSE myFile END Procedure
Write pseudocode for reading (a set of string values) from a sequential text file into
an array
PROCEDURE ReadFile(name) DECLARE myFile INITIALLY "N://myFile.txt" OPEN myFile FOR counter FROM 0 to End of File DO Receive names[counter] from myFile END FOR CLOSE myFile END PROCEDURE
Describe a random file
A file which stores data in a way which allows it to be retrieved from any place in the file without needing to read through the entire file
Data is indexed in a way which allows each item to be uniquely identified
What are random files frequently used to store?
Records
Give three advantages to random files?