****PLEASE CODE IN C++ and line doc explaining what is
happening!*****
**HERE IS THE INPUT FILE(.txt)*****
Ottawa Senators
New York Rangers
Boston Bruins
Montreal Canadiens
Montreal Canadiens
Toronto Maple Leafs
New York Rangers
Chicago Blackhawks
Montreal Maroons
Detroit Red Wings
Detroit Red Wings
Chicago Blackhawks
Boston Bruins
New York Rangers
Boston Bruins
Toronto Maple Leafs
Detroit Red Wings
Montreal Canadiens
Toronto Maple Leafs
Montreal Canadiens
Toronto Maple Leafs
Toronto Maple Leafs
Toronto Maple Leafs
Detroit Red Wings
Toronto Maple Leafs
Detroit Red Wings
Montreal Canadiens
Detroit Red Wings
Detroit Red Wings
Montreal Canadiens
Montreal Canadiens
Montreal Canadiens
Montreal Canadiens
Montreal Canadiens
Chicago Blackhawks
Toronto Maple Leafs
Toronto Maple Leafs
Toronto Maple Leafs
Montreal Canadiens
Montreal Canadiens
Toronto Maple Leafs
Montreal Canadiens
Montreal Canadiens
Boston Bruins
Montreal Canadiens
Boston Bruins
Montreal Canadiens
Philadelphia Flyers
Philadelphia Flyers
Montreal Canadiens
Montreal Canadiens
Montreal Canadiens
Montreal Canadiens
New York Islanders
New York Islanders
New York Islanders
New York Islanders
Edmonton Oilers
Edmonton Oilers
Montreal Canadiens
Edmonton Oilers
Edmonton Oilers
Calgary Flames
Edmonton Oilers
Pittsburgh Penguins
Pittsburgh Penguins
Montreal Canadiens
New York Rangers
New Jersey Devils
Colorado Avalanche
Detroit Red Wings
Detroit Red Wings
Dallas Stars
New Jersey Devils
Colorado Avalanche
Detroit Red Wings
New Jersey Devils
Tampa Bay Lightning
Not Awarded
Carolina Hurricanes
Anaheim Ducks
Detroit Red Wings
Pittsburgh Penguins
Chicago Blackhawks
Boston Bruins
Los Angeles Kings
Chicago Blackhawks
Los Angeles Kings
Chicago Blackhawks
Pittsburgh Penguins
Pittsburgh Penguins
Washington Capitals
Overview
The Stanley Cup is the trophy awarded annually to the playoff
champion of the National Hockey League (NHL). It is the oldest
professional sports trophy in North America.
For this assignment, write a program that will process a file
of data that contains the winners of the Stanley Cup between 1927
and 2018. It will allow the user of the program to name a hockey
team and learn how many times that the team has won the Stanley
Cup.
Processing
The main function for this program is pretty basic. It should
start by creating an array that can hold a maximum of 100 string
elements. Each element in the array will be the name of a team that
won the Stanley Cup (or "Not Awarded"). There should also be an
integer to hold the number of teams that are in the array, an
integer to hold the number of times a specific team has won the
Stanley Cup, and a string to hold a specific team name.
Call the buildArray function that is described below to fill
the array with the names of the teams. The value returned from the
function should be saved in the integer that was created to hold
the number of teams that are in the array.
Display the integer value that is returned from the buildArray
function with an appropriate label.
Prompt the user for the name of a hockey team and save the
value in the string variable.
Call the numWins function that is described below to find the
number of times the selected team has won the Stanley Cup. The
value returned from the function should be saved in the integer
that was created to hold the number of times that a specific team
has won the Stanley Cup.
Finally, display either the number of times that the selected
team has won the Stanley Cup or the number of times that the Cup
was not awarded if the user entered "Not Awarded".
Reading a string
In the previous assignments, whenever an input operation was
performed, the input operator (>>) was used with either cin
or an input file stream variable. This worked because the
information that was being inputted was either separated by
whitespace (a space or a newline character) or was being read one
character at a time.
For this assignment, the input operator CANNOT be used because
the team names will have at least one space separating the parts of
the name. For example:
Chicago Blackhawks
New York Rangers
Rather than trying to read the team names in parts, it should
be read as a "whole" string. To do this, the getline function must
be used. The format for getline is:
getline( name_of_the_input_stream,
name_of_the_string_to_hold_data );
So, if the information should come from standard input (the
keyboard):
string str;
getline( cin, str );
or from an input file:
string str;
getline( infile, str );
The Functions
For this program, two functions are required:
int buildArray( string team_array[] )
This function will place the values from the input file into
the passed in array of strings.
It takes one argument: an array of strings that will be filled
with the names of the teams that have won the Stanley Cup. It
returns an integer: the number of teams that were placed into the
array.
This function should use a standard read loop pattern to read
the data from the file and place it into the array. Read the first
team name from the file. In a loop that executes while there is
data in the file, put the team name that was read into the array,
update the array subscript, and get another name from the
file.
Once all of the data has been read from the file, return the
number of teams that were placed into the array.
int numWins( string team_array[], int numTeams, string
search_team )
This function will search the array of Stanley Cup winning
teams to determine the number of times that a specific team has won
the Stanley Cup.
It takes three arguments: an array of strings that will be
searched, an integer that represents the number of teams that are
in the array (ie. the number of teams to be searched), and a string
that represents the specific team to search for in the array. It
returns an integer: the number of times that the specified team was
found in the array.
In a loop that executes exactly one time for the number of
teams that are in the array (ie. numTeams number of times), check
to see if the specific team to search for in the array (ie.
search_team) is found in the array of strings that will be searched
(ie. team_array). If the specific team is found, increment a
counter by 1.
Once the loop is finished executing, return the counter.
Symbolic Constant
This program requires the use of 1 symbolic constant. The
constant should represent the maximum number of teams that can be
placed into the array. The value should be 100.
Programming Requirements:
1. Add #include <cstdlib> and #include <fstream>
at the top of the program. Depending on the compiler, #include
<string> might also have to be added at the top of the
program to be able to use the getline function.
Output
The output will depend on the teams that the user
specifies.
Run 1
There are 92 entries in the input file
Team? Chicago Blackhawks
The Chicago Blackhawks have won the Stanley Cup 6
time(s).
Run 2
There are 92 entries in the input file
Team? Montreal Canadiens
The Montreal Canadiens have won the Stanley Cup 22
time(s).
Run 3
There are 92 entries in the input file
Team? Not Awarded
The Stanley Cup was not awarded 1 time(s).
Run 4
There are 92 entries in the input file
Team? Nashville Predators
The Nashville Predators have won the Stanley Cup 0
time(s).