Hello,
I am really new and need your help with getting this formatted correctly. my output is all messed up.
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 read.
December 8, 2017 is
the LAST regular calss
day of the SeMeSter.
"Hooray!!!"
example of the out put that is correct.
rebmeceD
,8
7102
si
eht
TSAL
raluger
ssalc
yad
fo
eht
, retSeMeS
"!!!!yarooH"
|
my out put that is not formatting correctly.
BACKWARDS WORDS
rebmeceddecember
rebmeceddecember
7,88,
1022017
siis
ehtthe
TSALLAST
ralugerregular
sslaccalss
yadday
foof
ehtthe
.retSeMeSSeMeSter.
"!!!yarooH""Hooray!!!"
"Hooray!!!"
Words in file: 13
Lowercase vowels in file: 2
|
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
|
#include <iostream>
#include <cctype>
#include <string>
#include <iomanip>
using namespace std;
bool islcvowel(char);
void BACKWARDS(string&);
int digitcount(string);
int main()
{
string text;
int digits=0;
int words=0;
cout <<"BACKWARDS WORDS"<<endl;
cout <<left;
cin >>text;
while (cin)
{
words++;
digits = digits + digitcount (text);
BACKWARDS(text);
cout << text << endl;
cin >> text;
}
cout << text << endl;
cout << endl;
cout << "Words in file: "<< words << endl;
cout <<"Lowercase vowels in file: "<< digits << endl;
return 0;
}
int digitcount (string text)
{
int total=0;
char ch;
int n;
n=text.size();
for (int i=0; i<n; i++)
ch = tolower(text[i]);
if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
total++;
return total;
}
void BACKWARDS(string& word)
{
int n;
n=word.size();
for (int i= n ;i >= 0 ; i--)
cout<< word[i];
}
|