PSEUDO CODE Flashcards

(10 cards)

1
Q

Iteration – Count controlled

A

FOR I = 0 to 7
PRINT(“Hello”)
NEXT i
This would print hello 8 times (0-7 inclusive).

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

Iteration – Condition controlled

A

WHILE answer != “computer”
answer = INPUT(“What is the password?”)
ENDWHILE While Loop

DO
Answer = INPUT(“What is the password?”)
UNTIL answer == “computer” Do Until Loop

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

Subroutines

A

FUNCTION triple(number)
RETURN number * 3
ENDFUNCTION

Called from main program

Y =triple(7)

PROCEDURE greeting(name)
PRINT(“hello” + name)
ENDPROCEDURE

Called from main program

greeting(“Hamish”) Procedure

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

Arrays / Lists

A

ARRAY names[5]
names[0] = “Ahmad”
names[1] = “Ben”
names[2] = “Catherine”
names[3] = “Dana”
names[4] = “Elijah”
PRINT(names[3])

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

To open a file to read you should use OPENREAD.
READLINE should be used to return a line of text from the file.

A

myFile = OPENREAD(“sample.txt”)
x = myFile.READLINE()
myFile.CLOSE()

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

will print out the contents of sample.txt

A

myFile = OPENREAD(“sample.txt”)
WHILE NOT myFile.ENDOFFILE()
PRINT(myFile.READLINE())
ENDWHILE
myFile.CLOSE()

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

To open a file to write to openWrite is used and writeLine to add a line of text to the file

A

myFile = OPENWRITE(“sample.txt”)
myFile.WRITELINE(“Hello World”)
myFile.CLOSE()

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

Methods and attributes

A

PUBLIC and PRIVATE

PRIVATE attempts = 3

PUBLIC PROCEDURE setAttempts(number)
attempts = number
ENDPROCEDURE

PRIVATE FUNCTION getAttempts()
RETURN attempts
END FUNCTION

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

Declaring a class

A

CLASS Pet
PRIVATE name
PUBLIC PROCEDURE NEW(givenName)
Name = givenName
ENDPROCEDURE
ENDCLASS

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

Inheritance

A

CLASS dog INHERITS Pet
PRIVATE breed
PUBLIC PROCEDURE NEW(givenName, givenBreed)
SUPER.NEW(givenName)
Breed = givenBreed
ENDPROCEDURE
ENDCLASS

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