Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design an algorithm that reads characters from a file and counts and tracks the number of: Total Characters Read Letters Vowels Consonants Numbers Punctuation White

Design an algorithm that reads characters from a file and counts and tracks the number of:

  • Total Characters Read
  • Letters
  • Vowels
  • Consonants
  • Numbers
  • Punctuation
  • White Space (Space, Tab, or Newline Characters)

*Hint: You can determine some counts using some of the other counts listed above.

  • When the program begins display a program introduction message.
  • The program should prompt the user for the name of the file to open. You should display an error message if you cannot open the file.
  • If the input file opens successfully, make sure to close the input file before displaying the count information to the user on the screen.
  • If the input file opens successfully, open an output file named charsCounts.txt and write the count information to the file. If the output file opens successfully, remember to close it. Otherwise, display an error message that the output file could not be opened.
  • The program should include a loop that allows the user to run the program until they want to exit.

This is what I have so far please go off of my code and finish it/edit if ive done something worng

// Progam 4 Character Counter // Matt Cornell

#include #include #include using namespace std;

int main() { // local variables int totalChars = 0; int numLetters = 0; int numUpper = 0; int numLower = 0; int numVowels = 0; int numCons = 0; int numDig = 0; int numPunct = 0; int numWhite = 0; int other = 0; char ch; char runAgain; bool processMore; string fileName; string myFile; ifstream inFile; ofstream outFile;

//Display a welcome message cout << " Hi, Welcome to the Character Counter Program! "; do { // Get a filename from user cout << " Please enter a file name: "; getline(cin, fileName);

//open the file to read inFile.open(fileName.c_str());

// check for success if (inFile) { // Read a character at a time from the file and display it while (inFile.get(ch))// runs file until you run out of file characters { if (isalpha(ch)) { if (isupper(ch)) { numUpper++; } else { numLower++; } numLetters++; } else if (isdigit(ch)) { numDig++; } else if (isspace(ch)) { numWhite++; } else if (ispunct(ch)) { numPunct; } else { other++; } } //close the file inFile.close(); } else { cout << " There was an error opening the file. "; }

//Ask the user if they want to run the program again cout << " Would you like to run the program again? "; cin >> runAgain; } while (runAgain == 'y' || runAgain == 'Y');

system("pause"); return 0; }// end of main function

//*************Function Definition******************* bool writeData(ofstream& outFile, string filename) { //Local Variable bool open = false;

// Open File in Output mode outFile.open(filename.c_str());//.c_str makes filename a c style string

// Validate successful open if (outFile) // if (variable) will do if variable is true { // Set open flag to true open = true;

//Write the file outFile << "the number of Upper case letters is: " << ; outFile << " I hope you dont slip ";

//close the file outFile.close(); }// End of If statement return open; }// End writeData

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

Did you add the logo at correct size and proportion?

Answered: 1 week ago

Question

3. What changes should I be making?

Answered: 1 week ago

Question

2. Why?

Answered: 1 week ago