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

Lebo is in grade 4. She typed the following essay about her holiday on the compu

ID: 3627721 • Letter: L

Question

Lebo is in grade 4. She typed the following essay about her holiday on the computer. Please help her correct the
following 2 errors - she did not start her sentences with uppercase letters, and she used the character ‘5’ instead of the
letter ‘s’.
Create a file named essay.txt containing the essay below. Write a program that will read the file character by
character, change the first character of the first word of each sentence to an uppercase character, and change all the
‘5’ characters to ‘s’. Write the essay character by character to an output file called correct.txt.
Create an input file called essay.txt with the essay as follows:
my holiday. we went to my aunt’5 farm. 5he ha5 ponie5. 5he taught me to ride
the ponie5, and that wa5 great fun. and 5he ha5 lot5 and lot5 of 5trawberrie5.
we could pick them our5elve5, and we could eat a5 many a5 we wanted. my uncle
let me help him to milk the cow5. it i5 very difficult. the duck in the duck
pond bit my finger when I gave him bread to eat.
Ask the user to input the name of the input and output file.

Explanation / Answer

#include <fstream> #include <iostream> #include <string> using namespace std; void change5(string &essay) //changes all 5 to s { int loc; loc = essay.find_first_of("5"); //gets the position of the first 5 while(loc != -1) { essay[loc] = 's'; //replaces 5 with s loc = essay.find_first_of("5", loc + 1); //starts off finding the next 5 after what we just found } //keep searching until all clear } void capitalize(string &essay) //finds a . then capitalize's the letter 2 over { int loc; loc = essay.rfind(".", essay.size() - 2); //gets the position of the second to the last . essay[0] = toupper(essay[0]); //capitalize the first letter of the essay while(loc != -1) { essay[loc + 2] = toupper(essay[loc + 2]); //capitalize the letter loc = essay.rfind(".", loc - 1); //starts off finding the next . after what we just found } //keep searching until all clear } int main() { string filename; cout << "What's the essay name? "; //should be essay.txt getline(cin, filename); //gets the file name // filename = "essay.txt"; //while testing too lazy to input everytime comment out later ifstream inFile; inFile.open(filename.c_str()); //opens the given file for input if (!inFile) //if you can't open it { cout << "I could not open the file. Fooey. "; return 0; } string essay; getline(inFile, essay, ''); //reads the whole file into essay inFile.close(); //close file change5(essay); //we do change5's first so we just have to change all 5 to s and not have to worry about if it's first in the sentence capitalize(essay); cout << "Enter the output file name: "; getline(cin, filename); //gets the file name // filename = "correct.txt"; //while testing too lazy to input everytime comment out later ofstream outFile; outFile.open(filename.c_str()); //opens the given file for output outFile << essay; outFile.close(); system("pause"); return 0; }
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