Write a C++ program that reads in a text file (data.txt), and prints to the scre
ID: 3621480 • Letter: W
Question
Write a C++ program that reads in a text file (data.txt), and prints to the screen the text with all extra blanks removed (if there are 2 or more blanks in a row, replace them by a single blank) and changes all LOWERCASE letters to UPPERCASE letters. WATCH THAT YOU DON”T DELETE CARRIAGE RETURNS and tabs – whitespace includes tabs and carriage returns as well as blanks…so you only want to get rid of extra blank characters.
****input Text:
In the late 60s and early 70s, PL/I was popular, and was the largest language of its day. The C language was developed as a reaction, where the language itself is relatively small, and instead of the hundreds of "built-in" functions of PL/I, it allowed the user to choose the subset of functions they wanted to use via #include statements.
Later, C++ was developed as an extension to C, creating a language that was still procedure-oriented via its functions., but with object constructions overlaid on it. As C++ continued to develop, more constructions were added ( e.g. templates), and existing features were redefined .
Explanation / Answer
please rate - thanks
#include <iostream>
#include <fstream>
using namespace std;
int main()
{char filename[30];
string input;
ifstream in;
int i;
char prev;
cout<<"what is the name of the file you are using? ";
cin>>filename;
in.open(filename); //open file
if(in.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
return 1;
}
cout<<endl;
getline(in,input);
while(in)
{i=0;
prev=input[i];
if(islower(input[i]))
cout<<(char)toupper(input[i]);
else
cout<<input[i];
for(i=1;input[i]!='';i++)
{if(input[i]!=' ')
{if(islower(input[i]))
cout<<(char)toupper(input[i]);
else
cout<<input[i];
}
else
if(prev!=' ')
cout<<input[i];
prev=input[i];
}
cout<<endl;
getline(in,input);
}
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.