Question

Will someone please post the solution to Starting out with C++ from control structures through objects...

Will someone please post the solution to Starting out with C++ from control structures through objects 8th edition chapter 7 programming challenge # 16.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#include
#include
using namespace std;

void showMenu()
{
cout << "MLB - World Series Champion\n\n"
<< "1. Team Kane\n"
<< "2. Quit\n\n"
<< "Your choice: ";
}


void putTeams(vector &my)
{
  
my.clear();

ifstream my_team;

string teamRoster = " ";
my_team.open("Teams.txt");
if (my_team)
{
while (getline(my_team, teamRoster) && !my_team.eof())
{  
my.push_back(teamRoster);
}
}
else
{
cout << "\nThe file 'Teams.txt' could not be opened\n";

}

my_team.close();
}


void findWinner(vector &winners)
{

ifstream my_team;

string winner = " ";

my_team.open("WorldSeriesWinners.txt");

if (my_team)
{
while (getline(my_team, winner) && !my_team.eof())
{
winners.push_back(winner);
}
}
else
{
cout << "\nThe file 'WorldSeriesWinners.txt' could not be opened\n";
}

my_team.close();
}

void print(const vector winners, const vector teams)
{

string teamName = " ";
int cnt = 0;

cout << "\nTeam Kane:\n\n";
for (string v : teams)
{
cout << v << "\n";
}

cout << "\nEnter a team name: ";
cin.get();
getline(cin, teamName);

for (size_t n = 0; n < winners.size(); n++)
{
if (teamName == winners[n])
{
cnt++;
}
}

cout << "\nThe " << teamName << " have won the Major League Baseball "
<< "World Series " << cnt << " times!\n\n";
}

int main()
{
showMenu();
const int KANE = 1,Quit = 2;
int choice = 0;

vector teams = { " " };
vector winners = { " " };

do
{
cin >> (choice);
switch (choice)
{
case 1:
winners.clear();
teams.clear();

putTeams(teams);
findWinner(winners);
print(winners, teams);

showMenu();
break;

case 2:
if (choice == Quit)
{
cout << "Thanks for using this program!\n"
<< "(Now exiting ...)";
}
break;
}
} while (choice != Quit);
return 0;
}

=========================
#include<iostream» #include«vector» #include«fstream» using namespace std; MLBWORLD SERIES CHAMPION DATABASE MAIN MENU 1. INT

Know the answer?
Add Answer to:
Will someone please post the solution to Starting out with C++ from control structures through objects...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT