Paragraph Reformat

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
#include <iomanip>
using namespace 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?
Last edited on
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.
Topic archived. No new replies allowed.