Deck 10: Structures and Sequential Access Files
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/60
Play
Full screen (f)
Deck 10: Structures and Sequential Access Files
1
Programmers refer to a sequence of characters as a ____.
A)string of characters
B)stream of characters
C)file
D)variable
A)string of characters
B)stream of characters
C)file
D)variable
B
2
To access a member of a structure variable in an array,you use the syntax ____.
A)arrayName(subscript).memberVariableName
B)arrayName(subscript)->memberVariableName
C)arrayName(subscript)[memberName]
D)arrayName(subscript)@memberName
A)arrayName(subscript).memberVariableName
B)arrayName(subscript)->memberVariableName
C)arrayName(subscript)[memberName]
D)arrayName(subscript)@memberName
A
3
Data types created using the Structure statement are referred to as user-defined data types or structures.
True
4
You cannot include an array in a structure.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
5
You use the ____ member access operator to separate the structure variable's name from the member variable's name.
A)()
B)arrow
C)asterisk
D)dot
A)()
B)arrow
C)asterisk
D)dot
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
6
The Peek method,looks ahead into the file to determine whether the file contains another character to read.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
7
In Visual Basic,you use a(n)____ to write a stream of characters to a sequential access file.
A)CreateText method
B)StreamReader object
C)StreamWriter object
D)AppendText method
A)CreateText method
B)StreamReader object
C)StreamWriter object
D)AppendText method
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
8
When you pass a structure variable to a Sub or Function procedure,its member variables are not automatically passed.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
9
Files to which information is written are called input files.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
10
Files that are read by the computer are called ____ files.
A)storage
B)serial
C)input
D)report
A)storage
B)serial
C)input
D)report
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
11
The syntax used to declare a StreamWriter variable is ____.
A){Dim|Private} streamWriterVariableName IO.StreamWriter
B){Dim|Private} streamWriterVariableName As IN.StreamWriter
C){Dim|Private} streamWriterVariableName As IO.StreamWriter
D){Dim|Private} streamWriterVariableName As StreamWriter
A){Dim|Private} streamWriterVariableName IO.StreamWriter
B){Dim|Private} streamWriterVariableName As IN.StreamWriter
C){Dim|Private} streamWriterVariableName As IO.StreamWriter
D){Dim|Private} streamWriterVariableName As StreamWriter
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
12
Programmers use structure variables to store related items in an array,even when the items have different data types.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
13
A file to which information is written is referred to as a(n)____ file.
A)report
B)text
C)output
D)data
A)report
B)text
C)output
D)data
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
14
You can use the Strings.Space method to include a specific number of space characters in a string.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
15
Variables declared using a structure are often referred to as ____.
A)functions
B)Subs
C)structure variables
D)objects
A)functions
B)Subs
C)structure variables
D)objects
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
16
Most programmers use the Structure statement,rather than the Class statement,to create data types that contain procedures.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
17
You reserve memory locations by declaring a structure variable.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
18
The members of a structure can be variables,constants,or ____.
A)structures
B)classes
C)procedures
D)control characters
A)structures
B)classes
C)procedures
D)control characters
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
19
In addition to getting data from the keyboard and sending data to the computer screen,an application can also get data from and send data to a file on a disk.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
20
You can use the ____ to open a sequential access file for output.
A)CreateText method
B)StreamReader object
C)StreamWriter object
D)AppendText method
A)CreateText method
B)StreamReader object
C)StreamWriter object
D)AppendText method
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
21
You should use the ____ method to close a sequential access file as soon as you are finished using it.
A)Exit
B)Close
C)End
D)Quit
A)Exit
B)Close
C)End
D)Quit
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
22
You need to create a report using the pictureFrame.txt sequential access file.The report provides a list of all picture frames with a size of 5x7.The report will be saved as another sequential access file named pictureFrame57.txt.Your first step is to ____.
A)declare a StreamWriter variable for the output file
B)open the pictureFrame57.txt file for output using the CreateText method
C)declare a StreamReader variable for the input file
D)open the pictureFrame.txt file
A)declare a StreamWriter variable for the output file
B)open the pictureFrame57.txt file for output using the CreateText method
C)declare a StreamReader variable for the input file
D)open the pictureFrame.txt file
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
23
In Visual Basic,you use a(n)____ to read data from a sequential access file.
A)StreamWriter object
B)OpenText method
C)ReadLine method
D)StreamReader object
A)StreamWriter object
B)OpenText method
C)ReadLine method
D)StreamReader object
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
24
After opening a file for input,you can use the ____ to read the file's contents,one line at a time.
A)ReadLine method
B)OpenText method
C)AppendText method
D)WriteLine method
A)ReadLine method
B)OpenText method
C)AppendText method
D)WriteLine method
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
25
In the syntax for the PadLeft method,____ is an integer that represents the total number of characters you want the string to contain.
A)totalChars
B)character
C)variable
D)string
A)totalChars
B)character
C)variable
D)string
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following statements will close the sequential access file associated with the outFile variable?
A)outFile.End()
B)outFile.Quit()
C)outFile.IO()
D)outFile.Close()
A)outFile.End()
B)outFile.Quit()
C)outFile.IO()
D)outFile.Close()
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following can be used to determine whether the accounts.txt file exists?
A)If IO.Exists.File("accounts.txt") Then
B)If IO.File.Exists("accounts.txt") Then
C)If IO.File("accounts.txt") Then
D)If IO.Exists("accounts.txt") Then
A)If IO.Exists.File("accounts.txt") Then
B)If IO.File.Exists("accounts.txt") Then
C)If IO.File("accounts.txt") Then
D)If IO.Exists("accounts.txt") Then
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following opens the employee.txt file for output,creates a StreamWriter object,and assigns it to the outFile variable?
A)outFile = File.CreateText("F:\employee.txt")
B)outFile = IO.File.CreateText("F:\employee.txt")
C)outFile = File.CreateText("F:\")
D)outFile = IO.File.Create("F:\employee.txt")
A)outFile = File.CreateText("F:\employee.txt")
B)outFile = IO.File.CreateText("F:\employee.txt")
C)outFile = File.CreateText("F:\")
D)outFile = IO.File.Create("F:\employee.txt")
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following determines whether an item is selected in the lstTrees control?
A)If lstTrees.SelectedIndex = -1 Then
B)If lstTrees.SelectedIndex <> -1 Then
C)If lstTrees.SelectedIndex > -1 Then
D)If lstTrees.SelectedIndex < -1 Then
A)If lstTrees.SelectedIndex = -1 Then
B)If lstTrees.SelectedIndex <> -1 Then
C)If lstTrees.SelectedIndex > -1 Then
D)If lstTrees.SelectedIndex < -1 Then
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements will write the text "Programming" to a sequential access file?
A)outFile.Write("Programming")
B)outFile.Append("Programming")
C)outFile.Write{"Programming"}
D)outFile.Add["Programming"]
A)outFile.Write("Programming")
B)outFile.Append("Programming")
C)outFile.Write{"Programming"}
D)outFile.Add["Programming"]
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following statements will read data from a sequential access file?
A)inFile.Read
B)inFile.Peek
C)inFile.ReadWrite
D)inFile.ReadLine
A)inFile.Read
B)inFile.Peek
C)inFile.ReadWrite
D)inFile.ReadLine
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
32
A(n)____ is defined as a sequence (stream)of characters followed by the newline character.
A)character
B)line
C)input
D)stream
A)character
B)line
C)input
D)stream
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
33
The ____ method writes a newline character after the data.
A)WriteLine
B)ReadLine
C)Write method
D)Read
A)WriteLine
B)ReadLine
C)Write method
D)Read
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
34
Assume that the variable amount contains the value 46.How many characters will be padded in the statement below? amount = amount.ToString.PadLeft(5)
A)two
B)three
C)four
D)five
A)two
B)three
C)four
D)five
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
35
You can use the ____ to open a sequential access file for append.
A)CreateText method
B)StreamReader object
C)StreamWriter object
D)AppendText method
A)CreateText method
B)StreamReader object
C)StreamWriter object
D)AppendText method
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
36
After declaring a StreamReader variable,you can use the ____ to open a sequential access file for input; doing this automatically creates a StreamReader object.
A)OpenText method
B)Write method
C)StreamWriter object
D)ReadLine method
A)OpenText method
B)Write method
C)StreamWriter object
D)ReadLine method
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following removes the sixth item from the lstTrees control?
A)lstTrees.Items.Remove(5)
B)lstTrees.Items.Remove(6)
C)lstTrees.Items.RemoveAt(5)
D)lstTrees.Items.RemoveAt(6)
A)lstTrees.Items.Remove(5)
B)lstTrees.Items.Remove(6)
C)lstTrees.Items.RemoveAt(5)
D)lstTrees.Items.RemoveAt(6)
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following statements can be used to fill a string variable with asterisks resulting in "*****$675.89"?
A)amount=amount.Fill(12,"*")
B)amount=amount.Insert(5,"*")
C)amount=amount.PadLeft(12,"*")
D)amount=amount.Space(5, "*")
A)amount=amount.Fill(12,"*")
B)amount=amount.Insert(5,"*")
C)amount=amount.PadLeft(12,"*")
D)amount=amount.Space(5, "*")
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following declares a StreamReader variable named newFile?
A)Dim inFile As IO.StreamReader
B)Dim newFile As IO.StreamReader
C)Dim newFile As IO.StreamWriter
D)Dim newFile As StreamReader
A)Dim inFile As IO.StreamReader
B)Dim newFile As IO.StreamReader
C)Dim newFile As IO.StreamWriter
D)Dim newFile As StreamReader
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following statements should be used first when opening the input file?
A)If IO.File.Exists("pictureFrame57.txt") Then
B)If IO.File.Exists("pictureFrame.txt") Then
C)inFile = IO.File.OpenText("pictureFrame57.txt")
D)inFile = IO.File.OpenText("pictureFrame.txt")
A)If IO.File.Exists("pictureFrame57.txt") Then
B)If IO.File.Exists("pictureFrame.txt") Then
C)inFile = IO.File.OpenText("pictureFrame57.txt")
D)inFile = IO.File.OpenText("pictureFrame.txt")
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
41
Write the code to declare a variable named outFile that can be used to write data to a sequential access file.Then write the statement to open a sequential access file named customers.txt for output.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
42
Write a Structure statement that defines a structure named Order.The structure contains four member variables named strItemNum,strItemDesc,decPrice,and intQuantity.Then write the Dim statement that declares an Order variable named furniture.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
43
Write the statement that would write two columns of text to an output file named outFile.The first column,which contains the data for the strStudentID variable,must contain nine characters.The second column contains the data for the strLastName variable.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
44
Private Sub btnDisplay_Click(ByVal sender As Object,ByVal e As System.EventArgs)Handles btnDisplay.Click
' display the contents of the students.txt file
' declare variables
Dim inFile As IO.StreamWriter
Dim strStudent As String
' clear previous students from the Students box
lblStudents.Text = String.Empty
' determine whether the file exists
If IO.Exists("students.txt")= True Then
' open the file for input
inFile = IO.File.ReadText("students.txt")
' process loop instructions until end of file
Do Until inFile.Peek <> -1
' read a student line
strStudent = inFile.ReadLine
' display the student
lblStudents.Text = lblStudents.Text &
strStudent & ControlChars.NewLine
Loop
' close the file
Me.Close()
Else
MessageBox.Show("File not found","Students",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End Sub
' display the contents of the students.txt file
' declare variables
Dim inFile As IO.StreamWriter
Dim strStudent As String
' clear previous students from the Students box
lblStudents.Text = String.Empty
' determine whether the file exists
If IO.Exists("students.txt")= True Then
' open the file for input
inFile = IO.File.ReadText("students.txt")
' process loop instructions until end of file
Do Until inFile.Peek <> -1
' read a student line
strStudent = inFile.ReadLine
' display the student
lblStudents.Text = lblStudents.Text &
strStudent & ControlChars.NewLine
Loop
' close the file
Me.Close()
Else
MessageBox.Show("File not found","Students",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End Sub
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
45
Describe two advantages to programmers of using structures and structure variables.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
46
Write a Structure statement that defines a structure named Vehicle.The structure contains three member variables named strMake,strModel,and intYear.Then write the Private statement that declares a Vehicle variable named truck.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
47
What is the difference between an input file and an output file?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
48
Write the code to declare a variable named outFile that can be used to write data to a sequential access file.Then write the statement to open a sequential access file named samples.txt for output.New data should be written to the file after any existing data in the file.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
49
Structure ExamGrades
Public decExam1 As Decimal
Public decExam2 As Decimal
Public decExam3 As Decimal
End Structure
---------------------------
Private Function CalcAverage(ByVal grades As Decimal)As Decimal
' calculates and returns the average grade
Dim decSum As Decimal
decSum = grades.Exam1 + grades.Exam2 +
grades.Exam3
Return decSum * 3
End Function
---------------------------
Private Sub btnAverage_Click(ByVal sender As Object,ByVal e As System.EventArgs)Handles btnAverage.Click
' display the average exam grade
Dim threeGrades As ExamGrades
Dim decAverage As Decimal
Decimal.TryParse(txtGrade1.Text,decExam1)
Decimal.TryParse(txtGrade2.Text,decExam2)
Decimal.TryParse(txtGrade3.Text,decExam3)
decAverage = CalcAverage(threeGrades)
lblResult.Text = decAverage.ToString("N1")
End Sub
Public decExam1 As Decimal
Public decExam2 As Decimal
Public decExam3 As Decimal
End Structure
---------------------------
Private Function CalcAverage(ByVal grades As Decimal)As Decimal
' calculates and returns the average grade
Dim decSum As Decimal
decSum = grades.Exam1 + grades.Exam2 +
grades.Exam3
Return decSum * 3
End Function
---------------------------
Private Sub btnAverage_Click(ByVal sender As Object,ByVal e As System.EventArgs)Handles btnAverage.Click
' display the average exam grade
Dim threeGrades As ExamGrades
Dim decAverage As Decimal
Decimal.TryParse(txtGrade1.Text,decExam1)
Decimal.TryParse(txtGrade2.Text,decExam2)
Decimal.TryParse(txtGrade3.Text,decExam3)
decAverage = CalcAverage(threeGrades)
lblResult.Text = decAverage.ToString("N1")
End Sub
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
50
What is the difference between a structure and a structure variable?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
51
You should ____ the pictureFrame.txt file as soon as you have finished using it.
A)Save
B)Read
C)Close
D)Peek
A)Save
B)Read
C)Close
D)Peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
52
Write the code to declare a variable named inFile that can be used to read data from a sequential access file.Then write the statement to open a sequential access file named samples.txt for input.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
53
Which of the following statements removes the selected line in the list box?
A)lstPosters.Items.DeleteAt(lstPosters.SelectedIndex)
B)lstPosters.Items.Remove(5)
C)lstPosters.Items.Remove("16x20")
D)lstPosters.Items.RemoveAt(lstPosters.SelectedIndex)
A)lstPosters.Items.DeleteAt(lstPosters.SelectedIndex)
B)lstPosters.Items.Remove(5)
C)lstPosters.Items.Remove("16x20")
D)lstPosters.Items.RemoveAt(lstPosters.SelectedIndex)
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
54
An application uses the posterFrame.txt sequential access file to display all of the poster frames in a list box.You need to use the list box to select and remove any poster frames that are 16x20.Which of the following statements determines if a line is selected in the list box?
A)if lstPosters.SelectedIndex <> -1 Then
B)if lstPosters.Selected <> -1 Then
C)if lstPosters.SelectedIndex = -1 Then
D)if lstPosters.Selected = -1 Then
A)if lstPosters.SelectedIndex <> -1 Then
B)if lstPosters.Selected <> -1 Then
C)if lstPosters.SelectedIndex = -1 Then
D)if lstPosters.Selected = -1 Then
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
55
Write an If clause that determines whether the sequential access file named contacts.txt exists.If the file exists,open the file.If the file does not exist,display the message "File not found" in a message box.The application is named "View Contacts".
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
56
Write the statement that would remove the selected item from the lstFlowers control if an item is selected.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
57
Write the statement that would remove the item "RGT12985" from the lstPartNumber control.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
58
Write a Do clause that reads each line of text in a sequential access file and assigns the line to the strTextLine variable.Process the loop until the end of the file has been reached.The file is associated with a StreamReader variable named inFile.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
59
An application contains the Structure statement shown below:
Structure SalonInfo
Public strService As String
Public intRate As integer
End Structure
Write a Dim statement that declares an eight-element one-dimensional array of SalonInfo variables.Name the array mySalonInfo.Write the code to store the following data in the array:

Structure SalonInfo
Public strService As String
Public intRate As integer
End Structure
Write a Dim statement that declares an eight-element one-dimensional array of SalonInfo variables.Name the array mySalonInfo.Write the code to store the following data in the array:

Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
60
An application contains the Structure statement shown below:
Structure Furniture
Public strStyle As String
Public decPrice As Decimal
End Structure
Write a Dim statement that declares a Furniture variable named sofas.Then,write assignment statements that assign the value "Sectional" to the strStyle member,and assign the number 1895.99 to the decPrice member.
Structure Furniture
Public strStyle As String
Public decPrice As Decimal
End Structure
Write a Dim statement that declares a Furniture variable named sofas.Then,write assignment statements that assign the value "Sectional" to the strStyle member,and assign the number 1895.99 to the decPrice member.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck