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

in c++ Question 3 Write a program that reads the following sentences from a file

ID: 3806068 • Letter: I

Question

in c++

Question 3

Write a program that reads the following sentences from a file:

I am Sam
Sam I am
That Sam I am
That Sam I am
I do not like
that Sam I am
Do you like
green eggs and ham ?

I do not like them

I do like spam

Your program should produce two output files: (i) one with the whole text in uppercase and (ii) another one with statistics about the text. The latter should present the number of characters in the whole text, the longest verse, and the number of lines in the original file.

The content of both files should also be presented on screen.

Explanation / Answer

//To read the sentences from the file line by line

#include<cstdio>
#include<iostream>

using namespace std;

int main(){
freopen("path to the file", "rb", stdin);
string line;
while(getline(cin, line))
cout << line << endl;
return 0;
}

//Convert to uppercase

#include<fstream.h>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
void main()
{
char c,up;
char fname[10];
clrscr();
ofstream out;
cout<<"Enter File Name:";
cin>>fname;
out.open(fname);
cout<<"Enter the text(Enter # at end) "; //write contents to file
while((c=getchar())!='#')
{
up=c-32;
out<<up;
}
out.close();
ifstream in(fname); //read the contents of file
cout<<" File converted in uppercase ";
while(in.eof()==0)
{
in.get(c);
cout<<c;
}
getch();
}