Using a text editor, create a text file called File1.txt and place it into the r
ID: 3622022 • Letter: U
Question
Using a text editor, create a text file called File1.txt and place it into the root directory C:/ . Fill File1.txt with a sentence and save the file.
The, write the C++ program that performs the following:
1. Reads the sentence from the file File1.txt and display it on the screen.
2. Asks the user to input a sentence (80characters or less) to be saved into a new file called c:/File2.txt, placed in the same C:/directory.
3. Compares the two sentences and display a message to let the user know if the strings are identical or not.
4. Replaces the original sentence in File1.txt with the sentence entered by the user, in order to make the file File1.txt and File2.txt identical
Note: Every file must be explicitly opened and then closed immediately after the read/write operations.
--------------------------------------------------------------------------------------------------------------------------------
Output (if senteces are identical):
My code, what i have so far: Produces the first 2 lines of the output.
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
ifstream inFile ("c:/File1.txt", ios::in);
char sentence[80];
if(!inFile)
{
cerr<<"File File1.txt could not be opened"<<endl;
exit(1);
}
inFile.getline(sentence,80);
cout<<endl;
cout<<"The file Text1.txt contains the following sentence:";
cout<<endl;
cout<<sentence;
inFile.close();
cout<<endl;
cout<<endl;
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------
Please help in completing my program code, i cant figure out how to get the rest of it.
Explanation / Answer
Hope this helps. Let me know if you have any questions. Please rate. :) #include #include #include #include using namespace std; int main() { ifstream inFile ("c:/File1.txt", ios::in); char s[81]; if(!inFile.is_open()) { cerrRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.