Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <string>
- #include <cctype>
- #include <fstream>
- using namespace std;
- void worddisplay(string,int); // Function to display file in proper format
- int longest(string,int); // Function for longest word
- int wordlength(string); // Function to determine word length
- int lettercount(string); // Function to count the letters in a word
- int digitcount(string); // Function to count digits in word
- int consonants(string); // Function to count lowercase consonants in word
- int charcount(string); // Function to count number of non alnum characters
- int main()
- {
- ifstream infile; // Represent the input file
- string fname; // Actual name of file
- string text; // Variable used for input of non-whitespace from input file
- int num; // Used for number of words to display per line in output int lng;
- int wlen=0; // Variable used for word length
- int digits=0; // Count variable for number of digits
- int words=1; // Count variable for number of words
- int concount=0; // Count variable for number of consonants
- int letcount=0; // Count variable for number of letters
- int chcount=0; // Count for number characters not letters of digits
- double average; // Equation for finding average word length
- cout << "Please enter the name of the input file" << endl;
- cin >> fname;
- cout << "Please enter number of words per line to display (2-10)" << endl;
- cin >> num;
- cout << " " << endl;
- cout << "Ryan Hedderly Assignment #9 Section #1001" << endl;
- cout << " " << endl;
- infile.open(fname.c_str());
- cout << "Input file: " << fname << endl;
- cout << " " << endl;
- infile >> text;
- while(!infile.eof())
- {
- wordlength(text);
- lettercount(text);
- digitcount(text);
- consonants(text);
- charcount(text);
- lng = wordlength(text);
- longest(text,lng);
- wlen = wlen + wordlength(text);
- letcount = letcount + lettercount(text);
- digits = digits + digitcount(text);
- concount = concount + consonants(text);
- chcount = chcount + charcount(text);
- words++;
- infile >> text;
- }
- worddisplay(fname,num);
- infile.close();
- cout << " " << endl;cout << left << setw(30) << "Longest word:" << " " << endl;
- cout << left << setw(35) << "# words:" << right << setw(7) << words << endl;
- cout << left << setw(35) << "# letters:" << right << setw(7) << letcount << endl;
- cout << left << setw(35) << "# lower case consonants:" << right << setw(7) << concount << endl;
- cout << left << setw(35) << "# digits:" << right << setw(7) << digits << endl;
- cout << left << setw(35) << "# non alphanumeric chars:" << right << setw(7) << chcount << endl;
- cout << fixed << setprecision(3);
- average = static_cast<double>(wlen)/words;
- cout << left << setw(35) << "average word length:" << right << setw(7) << average << endl;
- return 0;
- }
- void worddisplay(string fname, int num)
- {
- ifstream infile;
- string text;
- int count=0;
- infile.open(fname.c_str());
- infile >> text;
- while(!infile.eof())
- {
- cout << text << " ";
- count++;
- if(count==num)
- {
- cout << endl;
- count=0;
- }
- infile >> text;
- }
- infile.close();
- cout << endl;
- }
- int wordlength(string text)
- {
- text.length();
- }
- int longest(string text, int lng)
- {
- }
- int lettercount(string text)
- {}
- int digitcount(string text)
- {
- }
- int consonants(string text)
- {
- }
- int charcount(string text)
- {
- }