Programming Fundamentals Flashcards
What is a data type?
The kind of values that can be used in a data item
What are some examples of data types?
Integer, float/real, character, string, Boolean
What are arithmetic operators?
A symbol that will perform an operation on numbers
What are the arithmetic operators?
+, -, *, /, ^, MOD, DIV
What is ^
Exponent (power of)
What data type is the variable ‘numberOfStudents’
Integer
What data type is the variable ‘circleArea’
Real/Floating point number
What data type is the variable ‘found’
Boolean
What data type is the variable ‘answer’
Character
What data type is the variable ‘studentName’
String
What type of data is a char
A single ASCII character such as A, b, 3, ! or space
What type of data is a string
Zero or more characters
What can you define other than variables
Constants
What are some examples of constants
const PI = 3.14157926535
const VAT = 0.2
const MAX_PLAYERS = 6
What is snake case
Words that are separated with an underscore, e.g. MIN_AGE
Why declare a constant instead of a variable?
This prevents the value from being changed accidentally by a part of code
It shows a programmer that the value should stay the same throughout the program
Can a constant ever change its value?
A constant cannot be changed when the program is running
A constant can be changed by a programmer before the program is compiled or translated
What is DIV used for
Integer division, also known as quotient
e.g. 31 DIV 7 = 4 (remainder 3)
What is MOD (modulus) used for
Used to find the remainder when dividing one integer by another
e.g. 31 MOD 7 = 3 (remainder)
What is MOD (modulus) used for
Used to find the remainder when dividing one integer by another
e.g. 31 MOD 7 = 3 (remainder)
What is represented differently in binary
Strings and numbers
What is the string “17” represented in binary as
0011000100110111
What is the integer 17 held in binary as
00010001
What are functions/casting
They are used to convert data types
What does the function int(s) do (written in pseudocode)
converts a string s to an integer
What does the function float(s)/real(s) do (written in pseudocode)
converts a string s to a number with a decimal point
What does the function str(x) do (written in pseudocode)
converts an integer or floating point number x to a string
What does the function bool(s) do (written in pseudocode)
converts a string (e.g. “True”) to a Boolean
What does the function ASC(‘a’) do (written in pseudocode)
evaluates to 97, using ASCII
What does the function CHR(97) do (written in pseudocode)
evaluates to ‘a’
What is wrong with the variable tickets = input(“Please enter number of tickets required: “)
You need to convert the variable to an integer, as the inputs from the user are strings e.g. tickets = int(tickets) or tickets = int(input(“Please enter number of tickets required: “))
What is concatenating
Means joining together strings
e.g.
firstname = “Rose”
surname = “Chan”
fullname = firstname + “ “ + surname
print(fullname)
output = Rose Chan (not part of code)
x = “6” + “3”
print(x)
output = “63” (not part of code)
Examples of string handling functions
word = “Algorithm”
print(word.length) = 9
print(word.substring(3,6)) = “orit”
print(word.left(3)) = “Alg”
print(word.right(4)) = “ithm”
zooName = “London Zoo”
zooName.length = 10
zooName.substring(1,4) = ondo
zooName.left = London Z
zooName.right(5) = n Zoo
How can characters be converted to their ASCII value and vice versa?
Using the functions: ASC(character) and CHR(integer)
e.g.
x = ASC(‘a’) // sets x = 97
y = CHR(97) // sets y to ‘a’
How can I convert a string to uppercase or lowercase?
phrase1 = “Good morning”
phrase2 = “HAPPY BIRTHDAY”
print(phrase1.upper) //”GOOD MORNING”
print(phrase2.lower) //”happy birthday”
Why should I use comments in my programs?
to describe the purpose of the program
to state the author of the program
to explain what the code does
How do comments start in different languages?
Pseudocode - //
Python - #
Visual Basic - ‘