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

C++ _ the portion of my code to use and add to is below: Create a program that c

ID: 3912676 • Letter: C

Question

C++ _ the portion of my code to use and add to is below:

Create a program that counts the number of vowels in a file.  

Requirements:

User must specify the name of the file to analyze when the program is run. If not an error should be generated. Use constants where appropriate.

Use I/O (stream) manipulators to format the output so that it is identical to the example below

Example:

Notice in the pic above how the program was run. It wasn't clicked on but instead it was run from a console window that was opened first. Notice how both the exe (VowelCounter.exe) and the file to analyze (Constitution_of_the_United_States.html) are in the same folder (aka directory) and used together on the command line of the console window.

Code:

#include "stdafx.h"
#include "windows.h"
#include <iostream>
#include <string>
#include <fstream>

int main(int argc, char* argv[])
{
// The executable name and at least one argument?
if (argc < 2)
{
  std::cout << "Error with input agrs.." << std::endl;
  return 1;
}
// For debugging purposes only
for (int i = 0; i < argc; i++)
{
  std::cout << i << ":" << argv[i] << std::endl;
}
std::ifstream inFile;
inFile.open(argv[1]);
if (!inFile)
{
  std::cout << "Error with file name.." << std::endl;
  return 1;
}
///////////////////////
// Work here with open file.....
///////////////////////
inFile.close();
return 0;
}

C: Users JohnDocumentsVisual Studio 2017ProjectsITCS2530VowelCountRelease>VowelCount.exe Constitution_of_the_United_States.html nalyzing file 'Constitution_of_the_United_States.html 2076 The number of A's: The number of E's: The number of I's: Press any key to continue .. .

Explanation / Answer

If you have any doubts, please give me comment...

// #include "stdafx.h"

// #include "windows.h"

#include <iostream>

#include <string>

#include <fstream>

int main(int argc, char *argv[])

{

// The executable name and at least one argument?

if (argc < 2)

{

std::cout << "Error with input agrs.." << std::endl;

return 1;

}

// For debugging purposes only

for (int i = 0; i < argc; i++)

{

std::cout << i << ":" << argv[i] << std::endl;

}

std::ifstream inFile;

inFile.open(argv[1]);

if (!inFile)

{

std::cout << "Error with file name.." << std::endl;

return 1;

}

std::cout<<"******************************************************************"<<std::endl;

std::cout<<"*************** Welcome to my Letter Count Program ***************"<<std::endl;

std::cout<<"******************************************************************"<<std::endl;

std::cout<<std::endl;

std::cout<<"Analyzing file '"<<argv[1]<<"'"<<std::endl<<std::endl;

///////////////////////

// Work here with open file.....

///////////////////////

int A = 0, E = 0, I = 0, O = 0, U = 1;

std::string str;

while(!inFile.eof()){

inFile>>str;

for(int i=0; i<str.size(); i++){

if(str[i]=='A' || str[i]=='a')

A++;

else if(str[i]=='E' || str[i]=='e')

E++;

else if(str[i]=='I' || str[i]=='i')

I++;

else if(str[i]=='O' || str[i]=='o')

O++;

else if(str[i]=='U' || str[i]=='u')

U++;

}

}

inFile.close();

std::cout<<"The number of A's:........................................"<<A<<std::endl;

std::cout<<"The number of E's:........................................"<<E<<std::endl;

std::cout<<"The number of I's:........................................"<<I<<std::endl;

std::cout<<"The number of O's:........................................"<<O<<std::endl;

std::cout<<"The number of U's:........................................"<<U<<std::endl;

std::cout<<"The vowel count is:......................................."<<(A+E+I+O+U)<<std::endl;

std::cout<<"Press any key to continue....";

getchar();

return 0;

}

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