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

My assignment is to read some text from a file and produce an output with lower

ID: 3654920 • Letter: M

Question

My assignment is to read some text from a file and produce an output with lower case and the same output displayed in upper case underneath the lowercase output. so far I have gotten the output to display lower case. My problem is that I can't get my same output to display in upper case.

Here is my program so far:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {
string filename = "/Users/ptrinh/Documents/Xcode files/Program 4/catinthehat.dat";

ifstream inFile;
inFile.open ( filename.c_str(), ifstream::in );

if (!inFile){
cout << "File was NOT found" << endl;
return 1;
}

string line;

while (!(inFile.eof())){
getline (inFile,line);
transform(line.begin(), line.end(), line.begin(), ::tolower);
cout << line << endl;

}

inFile.close();



return 0;

}

************************************************************************************************************************************************
Here is my output in lower case:

bump! and then something went bump! how that bump made up jump!
we looked! then we saw him step in on the mat! we looked! and
we saw him! the cat in the hat! and he said to us,
"why do you sit there like that?" "i know it is wet and the sun
is not sunny. but we can have lots of good fun that is funny!"

************************************************************************************************************************************************
Now I need the same output but in uppercase underneath the lowercase output. Thanks!

Explanation / Answer

You can make use of

std::transform(str.begin(), str.end(),str.begin(), ::toupper);

Your final program will be

#include
#include
#include

using namespace std;

int main () {
string filename = "/Users/ptrinh/Documents/Xcode files/Program 4/catinthehat.dat";

ifstream inFile;
inFile.open ( filename.c_str(), ifstream::in );

if (!inFile){
cout << "File was NOT found" << endl;
return 1;
}

string line,temp;

while (!(inFile.eof())){
getline (inFile,line);

temp = line;
transform(line.begin(), line.end(), line.begin(), ::tolower);
transform(temp.begin(), temp.end(), temp.begin(), ::toupper);
cout << line << endl;

cout << temp<< endl;

}

inFile.close();



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