T7 - Records and files Flashcards

1
Q

data structure

A
  • is a collection of elementary data types such as integer, real, Boolean, char or string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

record -

A

is a data structure consisting of a number of fields which can all be of different types

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

field

A
  • is a single item of data in a record
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A file -

A

is able to store a collection of records
only data type is “string”

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

CSV (comma-separated values) file:

A

Each record is on a new line
Each field is separated by a comma

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

with any text editor

A

you can create, read and print a CSV file

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

Create a new file: code

A

names = newFile(“names.txt”)

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

Write mode –

A

allows writing to a file

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

Append mode –

A

allows more data to be added to a file

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

Read mode

A

– only allows the file to be read

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

Reading:

A

from a text file involves
opening the file, processing each line
then closing the file

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

Here is an algorithm which writes to a text file:

A

marksFile = open(“marks.txt”)
name = input(“Input student name: “)
mark = input(“Input student mark: “)
marksFile.writeLine(name + “,” + mark + “\n”)
marksFile.close()

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

“\n”

A

is the newline character indicating then end of this record

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

After opening, must close a file why?

A
  • frees up any memory used by having it open
  • Once closed, the file cannot be read from or written to without opening it again
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

To close a file, use: code

A

myFile.close()

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