Each of the following
as you can.
A) fstream file(ios :: in I ios :: out);
file.open("info.dat");
if (!file)
{
cout << "Could not open file.\n";
}
B) ofstream file;
file.open("info.dat", ios::in);
if (file)
{
cout << "Could not open file.\n";
}
C) fstream file("info.dat");
If (!file)
{
cout << "Could not open file.\n";
}
D) fstream dataFile("info.dat", ios:in I ios:binary);
int X = 5;
dataFile << x;
E) fstream dataFile("info.dat", ios:in);
int x;
while (dataFile.eof())
{
)
dataFile >> x;
cout << x << endl;
F) fstream dataFile("info.dat", ios:in);
char line [81];
dataFile .get(line);
G) fstream dataFile("info.dat", ios:in);
char stuff[81];
dataFile.get(stuff);
H) fstream dataFile("info.dat", ios:in);
char stuff [81] = "abcdefghijklmnopqrstuvwxyz";
dataFile.put(stuff);
I) fstream dataFile("info.dat", ios:out);
struct Date
{
int month;
int day;
int year;
);
Date dt = { 4, 2, 98 };
dataFile.write(&dt, sizeof(int));
J) fstream inFile("info.dat", ios:in);
int x;
inFile.seekp(5);
inFile >> x;
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
STARTING OUT WITH C++ MPL
Additional Engineering Textbook Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
Problem Solving with C++ (9th Edition)
- in pythonarrow_forwardComputer sciencearrow_forwardThe function file_first_chars in python takes one parameter, fname, the name of a text file, and returns a string made up of the first character from each line in the file. You may assume there are no blank lines in the file. Hint: Use a for loop to iterate over the lines of the file and accumulate the string of first characters. NOTE: Return the function, don't print For example: Test Result print(file_first_chars("wordlist1.txt")) hsaemarrow_forward
- Under what circumstances is a file stream object’s ios::hardfail bit set? What member function reports the state of this bit?arrow_forward* The ofstream class then default mode of opening the file are ios::in ios::out O ios::outlios::trunk O ios::inlios::trunc Oarrow_forward2. File handling is an important part of any application. Assume that, you are asked to build an application to find the harmonic mean in a file. Assume that you have to read the file of "Filel.txt" and print the harmonic mean of each row to an output file "File2.txt". All of the data in the "File1.txt" is comma separated. In file1.txt you are given the name of the data set in first place, then you are given the data list. All of them are comma separated. Your task is to compute the harmonic mean from the given file | for each dataset. The file may contain more than 1000 rows. Write your code by following the requirements. File2.txt harmonic mean of Datal is 3.50 harmonic mean of Data2 is 3.43 harmonic mean of Data3 is 3.50 File1.txt Data1, 3, 4, 4, 3, 3.7, 4, 3.3, 1 Data2, 3, 4, 3.7, 3, 3.7, 4, 3, 1 Data3, 3, 4, 4, 3, 3.7, 4, 3, 2 Data4, 3, 4, 4, 3, 3.7, 4, 3.3, 2 Design a JAVA application that can perform the task with the given scenario. harmonic mean of Data4 is 3.49arrow_forward
- pythonarrow_forwardThis Python Lab 9 Lab: Write a file copying program. The program asks for the name of the file to copy from (source file) and the name of the file to copy to (destination file). The program opens the source file for reading and the destination file for writing. As the program reads each line from the source file and it writes the line to the destination file. When every line from the source file has been written to the destination file, it close both files and print “Copy is successful.” In the sample run, “add.py” is the source file and “add-copy.py” is the destination file. Note that both “add-copy.py” is identical to “add.py” because “add-copy.py” is a copy of “add.py”. Sample run: Enter file to copy from: add.py Enter file to copy to : add-copy.py Copy is successful. Source file: add.py print("This program adds two numbers") a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print(f"{a} + {b} = {a+b}") Destination file:…arrow_forwardWrite a code segment that creates an ofstream object named outfile, opens a file named numbers.txt, and associates it with outfile. The code should then use a loop to write the numbers 1 through 100 to the file before closing it.arrow_forward
- please code in python count_word: This function takes a filename and a keyword. Return the number of times the keywordoccurs in the file. Initialize a variable to keep track of the number of times the keyword appears.Traverse the file by line. Use the count method on each line to find the number of times the keywordappears in it and add that amount to the variablearrow_forwardNote: The code should be written in Pythonarrow_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_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT