/**  * @file   main.cpp  * @brief  This is the main file for the baseball champions program  * @author Connor Melton  * @date   March 12, 2013  *  */ // INCLUDE THE HEADER FILES NEEDED FOR THE FUNCTIONS TO WORK #include "baseball.h" int main() {     ifstream teamFile;     teamFile.open("./Teams.txt");     string teams[30];     int teams_count = 0;     while (getline(teamFile, teams[teams_count]))     {         teams_count++;     }     teamFile.close();     ifstream winnersFile;     winnersFile.open("./WorldSeriesWinners.txt");     // 1. Check if file opened successfully, if not exit the program     // 2a. Declare an array of strings to store data for world series winners     // 2. Load data from winnersFile to an array by calling loadWinnersFromFileToArray     // 3. Close the file stream     // Read the instructions on what else you need to finish this program     string winners[65];     int winnersCount = 0;     while (getline(winnersFile, winners[winnersCount]))     {         winnersCount++;     }     winnersFile.close();     cout << "Team Name:" << endl;     // display the list of teams     for (int i = 0; i < teams_count; i++)     {         cout << teams[i] << endl;     }     while (true)     {         string teamName;         cout << "\nEnter the name of a team, or 'quit' to exit: ";         getline(cin, teamName);         if (teamName == "quit")         {             break;         }         int wins = 0;         for (int i = 0; i < winnersCount; i++)         {             if (winners[i] == teamName && i >= 40)             { // Only count wins from 1950 to 2014 (40th element is 1950)                 wins++;             }         }         // display the number of wins         cout << teamName << " won the World Series " << wins << " times from 1950 to 2014." << endl;     }     return 0; } -----------------------------------------------------------------------------   ----------------------------------------------------------------------------- /**  * @file   baseball.h  * @brief  Declaration file  * @author Connor Melton  * @date   March 12, 2023  *  */ // START GUARD CODES # ifndef BASEBALL_H # define BASEBALL_H // INCLUDE THE HEADER FILES NEEDED FOR THE FUNCTIONS TO WORK using namespace std; #include #include #include "baseball.cpp" void loadTeamsFromFileToArray(ifstream &file, string array[], int size); void loadWinnersFromFileToArray(ifstream &file, string array[], int size); // END GUARD CODE # endif --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- /**  * @file   Baseball.cpp  * @author Connor Melton  * @brief  Implementation/Definition file  * @date   March 12, 2023  *  */ #include "baseball.h" /**  * @brief  This function loads the teams from the file into the array  * @param  file The file to read from  * @param  array The array to store the teams  * @param  size The size of the array  * @return void  */ void loadTeamsFromFileToArray(ifstream &file, string array[], int size) {     for (int i = 0; i < size; i++)     {         getline(file, array[i]);     } } /**  * @brief  This function loads the winners from the file into the array  * @param  file The file to read from  * @param  array The array to store the winners  * @param  size The size of the array  * @return void  */ void loadWinnersFromFileToArray(ifstream &file, string array[], int size) {     for (int i = 0; i < size; i++)     {         getline(file, array[i]);     } } --------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------- WorldSeriesWinners.txt New York Yankees New York Yankees New York Yankees New York Yankees New York Giants Brooklyn Dodgers New York Yankees Milwaukee Braves New York Yankees Los Angeles Dodgers Pittsburgh Pirates New York Yankees New York Yankees Los Angeles Dodgers St. Louis Cardinals Los Angeles Dodgers Baltimore Orioles St. Louis Cardinals Detroit Tigers New York Mets Baltimore Orioles Pittsburgh Pirates Oakland Athletics Oakland Athletics Oakland Athletics Cincinnati Reds Cincinnati Reds New York Yankees New York Yankees Pittsburgh Pirates Philadelphia Phillies Los Angeles Dodgers St. Louis Cardinals Baltimore Orioles Detroit Tigers Kansas City Royals New York Mets Minnesota Twins Los Angeles Dodgers Oakland Athletics Cincinnati Reds Minnesota Twins Toronto Blue Jays Toronto Blue Jays Atlanta Braves New York Yankees Florida Marlins New York Yankees New York Yankees New York Yankees Arizona Diamondbacks Anaheim Angels Florida Marlins Boston Red Sox Chicago White Sox St. Louis Cardinals Boston Red Sox Philadelphia Phillies New York Yankees San Francisco Giants St. Louis Cardinals San Francisco Giants Boston Red Sox San Francisco Giants ----------------------------------------------------------------------------------- ---------------------------------------------------------------------------------- Whydoes my program not tell me howmany winsthe teamhas?

icon
Related questions
Question

/**
 * @file   main.cpp
 * @brief  This is the main file for the baseball champions program
 * @author Connor Melton
 * @date   March 12, 2013
 *
 */
// INCLUDE THE HEADER FILES NEEDED FOR THE FUNCTIONS TO WORK
#include "baseball.h"

int main()
{
    ifstream teamFile;
    teamFile.open("./Teams.txt");

    string teams[30];
    int teams_count = 0;
    while (getline(teamFile, teams[teams_count]))
    {
        teams_count++;
    }
    teamFile.close();

    ifstream winnersFile;
    winnersFile.open("./WorldSeriesWinners.txt");

    // 1. Check if file opened successfully, if not exit the program

    // 2a. Declare an array of strings to store data for world series winners
    // 2. Load data from winnersFile to an array by calling loadWinnersFromFileToArray
    // 3. Close the file stream
    // Read the instructions on what else you need to finish this program

    string winners[65];
    int winnersCount = 0;
    while (getline(winnersFile, winners[winnersCount]))
    {
        winnersCount++;
    }
    winnersFile.close();

    cout << "Team Name:" << endl;
    // display the list of teams
    for (int i = 0; i < teams_count; i++)
    {
        cout << teams[i] << endl;
    }

    while (true)
    {
        string teamName;
        cout << "\nEnter the name of a team, or 'quit' to exit: ";
        getline(cin, teamName);
        if (teamName == "quit")
        {
            break;
        }

        int wins = 0;
        for (int i = 0; i < winnersCount; i++)
        {
            if (winners[i] == teamName && i >= 40)
            { // Only count wins from 1950 to 2014 (40th element is 1950)
                wins++;
            }
        }

        // display the number of wins
        cout << teamName << " won the World Series " << wins << " times from 1950 to 2014." << endl;
    }

    return 0;
}

-----------------------------------------------------------------------------

 

-----------------------------------------------------------------------------

/**
 * @file   baseball.h
 * @brief  Declaration file
 * @author Connor Melton
 * @date   March 12, 2023
 *
 */
// START GUARD CODES
# ifndef BASEBALL_H
# define BASEBALL_H

// INCLUDE THE HEADER FILES NEEDED FOR THE FUNCTIONS TO WORK
using namespace std;
#include <iostream>
#include <fstream>
#include "baseball.cpp"

void loadTeamsFromFileToArray(ifstream &file, string array[], int size);
void loadWinnersFromFileToArray(ifstream &file, string array[], int size);

// END GUARD CODE
# endif

---------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------

/**
 * @file   Baseball.cpp
 * @author Connor Melton
 * @brief  Implementation/Definition file
 * @date   March 12, 2023
 *
 */

#include "baseball.h"

/**
 * @brief  This function loads the teams from the file into the array
 * @param  file The file to read from
 * @param  array The array to store the teams
 * @param  size The size of the array
 * @return void
 */

void loadTeamsFromFileToArray(ifstream &file, string array[], int size)
{
    for (int i = 0; i < size; i++)
    {
        getline(file, array[i]);
    }
}

/**
 * @brief  This function loads the winners from the file into the array
 * @param  file The file to read from
 * @param  array The array to store the winners
 * @param  size The size of the array
 * @return void
 */

void loadWinnersFromFileToArray(ifstream &file, string array[], int size)
{
    for (int i = 0; i < size; i++)
    {
        getline(file, array[i]);
    }
}

---------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------

WorldSeriesWinners.txt

New York Yankees
New York Yankees
New York Yankees
New York Yankees
New York Giants
Brooklyn Dodgers
New York Yankees
Milwaukee Braves
New York Yankees
Los Angeles Dodgers
Pittsburgh Pirates
New York Yankees
New York Yankees
Los Angeles Dodgers
St. Louis Cardinals
Los Angeles Dodgers
Baltimore Orioles
St. Louis Cardinals
Detroit Tigers
New York Mets
Baltimore Orioles
Pittsburgh Pirates
Oakland Athletics
Oakland Athletics
Oakland Athletics
Cincinnati Reds
Cincinnati Reds
New York Yankees
New York Yankees
Pittsburgh Pirates
Philadelphia Phillies
Los Angeles Dodgers
St. Louis Cardinals
Baltimore Orioles
Detroit Tigers
Kansas City Royals
New York Mets
Minnesota Twins
Los Angeles Dodgers
Oakland Athletics
Cincinnati Reds
Minnesota Twins
Toronto Blue Jays
Toronto Blue Jays
Atlanta Braves
New York Yankees
Florida Marlins
New York Yankees
New York Yankees
New York Yankees
Arizona Diamondbacks
Anaheim Angels
Florida Marlins
Boston Red Sox
Chicago White Sox
St. Louis Cardinals
Boston Red Sox
Philadelphia Phillies
New York Yankees
San Francisco Giants
St. Louis Cardinals
San Francisco Giants
Boston Red Sox
San Francisco Giants

-----------------------------------------------------------------------------------

----------------------------------------------------------------------------------

Whydoes my program not tell me howmany winsthe teamhas?

Expert Solution
steps

Step by step

Solved in 6 steps with 5 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, data-structures-and-algorithms and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS