Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE PROVIDE A PROGRAM FOR THE FOLLOWING QUESTION WITHOUT ANY ERRORS. This is

ID: 3930437 • Letter: P

Question

PLEASE PROVIDE A PROGRAM FOR THE FOLLOWING QUESTION WITHOUT ANY ERRORS.

This is a C++ programing assignment

Problem 2. write a c++ program which will take a filename from the command line and count the vowels contained therein. For the purposes of this problem, the vowels are a, e, i, o, u, and their uppercase equivalents. Choose your own files for testing. The graders will choose theirs, too.

Hint: if you declare a string

string vowels = "aAeEiIoOuU";

then the function call vowels.find(ch) will return a non-null pointer if ch is a vowel.

Explanation / Answer

VowelsCount.cpp

#include <iostream>
#include<fstream>
using namespace std;

int main(int argc, char *argv[])
{
if(argc == 2){
ifstream fin;
fin.open(argv[1], ios::in);
string vowels = "aAeEiIoOuU";
char ch ;
int volwelsCount = 0;

   while (!fin.eof() ) {

   fin.get(ch);
       if (vowels.find(ch) != std::string::npos ){
           ++volwelsCount;
       }
   }
cout << "Number of Vwels in a file: " << volwelsCount << endl;
}
else{
cout<<"Invalid command line arguements"<<endl;
}
return 0;
}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                        

sh-4.3$ main                                                                                                                                                                                                                

Invalid command line arguements                                                                                                                                                                                             

sh-4.3$ ./main input.txt                                                                                                                                                                                                    

Number of Vwels in a file: 8

input.txt

abcdefj abcioewu

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote