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

Please rewrite code so it does not use output files (see code below). Problem Wr

ID: 3625293 • Letter: P

Question

Please rewrite code so it does not use output files (see code below).
Problem
Write a C++ program that reads in a text file ( called sample1.txt), and prints to the screen the text with all extra blanks removed (that is, 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.
sample1 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 .

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

using namespace std;

int main()
{

char ch;
int count=0;
ifstream fin("sample1.txt");
ofstream fout("smaple2.txt");

while(fin)
{
ch=fin.get();
while(ch==' ')
{
if(count==0)
fout.put(ch);
ch=fin.get();
count++;
}
fout.put(ch);
count=0;
}
fin.close();
fout.close();
ifstream fil("sample2.txt");
while(fil)
{
ch=fil.get();
if((ch>=97)&&(ch<=122))
ch=ch-32;
cout<<ch;
}
return 0;
}




Explanation / Answer

please rate - thanks

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
char ch;
int count=0;
ifstream fin("sample1.txt");
ch=fin.get();
while(fin)
{ if(ch==' ')
      {if(count==0)
           cout<<ch;
       count++;
       }
   else
      {if((ch>=97)&&(ch<=122))
         ch=ch-32;
       cout<<ch;
       count=0;
       }
       ch=fin.get();
}
fin.close();
cout<<endl;
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