Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help I am having a bunch of code errors still. Overview The Stanley Cup is the trophy awarded annually to the playoff champion of

please help I am having a bunch of code errors still.

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.

Input File

The file with the input data can be downloaded and saved on your computer. It is called stanley_cup.txt and can be found here:

http://faculty.cs.niu.edu/~byrnes/csci240/pgms/stanley_cup.txt

The file contains the names of the teams that have won the Stanley Cup in the order that they were won from 1927 through 2018. The Stanley Cup was not awarded in the year 2005 because the season was cancelled due to a lockout. Therefore, that year has the string "Not Awarded" rather than a team name.

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:

Add #include and #include at the top of the program. Depending on the compiler, #include might also have to be added at the top of the program to be able to use the getline function.

As with program 6, each of the functions should have a documentation box that describes the function. This is the last reminder about function documentation that will appear in the assignment write-ups.

Hand in a copy of the source code using Blackboard.

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). 

Extra Credit 1

For up to 5 points of extra credit, modify the program to include a display of the years that the user's specified team won the Stanley Cup.

The modification should be made by coding a third function named displayYears, that should be called in main. However, it should only be called if the team has won a Stanley Cup.

void displayYears( string team_array[], int numTeams, string search_team )

This function will search the array of Stanley Cup winning teams to determine and display the exact years 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 nothing.

The years should be displayed with a maximum of 6 values per line of output.

Extra Credit 1 Output

Run 1

There are 92 entries in the input file Team? Chicago Blackhawks The Chicago Blackhawks have won the Stanley Cup 6 time(s). 1934 1938 1961 2010 2013 2015 

Run 2

There are 92 entries in the input file Team? Montreal Canadiens The Montreal Canadiens have won the Stanley Cup 22 time(s). 1930 1931 1944 1946 1953 1956 1957 1958 1959 1960 1965 1966 1968 1969 1971 1973 1976 1977 1978 1979 1986 1993 

Run 3

There are 92 entries in the input file Team? Not Awarded The Stanley Cup was not awarded 1 time(s). 2005 

Run 4

There are 92 entries in the input file Team? Nashville Predators The Nashville Predators have won the Stanley Cup 0 time(s). 

Extra Credit 2

For up to 5 points of extra credit, modify the program to include a display of all of the teams that have won the Stanley Cup.

The modification should be made by coding a fourth function named displayTeams, that should be called in main.

void displayTeams( string team_array[], int numTeams )

This function will display a listing of the teams that have won the Stanley Cup along with the year that the Cup was won.

It takes two arguments: an array of strings that will be displayed, and an integer that represents the number of teams that are in the array (ie. the number of teams to be displayed). It returns nothing.

Extra Credit 1 DOES NOT have to be attempted to receive the extra credit points for Extra Credit 2.

Note about extra credit: the points will ONLY be awarded if the required portions of the assignment work correctly. In other words, don't take short cuts in the rest of the program because it is assumed that 5 extra points will be awarded.

Extra Credit 2 Output

All of the teams that have won the Stanley Cup ---------------------------------------------- 1927 Ottawa Senators 1928 New York Rangers 1929 Boston Bruins 1930 Montreal Canadiens 1931 Montreal Canadiens 1932 Toronto Maple Leafs 1933 New York Rangers 1934 Chicago Blackhawks 1935 Montreal Maroons 1936 Detroit Red Wings 1937 Detroit Red Wings 1938 Chicago Blackhawks 1939 Boston Bruins 1940 New York Rangers 1941 Boston Bruins 1942 Toronto Maple Leafs 1943 Detroit Red Wings 1944 Montreal Canadiens 1945 Toronto Maple Leafs 1946 Montreal Canadiens 1947 Toronto Maple Leafs 1948 Toronto Maple Leafs 1949 Toronto Maple Leafs 1950 Detroit Red Wings 1951 Toronto Maple Leafs 1952 Detroit Red Wings 1953 Montreal Canadiens 1954 Detroit Red Wings 1955 Detroit Red Wings 1956 Montreal Canadiens 1957 Montreal Canadiens 1958 Montreal Canadiens 1959 Montreal Canadiens 1960 Montreal Canadiens 1961 Chicago Blackhawks 1962 Toronto Maple Leafs 1963 Toronto Maple Leafs 1964 Toronto Maple Leafs 1965 Montreal Canadiens 1966 Montreal Canadiens 1967 Toronto Maple Leafs 1968 Montreal Canadiens 1969 Montreal Canadiens 1970 Boston Bruins 1971 Montreal Canadiens 1972 Boston Bruins 1973 Montreal Canadiens 1974 Philadelphia Flyers 1975 Philadelphia Flyers 1976 Montreal Canadiens 1977 Montreal Canadiens 1978 Montreal Canadiens 1979 Montreal Canadiens 1980 New York Islanders 1981 New York Islanders 1982 New York Islanders 1983 New York Islanders 1984 Edmonton Oilers 1985 Edmonton Oilers 1986 Montreal Canadiens 1987 Edmonton Oilers 1988 Edmonton Oilers 1989 Calgary Flames 1990 Edmonton Oilers 1991 Pittsburgh Penguins 1992 Pittsburgh Penguins 1993 Montreal Canadiens 1994 New York Rangers 1995 New Jersey Devils 1996 Colorado Avalanche 1997 Detroit Red Wings 1998 Detroit Red Wings 1999 Dallas Stars 2000 New Jersey Devils 2001 Colorado Avalanche 2002 Detroit Red Wings 2003 New Jersey Devils 2004 Tampa Bay Lightning 2005 Not Awarded 2006 Carolina Hurricanes 2007 Anaheim Ducks 2008 Detroit Red Wings 2009 Pittsburgh Penguins 2010 Chicago Blackhawks 2011 Boston Bruins 2012 Los Angeles Kings 2013 Chicago Blackhawks 2014 Los Angeles Kings 2015 Chicago Blackhawks 2016 Pittsburgh Penguins 2017 Pittsburgh Penguins 2018 Washington Capitals

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

Step: 3

blur-text-image

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

Decisions Based On Data Analytics For Business Excellence

Authors: Bastian Weber

1st Edition

9358681683, 978-9358681680

More Books

Students also viewed these Databases questions

Question

1. Identify and control your anxieties

Answered: 1 week ago