I need help with an algorithm to reformat a paragraph using the cctype library and strings. Also there can only be 40 characters including whitespace per line. Thanks for any help in advance.
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
#include <iomanip>
usingnamespace std;
void readtext (string);
void reformat (string);
void sentencereformat (string);
int main ()
{
string input;//text within input file
ifstream inputfile;//datafile read in
cout<<"Please enter the name of the input file"<<endl;
inputfile.open(input.c_str());
cout<<"Brandon de Leon Assignment #9 Section #1003"<<endl<<endl;
cout<<"Reformatted content of the file named "<<endl<<endl;
// sentencereformat(input1);
readtext(input);
cout<<endl<<endl;
return 0;
}
void readtext (string input)
{
int wordcount=0;
int lettercount=0;
int sentencecount=0;
int charactercount=0;
int totalcharactercount=0;
int spacecount=0;
cin>>input;
while (cin)
{wordcount++;
// cout<<" ";
for (int i=0;i<input.length(); i++)
{ // input[i]=tolower(input[i]);
charactercount++;
if (isalpha(input[i]))
{ lettercount++;
spacecount=0;
}
if (input[i]=='.'||input[i]=='!'||input[i]=='?')
{
sentencecount++;
input[i]=toupper(input[i]);
input[i]=tolower(input[i]);
}
}
cout<<input<<" ";;
cin>>input;
}
//reformat(input);
cout<<endl<<endl;
cout<<"# words: "<<wordcount<<endl;
cout<<"# letters: "<<lettercount<<endl;
cout<<"# sentences: "<<sentencecount<<endl;
cout<<fixed<<showpoint<<setprecision(2);
cout<<"average word length: "<<static_cast<double>(charactercount)/wordcount;
}
Sample input
apRil 8, 2013.
tHE follOWing are excerpts from
ChaPter 3 of the textbook!
"the VAriABLES Cin and Cout are already
defined and assoCIATED
with the STANDard INPUT/OUTPUt
devices." dOES iT WOrk?
output at this point
apRil 8, 2013. tHE follOWing are excerpts from ChaPter 3 of the textbook! "the VAriABLES Cin and Cout are already defined and assoCIATED with the STANDard INPUT/OUTPUt devices." dOES iT WOrk?
figured out the forty characters a line part of the problem now. Just need help with capitalizing first letter right after punctuation and lowercasing the rest.