Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Program.... Sentence Filter Wirite a program that asks the user for two file

ID: 3858367 • Letter: C

Question

C++ Program....

Sentence Filter Wirite a program that asks the user for two file names. The first file wil be opened for input and Write a program that asks the user for two file names. The first file will be opened for input and the second file will be opened for output. (It will be assumed that the first file contains sentences that end with a period.) The program will read the contents of the first file and change all the letters to lowercase except the first letter of each sentence, which should be made uppercase. The revised contents should be stored in the second file.

Explanation / Answer

#include <iostream>

#include <fstream>

#include <cctype> // Needed for tolower function.

using namespace std;

int main()

{

const int SIZE = 81; // Constant size of filenames

// Arrays for file names

char fileName1[SIZE];

char fileName2[SIZE];

char ch; // Holds character

ifstream inFile; // Input file stream object

fstream outFile; // Output file stream object

  

// Get FIRST file from user

cout << "Please enter the first file (sentences.txt). ";

cin >> fileName1;

// Open file for input

inFile.open (fileName1);

// Test file for errors.

if (!inFile)

{

cout << "The file " << fileName1

<< " could not be opened.";

exit(0);

}

// Get SECOND file(user created) from user

cout << "Please enter a new file name to save the conversion([filename].txt). ";

cin >> fileName2;

// Open and create fileName2 for output

outFile.open (fileName2, ios::out);

// Process files

inFile.get(ch);

while(!inFile.eof())

{

outFile.put(tolower(ch));

inFile.get(ch);

}

// Close files

inFile.close();

outFile.close();

// Let user know conversion is finished

cout << "File conversion is complete. ";

system("pause");

return 0;

}

Output:

a text file will be created which contains lower case letters

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote