Data Types And Databases (Ch4) (M2) Flashcards

1
Q

When programming, what should variables be given?

A

Variables should be given appropriate data types

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

What are the advantages of using the correct data types for variables?

A

Using the correct data types makes code more memory-efficient, robust and predictable.

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

What are the 5 main types of variable?

A

The five main types are:

Integer
Real (or Float)
Boolean
Character
String

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

What is a character?

A

A character is a single character, such as a letter, number or punctuation symbol

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

What is a string?

A

A string is a sequence of characters, including letters, numbers and punctuation

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

What is an integer?

A

An integer is a whole number

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

What is a real?

A

A real is a decimal number

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

What is a boolean?

A

A boolean is an answer that only has two possible values

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

What data type are telephone numbers stored as? Why?

A

Telephone numbers are always stored as a string, not an integer because they may include other symbols like “+” for example.

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

How much memory does an integer take up?

A

An integer takes up 2 bytes or 4 bytes

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

How much memory does a real take up?

A

A real takes up 4 bytes or 8 bytes

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

How much memory does a boolean take up?

A

A boolean takes up 1 bit, but 1 byte is usually used

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

How much memory does a character take up?

A

A character takes up 1 byte

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

How much memory does a string take up?

A

A string takes up 1 byte for every character in the string

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

What is casting?

A

Casting is converting a variable from one data type to another.

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

Give two examples of functions that let you manually convert between data types?

A

Languages have functions that let you manually convert between data types:

This can be done using:
int()
real() (or float())
bool()
str()

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

What does int(“1”) do?

A

Int(“1”) converts the string “1” to the integer 1

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

What does real(1) do?

A

Real(1) converts the integer 1 to the real number 1.0

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

What does bool(1) do?

A

Bool(1) converts the integer 1 to the boolean value True

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

What does str(True) do?

A

Str(True) converts the boolean value True to the string “True”

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

Give five examples of common arithmetic operators

A

+

Arithmetic operators:

*
/

MOD
DIV

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

What does modulus/MOD mean?

A

Modulus is how many whole numbers are left over after a division, e.g 5 MOD 26 = 1.

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

What does integers division/DIV do?

A

Integers Division/Quotient is how many times the number on the right fits into the number on the left. e.g 7 DIV 2 = 3, 2 goes into 7, 3 times.
However you only mention the remainder in Modulus.

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

What is exponentation?

A

Exponentiation is when one number multiplies by itself, the amount of times this is done, depends on the number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is 9 MOD 2
9 MOD 2 = 1
26
What is 12 DIV 8?
12 DIV 8 = 1
27
Give five examples of comparison operators
Comparison operators: == <> or != < > <= >=
28
What is the assignment/comparison operator "=" used for?
The assignment/comparison operator "=" is used to assign values to constants or variables.
29
What do comparison operators do?
Comparison operators compare the expression on their left-hand side to the expression on their right-hand side and produce a Boolean value (either true or false).
30
Using WHILE, how can you create an infinite loop?
To create an infinite loop, use: WHILE True
31
What are the three boolean operators?
Boolean operators: NOT AND OR
32
If you use AND, what needs to happen?
If you use AND, both things have to be true
33
What is NOT equivalent to?
NOT is equivalent to False For example: while not end_of_file This is the same as: end_of_file = false
34
What is assignment?
Assignment is giving a variable or constant a value
35
What is casting?
Casting is converting a variable from one data type to another
36
What is a variable?
A variable is a value that is stored in memory and can change as the program is running
37
What is a constant?
A constant is a value that is stored in memory and does not change as the program is running
38
What are the three programming constructs used to control the flow of a program?
There are three constructs of programming that are used to control the flow of a program: Selection (Decision making using statements) Sequence (Structuring code into a logical, sequential order) Iteration (Repeating code using for or while loops)
39
What are the two parts of a variable?
A variable has two parts: The data value and an identifier
40
In an efficient program, how will variables be used?
In an efficient program: Variables will have sensible names Variables will have appropriate data types The purpose of variables will be immediately stated in the program
41
Why is using clear variable names important?
Using clear variable names is important because it will mean that other programmers will be able to work out the purpose of the code, without the need for extensive comments.
42
Large programs are often modular. What does this mean?
Large programs are often modular, meaning they are split into subroutines with each subroutine having a dedicated purpose
43
What is the difference between a local and global variable?
Local variables are declared within a specific subroutine and can only be used within that subroutine. Global variables can be used at any point within the whole program.
44
Give one advantage of a local variable
Local variable advantages: Saves memory - it only uses memory when that local variable is needed - global variables use memory whether they are used or not. Easier to debug local variables - because they can be changed within one subroutine. You can reuse subroutines with local variables in other programs
45
Give one advantage of a global variable
Global variable advantages: Variables can be used anywhere in the whole programs (and in multiple subroutines). It makes maintenance easier as they are only declared once. They can be used for constants - values that remain the same.
46
Give one advantage of a constant
Advantages of constants: Make a program easier to read, as it is declared and assigned at the top of a program Can be easily changed in one place, instead of it changing a value throughout a program
47
What is the code to find the length of a string, in pseudocode and visual basic?
In pseudocode, it is written: stringName.length In VB it is written: stringName.length()
48
What is a substring?
A substring is a smaller part of a string
49
What is concatenation?
Concatenation is the proceess of joining two or more strings together
50
What is an array?
An array is a static data structure that can hold a fixed number of data elements.
51
What is always the index of the first number of an array?
The first number in an array always has an index of 0
52
What is the index?
The index is a number that indicates an element's position in the array
53
To traverse an array, what can be used to display each data element in order?
To traverse an array, a for loop can be used to display each data element in order
54
Because the size of an array is fixed, what two things can you not do?
Because the size of an array is fixed, you can't: Insert new values Delete values
55
Declare an array called cars, that stores 8 items
Array cars[8]
56
How can two dimensional arrays be represented?
Two dimensional arrays can be represented by a table
57
What must all the data in a two dimensional array have in common?
All the data in a two dimensional array must be the same data type
58
What do you need to use, to search for a specific value in a 2D array?
To search for a specific value in a 2D array, you need two for loops. One for the row and another for the values of each row.
59
What is the difference between an array and a database?
An array can only store one data type. Whereas, databases can store multiple data types.
60
What is a database?
A database is a table, or a collection of tables that store data.
61
What is the software that operates on data in a database called?
The software that operates on data in a database is called a database management system. (DBMS)
62
What is a table?
A table is a collection of data that relates to an entity
63
What is a record?
A record is a collection of data about a single entity
64
What is a field?
A field is a unique piece of data about an entity
65
What is a field name?
A field name is an identifier for the single piece of data
66
What is a query?
A query is where we search for data in a database.
67
What language is used to create, update, delete, and query a program's database?
SQL (Structured Query Language) is used to create, update, delete, and query a program's database
68
What does Create Table do?
Create Table creates a database table
69
What does Select do?
Select selects data in a database table
70
What does Update do?
Update changes data in a database table
71
What does Delete do?
Delete removes data from a database table
72
What does Insert Info do?
Insert Info inserts data into a database table
73
What is each record made up of?
Each record is made up of information about a person or thing
74
Records should have a key field. What is a key field?
A key field is unique data that identifies each record
75
Why are records useful?
Records are useful becasuse they can store values with different data types