Write c++ program without using bits/stdc++.h, . You may assume
that the filename is correct, and that it is a csv file in the
format shown at the bottom of this page.
You need to use Link List.
main.cpp
#include
#include
#include
#include
#include
using namespace std;
class Node;
class Game {
public:
// Default up to
Fully-Qualified Constructor
// Copy
Constructor
// Getters / Accessor
methods
// Setters / Mutator
methods
// Utility function
to display the game
}
private:
string region;
int roundNum;
int gameNum;
string team1Name;
string team2Name;
string
winningTeam;
int team1Rank;
int team2Rank;
int team1Score;
int team2Score;
Node* subBrackets; //
This is a pointer to a Node, in order to represent the subbracts as
a linked list
};
// Node class in order to implement linked lists
class Node {
public:
Node() {
pNext = NULL;
}
Node(Game
theSubBracket, Node* thePNext) {
subBracket = theSubBracket;
pNext = thePNext;
}
Game subBracket;
Node* pNext;
};
void readInGameData(string filename, vector& games) {
string region, teamOne, teamTwo,
winningTeam;
int rankOne, rankTwo, roundNumber, gameNumber,
scoreOne, scoreTwo;
ifstream inStream;
inStream.open(filename);
assert(inStream.fail() == false);
string row;
getline(inStream, row);
while (getline(inStream, row)) {
stringstream
s_stream(row);
int colNum = 0;
while (s_stream.good())
{
string columnVal;
getline(s_stream, columnVal, ',');
// use the substring to fill in the appropriate part of the
BillboardRecord
switch (colNum) {
case 0:
region = columnVal;
break;
case 1:
rankOne = stoi(columnVal);
break;
case 2:
teamOne = columnVal;
break;
case 3:
if(columnVal != "") { scoreOne = stoi(columnVal); }
else { scoreOne = -1; }
break;
case 4:
rankTwo = stoi(columnVal);
break;
case 5:
teamTwo = columnVal;
break;
case 6:
if(columnVal != "") { scoreTwo = stoi(columnVal); }
else { scoreTwo = -1; }
break;
case 7:
winningTeam = columnVal;
break;
case 8:
roundNumber = stoi(columnVal);
break;
case 9:
gameNumber = stoi(columnVal);
break;
default:
cout << "More columns in the file than expected... Exiting
program" << endl;
exit(0);
break;
}
colNum++;
}
Game oneGame;
oneGame = Game(region,
rankOne, teamOne, scoreOne, rankTwo, teamTwo, scoreTwo,
winningTeam, roundNumber, gameNumber);
// and add it to the
vector
games.push_back(oneGame);
}
}
void determineSubBrackets(vector& games) {
for(int i=games.size()-1; i>=0; i--) {
for(int
j=games.size()-1; j>=0; j--) {
if(i==j) {
continue;
}
if( (games.at(j).getRoundNum() == (games.at(i).getRoundNum() - 1))
&&
(games.at(j).getWinner() == games.at(i).getTeamOneName() ||
games.at(j).getWinner() == games.at(i).getTeamTwoName()) ) {
// TO DO: Add games[j] to the linked list of sub-brackets for
games
// ...
}
}
}
}
int main() {
vector games;
string fileName;
cout << "Enter the name of the file with
the data for the NCAA tournament: ";
cin >> fileName;
readInGameData(fileName, games);
determineSubBrackets(games);
// TO DO: Handle the different menu
options
return 0;
}
test.csv
region,rank1,team1,score1,rank2,team2,score2,winning-team,round-number,game-number
Championship,8,North Carolina,69,1,Kansas,72,Kansas,6,1
Final Four,2,Duke,77,8,North Carolina,81,North Carolina,5,1
Final Four,2,Villanova,65,1,Kansas,81,Kansas,5,2
West,4,Arkansas,69,2,Duke,78,Duke,4,1
West,1,Gonzaga,68,4,Arkansas,74,Arkansas,3,1
West,3,Texas Tech,73,2,Duke,78,Duke,3,2
West,1,Gonzaga,82,9,Memphis,78,Gonzaga,2,1
West,12,New Mexico St.,48,4,Arkansas,53,Arkansas,2,2
West,11,Notre Dame,53,3,Texas Tech,59,Texas Tech,2,3
West,7,Michigan St.,76,2,Duke,85,Duke,2,4
West,1,Gonzaga,93,16,Georgia St.,72,Gonzaga,1,1
West,8,Boise St.,53,9,Memphis,64,Memphis,1,2
West,5,UConn,63,12,New Mexico St.,70,New Mexico St.,1,3
West,4,Arkansas,75,13,Vermont,71,Arkansas,1,4
West,6,Alabama,64,11,Notre Dame,78,Notre Dame,1,5
West,3,Texas Tech,97,14,Montana St.,62,Texas Tech,1,6
West,7,Michigan St.,74,10,Davidson,73,Michigan St.,1,7
West,2,Duke,78,15,Cal St. Fullerton,61,Duke,1,8
South,5,Houston,44,2,Villanova,50,Villanova,4,1
South,1,Arizona,60,5,Houston,72,Houston,3,1
South,11,Michigan,55,2,Villanova,63,Villanova,3,2
South,1,Arizona,85,9,TCU,80,Arizona,2,1
South,5,Houston,68,4,Illinois,53,Houston,2,2
South,11,Michigan,76,3,Tennessee,68,Michigan,2,3
South,7,Ohio St.,61,2,Villanova,71,Villanova,2,4
South,1,Arizona,87,16,Wright St.,70,Arizona,1,1
South,8,Seton Hall,42,9,TCU,69,TCU,1,2
South,5,Houston,82,12,UAB,68,Houston,1,3
South,4,Illinois,54,13,Chattanooga,53,Illinois,1,4
South,6,Colorado St.,63,11,Michigan,75,Michigan,1,5
South,3,Tennessee,88,14,Longwood,56,Tennessee,1,6
South,7,Ohio St.,54,10,Loyola Chicago,41,Ohio St.,1,7
South,2,Villanova,80,15,Delaware,60,Villanova,1,8
East,8,North Carolina,69,15,Saint Peter's,49,North
Carolina,4,1
East,8,North Carolina,73,4,UCLA,66,North Carolina,3,1
East,3,Purdue,64,15,Saint Peter's,67,Saint Peter's,3,2
East,1,Baylor,86,8,North Carolina,93,North Carolina,2,1
East,5,Saint Mary's,56,4,UCLA,72,UCLA,2,2
East,6,Texas,71,3,Purdue,81,Purdue,2,3
East,7,Murray St.,60,15,Saint Peter's,70,Saint Peter's,2,4
East,1,Baylor,85,16,Norfolk St.,49,Baylor,1,1
East,8,North Carolina,95,9,Marquette,63,North Carolina,1,2
East,5,Saint Mary's,82,12,Indiana,53,Saint Mary's,1,3
East,4,UCLA,57,13,Akron,53,UCLA,1,4
East,6,Texas,81,11,Virginia Tech,73,Texas,1,5
East,3,Purdue,78,14,Yale,56,Purdue,1,6
East,7,Murray St.,92,10,San Francisco,87,Murray St.,1,7
East,2,Kentucky,79,15,Saint Peter's,85,Saint Peter's,1,8
Midwest,1,Kansas,76,10,Miami (FL),50,Kansas,4,1
Midwest,1,Kansas,66,4,Providence,61,Kansas,3,1
Midwest,11,Iowa St.,56,10,Miami (FL),70,Miami (FL),3,2
Midwest,1,Kansas,79,9,Creighton,72,Kansas,2,1
Midwest,12,Richmond,51,4,Providence,79,Providence,2,2
Midwest,11,Iowa St.,54,3,Wisconsin,49,Iowa St.,2,3
Midwest,10,Miami (FL),79,2,Auburn,61,Miami (FL),2,4
Midwest,1,Kansas,83,16,Texas Southern,56,Kansas,1,1
Midwest,8,San Diego St.,69,9,Creighton,72,Creighton,1,2
Midwest,5,Iowa,63,12,Richmond,67,Richmond,1,3
Midwest,4,Providence,66,13,South Dakota St.,57,Providence,1,4
Midwest,6,LSU,54,11,Iowa St.,59,Iowa St.,1,5
Midwest,3,Wisconsin,67,14,Colgate,60,Wisconsin,1,6
Midwest,7,USC,66,10,Miami (FL),68,Miami (FL),1,7
Midwest,2,Auburn,80,15,Jacksonville St.,61,Auburn,1,8
1. See the sub-brackets of one game. The user will select the game, so your program should prompt them to first enter the round number of the game they would like to look at, and then the winning team of the game they would like to look at. (Note: Because there can be spaces within a team name, you may want to use cin.ignore) and/or getlined to resolve this. Also it matters whether the user input is uppercase/lowercase, i.e. "potre dame" will not match any games, but "Notre Dame" should.) Use that information to uniquely identify and find the game they are looking for. If the game is not found, display this message: Sorry, no games matching that round number and winning team were found. Otherwise, display the game and its sub-brackets using the linked list of sub-brackets for that game. If the game does not have any sub-brackets, your program should print: This game does not have any sub-brackets. The following two examples are based on the test.csv file: If the user enters round number "l" and winning team "Notre Dame", the output is: The game is: Round 1, Game 5: Alabama vs Notre Dame. Winner: Notre Dame This game does not have any sub-brackets. If the user enters round number "3" and winning team "Saint Peter's", the output is: The game is: Round 3, Game 2: Purdue vs Saint Peter's. Winner: Saint Peter's Sub-brackets of this game are: Round 2, Game 3: Texas vs Purdue. Winner: Purdue Round 2, Game 4: Murray St. vs Saint Peter's. Winner: Saint Peter's
Expected Output: Enter the name of the file with the data for the NCAA tournament: test.csv Enter the round number of the game: 1 Enter the winning team of the game: gonzaga Sorry, no games matching that round number and winning team were found. Enter the round number of the game: 1 Enter the winning team of the game: Gonzaga The game is: Round 1, Game 1: Gonzaga vs Georgia St.. Winner: Gonzaga This game does not have any sub-brackets. Enter the round number of the game: 4 Enter the winning team of the game: Gonzaga Sorry, no games matching that round number and winning team were found. Enter the round number of the game: 4 Enter the winning team of the game: North Carolina The game is: Round 4, Game 1: North Carolina vs Saint Peter's. Winner: North Carolina Sub-brackets of this game are: Round 3, Game 1: North Carolina vs UCLA. Winner: North Carolina Round 3, Game 2: Purdue vs Saint Peter's. Winner: Saint Peter's
Write c++ program without using bits/stdc++.h, . You may assume that the filename is correct, and that it is a csv file
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write c++ program without using bits/stdc++.h, . You may assume that the filename is correct, and that it is a csv file
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!