1.2 Flashcards
1.2.4
1) What is string manipulation?
2) What is the command to get a string length?
3) What is the command to extract part of a string?
1) The act of manipulating, extracting, or changing the characters in a string variable.
2) To get the length of the string: stringName.length
3) To extract part of a string: string.substring (starting position, number of characters)
1.2.4
1) What is a procedure?
2) What is a function?
3) How does a return value work?
1) A procedure is a named block of code that performs a task, but does not return a value.
2) A function is a named block of code that returns a value.
3) A return value can be used directly without being assigned to a variable first. Some programming languages allow just one value to be returned, while others support multiple return values.
1.2.4
1) What is a local variable?
2) Can local variables have the same identifier?
1) A local variable is a varible that is only accessible within a specific part of a program. These variables are usually local to a subroutine and are declared or defined within that routine.
2) Local variables in different subroutines are allowed to have the same identifier (name). Each variable’s data is stored in separate places in main memory, so changing the value of a local variable one subroutine will not affect the value of any local variables with the same identifier in their subroutine
1.2.4
1) What is a global variable?
2) Is it better to use local or global variables?
1) A global variable can be accessed anywhere in a program for the duration of the program’s execution. A global variable has a global has a global scope.
2) Programs using global variables are more difficult to debug, as the variables can be updated in any part of the program. It is almost always better to use local variables and to pass values between subroutines to avoid errors caused by unforeseen changes.
1.2.4
1. Define encapsulation
2. Define instantiation
3. Define inheritance
- Encapsulation is bundling together attributes and methods into a class.
- Instantiation is the process where classes provide blueprints for objects.
- Inheritance is a mechanism that allows an instance of a class to inherit attributes from another class — the parent class.
1.2.4
1. Define subclass
2. Define superclass
3. Define polymorphism
- A subclass is a class that inherits from another class.
- A superclass is the class from which the subclass inherits attributes and methods from.
- Polymorphism is the ability of an entity such as a variable, method or object to have more than one form.
1.2.4
1. Define overloading
2. Define overriding
3. What are the advantages of inheritance?
4. What are the disadvantages of inheritance?
- Overloading is where methods have the same name but different signatures. The signature can differ by the number of parameters, the type of parameters, or both. For example, there can be a function that has one output if the parameter is a string, and the same function can have a different function if the parameter is an integer.
- Overriding is where an inherited method is superseded by a method defined in the subclass. In OOP, this is where the ability for classes that share a common superclass to have different implementations of a method with the same name.
- Reusability and readability. When a child class inherits the properties of a parent class, there is no need to rewrite the code.
- When you inherit from another class, you have coupled the two classes. If the parent class is edited, there could be unwanted or unknown changes to the attributes and methods in the child class.
What is the process for file handling?
- Open the file for reading data,
- Assign a Boolean variable to FALSE to indicate that the end of the file is not reached. While the end of the file is false and the search item is not found:
a. Read the data from the file.
b. If the data matches what is being searched for, assign the data to the variables or output.
c. Check if the end of the file has been reached and assign the Boolean variable to true. - myFile = openWrite(“sample.txt’)
myFile.writeLine(“Hello World”)
myFile.close()
- What is the pseudocode to open a file and read one line?
- What is the pseudocode to write text to a text file?
- myFile = openRead(“sample.txt”)
x = myFile.readLine()
myFile.close()
What is the pseudocode to print all the lines of a text file?
myFile = openRead(“sample.txt”)
while NOT myFile.endOfFile(
print(myFile.readLine()
endwhile
myFile.close() - What is the pseudocode to write text to a text file?
- What is the pseudocode to open a file and read one line?
- What is the pseudocode to write text to a text file?
- myFile = openRead(“sample.txt”)
x = myFile.readLine()
myFile.close()
What is the pseudocode to print all the lines of a text file?
myFile = openRead(“sample.txt”)
while NOT myFile.endOfFile(
print(myFile.readLine()
endwhile
myFile.close() - What is the pseudocode to write text to a text file?