C Program using Strings and Functions DO NOT USE ARRAYS Desi

C++ Program using Strings and Functions. (DO NOT USE ARRAYS)

Design a C++ program with functions (as described below) that will read a text file (via Linux redirection) and

-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 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

the file can only be read ONE time.

NOTES:

the data file will exist and will not be empty

there will be at least one word in the file

a word is a consecutive series of non-whitespace characters

words will be separated by blanks and/or linefeeds

the characters in the file can be letters, digits, punctuation marks, and/or other printable charcters

the last line in the data file will be terminated with a linefeed (\'\ \')

Program must be designed to run in batch mode (no prompts) via Linux redirection.

Include all header files for library functions used by the program.

Label output and display counts as integers.

Sample terminal session:
[user@bobby keys]$ more data4nine
December 9, 2016 is
the   LAST regular class
day of the SeMeSter.
\"Hooray!!!!\"
Then FINALS...
[user@bobby keys]$ g++ ex09.cpp
[user@bobby keys]$ ./a.out < data4nine

BACKWARDS WORDS
rebmeceD
,9
6102
si
eht
TSAL
raluger
ssalc
yad
fo
eht
.retSeMeS
\"!!!!yarooH\"
nehT
...SLANIF

Words in file: 15
Lowercase vowels in file: 19

Solution

hey heres the code, compile and if you have any doubts place comments.

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void printReverse(string );
int countVowels(string );

int main(){

/*variable word to count number of words and nov to count number of vowels (n o v) */
int word=0,nov=0;

/*open file you want to read*/
ifstream myfile (\"myfile2.txt\");

string words;
/* if file exists read words*/
if (myfile.is_open())
{
    while ( myfile>>words)
    {
      word++;

      /*prints word in revers and checks number of lowercase vowels.*/
      printReverse(words);
     
      /*nov store number of all lowercase vowels in file.*/
      nov=nov+countVowels(words);
  
   /*prints new line after every word */
   cout<<endl;
    }
   
    cout<<\"\ \";
    cout<<\"Words in file: \"<<word<<endl;
    cout<<\"Lowercase vowels in file: \"<<nov<<endl;
    myfile.close();
}

/*if file doesnt exist prints file not found*/
else cout << \"File not found!\";

return 0;
}


/*function to print word in backward.*/
void printReverse(string word)
{

for(int i=word.length()-1;i>=0;i--)
cout<<word[i];

}


/*function to count number of lowercase vowels for a word.*/
int countVowels(string word)
{
/*lvow is variable to count lowercase vowels for word*/
int lvow=0;

/*declare string of lowercase vowels*/
     string vowel=\"aeiou\";

for(int i=0;i<word.length();i++)
{
  for(int j=0;j<vowel.length();j++)
  {
   if(word[i]==vowel[j])
   {
    lvow++;
   }
  }
}
return lvow;
}

C++ Program using Strings and Functions. (DO NOT USE ARRAYS) Design a C++ program with functions (as described below) that will read a text file (via Linux redi
C++ Program using Strings and Functions. (DO NOT USE ARRAYS) Design a C++ program with functions (as described below) that will read a text file (via Linux redi
C++ Program using Strings and Functions. (DO NOT USE ARRAYS) Design a C++ program with functions (as described below) that will read a text file (via Linux redi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site