A file that data is written to is known as a(n).______.
a. input file
b. output file
c. sequential access file
d. binary file
The data that are written to a file are known as output file.
Hence, the correct answer is option “B”.
Explanation of Solution
Output file:
- A file where the data are written is called as “output file”. The output file is created on the disk and allows the program to write data on it.
- The “output file” must be accessed using the file name and must be closed after the usage of the file.
- If the file is not closed properly, it can cause loss of data because the data that are written to a file are stored in a buffer first.
- After closing a file, the buffer saves the contents into the disk.
Example for output file:
The following program is used to open an output file, write a name to it, and then close it:
#Function main
def main():
#Open an outfile for writing
outfile=open('my_name.txt','w')
#Write the name into file
outfile.write("Tom cruise")
#Close the file
outfile.close()
#Display statement
print('Data written to my_name.txt')
#Call the main function
main()
Explanation:
The above program is used to open an output file named “my_name.txt”, write a name to it, and then close it:
- In the “main()” function, open a file “my_name.txt” and write a name "Tom cruise" to the file using the “write()” method.
- Close the file using the “close()” method. Display the intimation message on the screen.
- Call the “main()” function.
Explanation for the incorrect options:
Input file:
A file from which the data are read is called as an input file. When a program gets input from the file, then it is called as input file.
Hence, option “A” is wrong.
Sequential access file:
In sequential access method, the contents of the file are accessed from the beginning to the end.
Hence, option “C” is wrong.
Binary file:
Binary file holds data that are not represented in the form of text. The executable programs are stored in the type of binary file.
- Due to this, the contents present in the binary file cannot be viewed with normal text editors.
Hence, option “D” is wrong.
Output:
Data written to my_name.txt
Screenshot of “my_name.txt” file
Want to see more full solutions like this?
Chapter 6 Solutions
Starting Out with Python (4th Edition)
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
Starting out with Visual C# (4th Edition)
Starting Out With Visual Basic (7th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out With Visual Basic (8th Edition)
- Line Numbers Write a program that asks the user for the name of a file. The program should display the contents of the file with each line preceded with a line number followed by a colon. The line numbering should start at 1. Pythonarrow_forwardTime remaining: 01:47:21 Computer Science The file numbers.txt contains integer numbers, one number per line. The contents could look like this: 2 45 108 3 - 10 1100 ...etc... Please write a function named largest, which reads the file and returns the largest number in the filearrow_forwardProgramming Exercises 1. File Display Assume a file containing a series of integers is named numbers.txt and exists on the computer's disk. Write a program that displays all of the numbers in the file. VideoNote File Display 2. File Head Display Write a program that asks the user for the name of a file. The program should display only the first five lines of the file's contents. If the file contains less than five lines, it should display the file's entire contents.arrow_forward
- Function files can have zero, one, or several output arguments. False True Oarrow_forwardFile Display Assume that a file containing a series of integers is named numbers.dat and exists on the computer’s disk. Design a program that displays all of the numbers in the file. File Display IN Q Basic langauage and flowchartarrow_forwardFunction ________repositions the file position pointer to a specific location in the filearrow_forward
- #function read file and display reportdef displayAverage(fileName):#open the fileinfile = open(fileName, "r")#variable declaration and initializationtotal = 0count = 0#read filefor num in infile:total = total + float(num)count = count + 1#close the fileinfile.close()#calculate averageaverage = total / count#display the resultprint("Average {:.1f}".format(average)) #method callingdisplayAverage("numbers.txt")arrow_forwardIn C++arrow_forwardC++ Visual Studio 2019 Write a program that asks the user for the name of a file. The program should display the contents of the file on the screen. Each line of screen output should be preceded with a line number, followed by a colon. The line numbering should start at 1. Here is an example: George Rolland 127 Academy Street Brasstown, NC 28706 If the file's contents won't fit on a single screen, the program should display 24 lines of output at a time, and then pause. Each time the program pauses, it should wait for the user to strike a key before the next 24 lines are displayed. Note: Save text below as the file to use and name it forChap12.txt file for this assignment. The line numbers should NOT be reset for each screen. Text: No one is unaware of the name of that famous English shipowner, Cunard. In 1840 this shrewd industrialist founded a postal service between Liverpool and Halifax, featuring three wooden ships with 400-horsepower paddle wheels and a burden of 1,162 metric…arrow_forward
- C lanaguge Managing Student Information! C LANGUAGE We're going to build a student information management system. The user should be shown a menu with four options: display student initials, display student GPAs, add students, or exit the program. If the user chooses to exit, the program should end. Otherwise, if the user chooses to display the student initials, the contents of the students.txt file should be read, and just the student number and initials should be displayed to the user in a tabular format. If the user chooses to display the student GPAs, the contents of the students.txt file should be read, and just the student number and GPAs should be displayed to the user in a tabular format. If the user chooses to add students, they should be prompted for the number of studnets they’d like to add. They should then be prompted that many times for a studnet number, a GPA, a first initial, and a last initial. Each of the new items should be saved to the students.txt file.…arrow_forwardFile Display ProgramWrite a program that asks the user for the name of a file. The program should display thecontents of the file on the screen. If the file’s contents won’t fit on a single screen, the program should display 24 lines of output at a time, and then pause. Each time the programpauses, it should wait for the user to strike a key before the next 24 lines are displayed.arrow_forwardC# Write, compile, and test a console application named FileComparison that compares two files. First, use a text editor such as Notepad to save your favorite movie quote. Next, copy the file contents, and paste them into a word-processing program such as Word. Then, write the file-comparison application that displays the sizes of the two files as well as the ratio of their sizes to each other. To discover a file's size, you can create a System.IO.FileInfo object using statements such as the following, where FILE_NAME is a string that contains the name of the file, and size has been declared as an integer: FileInfo fileInfo = new FileInfo(FILE_NAME) ;Size = fileInfo.Length;arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr