Hello,
I am really lost in getting my code to work as well as using void functions and non main loop/value returning functions out side of the main. I took a stab at writing the code but it won't work.
this is what the code has to due.
• count the number of words in the file (a word is a consecutive series of non-whitespace
characters)
• display each word in the file backwards, 1 per line (for example, "the" would be displayed
as "eht")
• count the number of lowercase vowels in the file (vowels are a, e, i, o, and u)
the rules of the code build up are.
• the program must make use of functions and pass parameters (no global variables)
• there must be a void function that when passed a string (a word from the file) will display
the characters in the string backwards
• there must be a value-returning function that when passed a string (a word from the file)
will return a count of how many lowercase vowels are in the string
• all header files for library functions used by the program must be included
• additional functions are optional
• the file can only be read ONE time
example file that might be load.
december 8, 2017 is
the LAST regular calss
day of the SeMeSter.
"Hooray!!!"
example of the out put.
rebmeceD
,8
7102
si
eht
TSAL
raluger
ssalc
yad
fo
eht
, retSeMeS
"!!!!yarooH"
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
|
#include <string>
#include <iostream>
using namespace std;
int isvowel (char);
int count_words(string);
void reversewords (string);
int main()
{
cout << "Word count in file = "<<count_words<< endl;
cout << "vowel count in file = "<< isvowel<< endl;
return 0;
}
void reversewords (string input)
{
// output it in reverse order
for( int i = input.length(); i >= 0; -- i )
{
// output the char one by one according to character's index ( i-th letter in the word )
cout << input[i];
}
}
int isvowel (char ch)
{
for(int a = 0; a>= 0; a--)
{
if (ch == 'a' || ch == 'e' || ch == 'o' || ch == 'i' || ch == 'u')
isvowel++;
}
return isvowel;
}
int count_words( string s )
{
int word_count( 0 );
stringstream ss( s );
string word;
while( ss >> word ) ++word_count;
return word_count;
}
|