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++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Modern Database Management
Starting Out with Python (4th Edition)
BASIC BIOMECHANICS
Web Development and Design Foundations with HTML5 (8th Edition)
- Write a statement that defines a file stream object named people. The object will be used for file output.arrow_forwardWrite a statement that defines a file stream object named places. The object will be used for both output and input.arrow_forwardThe python function get_second_line takes one parameter, fname, the name of a text file. The function should open the file for reading, determine the second line of the file, close the file, and return the second line (a string). NOTE: You may assume the file will have at least two lines.arrow_forward
- 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
- ...ex2_main.cpp#include <stdio.h>#include <stdlib.h>#include "lab2_ex2.h" #define FILENAME "statement11.txt" int main(){ // 1. Acquire the text from file char *text = read_text_file(FILENAME); // Note: Caller should free the memory allocated printf("%s\n", text); // 2. Compute the readability and display the grade level float readability = get_readability(text); printf("Readability index = %f\n", readability); display_level(readability); // 3. Free resources, e.g. allocated memory by read_text_file() function free(text); return 0;}...lab2_ex2.cpp/* EDIT THIS FILE TO SOLVE THE LABORATORY EXERCISES*/ #include <stdio.h>#include <ctype.h>#include <string.h>#include <math.h>#include <stdlib.h>#include "lab2_ex2.h" /*Assume that a letter is any lowercase character from a to zor any uppercase character from A to Z*/int alpanumeric_count(const char *text){ int count = 0; /* YOUR CODE HERE!!! */ return…arrow_forwardUnder 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_forward
- 2. 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_forwardpythonarrow_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_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