Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7666733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:54:35+00:00 2026-05-31T14:54:35+00:00

I am completely stuck. This is my incomplete program. The program gets stuck at

  • 0

I am completely stuck. This is my incomplete program. The program gets stuck at the.at or if determine if vowel line. I need some advice to fix my program. What the program is supposed to do take a text file that contains these lines:

C++ Programming is fun
Winter is here, will it ever end?
The style requirements document is so useful
Functions really make programming easier
Spring must be coming soon...
I wish this #$##$$!!## program was done
What comes after C++, D--?

I am supposed to do some calculations and export to a file so it looks like in this link: http://tinypic.com/r/24fhbfb/5

Here is my code so far. Any pointers on what I’m doing wrong would be much appreciated. I must do everything in functions.

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

void OpenFiles (ifstream& inFile, ofstream& outFile);

void OutputDivider (ofstream& outFile, char symbol, int num);

void SetFileMessage (ifstream& inFile, bool& fileFound, string& message); 

void OutputFileMessage (bool& fileFound, ofstream& outFile, string& message);

void InitializeFileCounters (int& lineCounter, int& totalOfAs, int& characterTotal);

void OutputHeading (ofstream& outFile, string information, string name, int width);

string ReadALine (ifstream& inFile, int& lineLength);

void InitializeLineCounters (int& vowelCounter, int& charactersOfA, int& blankCounter);

void CalculateLineStats (ifstream& inFile, string readLine, int& vowelCounter, int&   lineLength,
                        int& blankCounter, int&  charactersOfA);



//Header to display in output file
const string INFORMATION = "CST 133 - Exercise 4";
const string MY_NAME = "Tom Hangler";

//Width of screen for dividers
const int SCREEN_WIDTH = 110;

int main(void)
{
    ifstream fin;
    ofstream fout;

    bool fileFound;

    string message;
    string lineCopy;

    int lineCounter;
    int totalOfAs;
    int characterTotal;
    int vowelCounter;
    int charactersOfA;
    int blankCounter;
    int lineLength;

    //Open input and output text files
    OpenFiles(fin, fout);

    //Set message based on if file was found or not
    SetFileMessage(fin, fileFound, message);

    //Output message to text file if file was not found
    OutputFileMessage(fileFound, fout, message);

    if (fileFound)
    {
        InitializeFileCounters(lineCounter, totalOfAs, characterTotal);

        OutputHeading(fout, INFORMATION, MY_NAME, SCREEN_WIDTH);

        InitializeLineCounters(vowelCounter, charactersOfA, blankCounter);

       ReadALine(fin, lineLength);

        CalculateLineStats(fin, lineCopy, vowelCounter, lineLength, blankCounter, charactersOfA);

        ReadALine(fin, lineLength);

    }   

    return 0;
}

void OpenFiles (ifstream& inFile, ofstream& outFile)
{
    inFile.open("LinesEx4.txt");
    outFile.open("Ex4Out.txt");
}

 void OutputDivider (ofstream& outFile, char symbol, int num)
{ 
    //Ouput to text file a divider with symbol '-' and specified length in 'num'
    outFile << setfill(symbol) << setw(num) << symbol << endl;
}

void SetFileMessage (ifstream& inFile, bool& fileFound, string& message)
{
    if (!inFile)
    {
        //Set message string to file not found.
        message = "Input file was not found.";

        //Set the file found flag 
        fileFound = false;
    }
    else
    {
        //Set the file found flag
        fileFound = true;

        //Set message string to file not found.
        message = "Processing continues, file successfully opened.";
    }
}

void OutputFileMessage (bool& fileFound, ofstream& outFile, string& message)
{
    if (fileFound == false)
    {
        //Output divider to text file
        OutputDivider(outFile, '-', SCREEN_WIDTH);

        //Output message to text file.
        outFile << message << endl;

        //Output divider to text file
        OutputDivider(outFile, '-', SCREEN_WIDTH);
    }
    else 
    {
        //Output divider to text file
        OutputDivider(outFile, '-', SCREEN_WIDTH);

        //Output message to text file.
        outFile << message << endl;

        //Output divider to text file
        OutputDivider(outFile, '-', SCREEN_WIDTH);
    }
 }

void InitializeFileCounters (int& lineCounter, int& totalOfAs, int& characterTotal)
{
    //Initialize variables for total counting
    lineCounter = 0;
    totalOfAs = 0;
    characterTotal = 0;
}

void OutputHeading (ofstream& outFile, string information, string name, int width)
{
    outFile << '\n' << endl;

    OutputDivider(outFile, '*', width);

    outFile << setfill(' ') << setw((width + information.length()) / 2) << information << endl;

    outFile << setfill(' ') << setw((width + name.length()) / 2) << name << endl;

     outFile << "Line" << setw(50) << "Length" << setw(15) << "# of Vowels" << 
    setw(15) << "# of As" << setw(15) << "# of Blanks" << endl;

     OutputDivider(outFile, '*', width);
  }

 string ReadALine (ifstream& inFile, int& lineLength)
{
     string readLine;

    getline(inFile, readLine);
    lineLength = readLine.length();

    return readLine;
}

void InitializeLineCounters (int& vowelCounter, int& charactersOfA, int& blankCounter)
 {
     //Initialize variables for line analysis
     vowelCounter = 0;
    charactersOfA = 0;
    blankCounter = 0;
}

void CalculateLineStats (ifstream& inFile, string readLine, int& vowelCounter, int&    lineLength,
                                int& blankCounter, int&  charactersOfA)
{
    int index;

     for (index = 0; index < lineLength; index++)
   {
        if (readLine.at(index) == 'A' || readLine.at(index) == 'E' || readLine.at(index) == 'I'
                    || readLine.at(index) == 'O' || readLine.at(index) == 'U')
        {
            vowelCounter++;
        }
        if (readLine.at(index) == ' ')
        {
             blankCounter++;
        } 
        if (readLine.at(index) == 'A') 
        {
            charactersOfA++;
         }
    }  

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:54:36+00:00Added an answer on May 31, 2026 at 2:54 pm

    You are not storing the return value from ReadALine() but pass lineLength > 0 to CalculateLineStats(). This will result in at() throwing a std::out_of_range exception, which is not caught by the caller and will result in abnormal termination of the program.

    Change to:

    lineCopy = ReadALine(fin, lineLength);
    

    There is no reason to store the lineLength in a separate variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've done some jQuery in the past, but I am completely stuck on this.
So I haven't been doing this for long but I'm completely stuck on this.
I'm completely stuck and need your help... I've created a webservice stub with jaxb
I am completely stuck on this issue so your help is greatly appreciated! I
I am completely stuck with this: I start out with a flat file type
I am completely stuck on this one. I know my code is correct. It
Hello everyone I am completely stuck with this problem. I want add the name
guys i really REALLY need some help on this one. 2 days i've been
I post this here as a last resort. I'm completely stuck and do not
I am completely stuck with this problem I'm having with excel. Basically I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.