Question: I need help with this C++ program. I am attempting to reorder data from a text file, the details are below: ********* BELOW: superbowlReorder.cpp ************
I need help with this C++ program. I am attempting to reorder data from a text file, the details are below:
********* BELOW: superbowlReorder.cpp ************
/* This file will read from superbowl.txt and reorder them in the correct order. The original order is from 50 - 1 After order should be 1 - 50 */ #include
// String class is use to convert string to integer
string removeSpaces(string);
int main(int argc, char const *argv[]) {
// Variables for input and output files string originalSBFile = "originalSBFile.txt"; string sortedSBFile = "sortedSBFile.txt";
int numOfSuperbowls = 50;
string* lines = new string[numOfSuperbowls];
string* dates = new string[numOfSuperbowls]; string* num = new string[numOfSuperbowls]; string* winningTeam = new string[numOfSuperbowls]; string* losingTeam = new string[numOfSuperbowls]; string* MVP = new string[numOfSuperbowls]; string* stadium = new string[numOfSuperbowls]; string* stadiumCity = new string[numOfSuperbowls]; string* stadiumState = new string[numOfSuperbowls];
int* winningTeamScore = new int[numOfSuperbowls]; int* losingTeamScore = new int[numOfSuperbowls];
/* To get each item in each line. Will have to get the line number and use in for loop to move through column Line Number: Row For loop Interator: Column */
// Input file ifstream input; input.open(originalSBFile);
int lineNumber = 0; string line;
// Check if file is open if (!input.is_open()) { cout << "Error couldn\'t open!"; exit(1); }else { //
while (getline(input,line)) { line = removeSpaces(line); lines[lineNumber] = line;
lineNumber++; } } input.close();
/*
for(int i = 0;i < numOfSuperbowls;i++){ cout << lines[i] << endl; char* lineToChar = new char[lines[i].length() + 1]; char* word = new char[30]; strcpy(lineToChar,lines[i].c_str()); //cout << lines[i] << endl; // for (int counter = 0; counter < lines[i].length() + 1; counter++) { // if (counter > 0) { // if (lineToChar[counter] == '\t') { // //cout << lineToChar[counter]; // //std::cout << "tab" << ' '; // }else{ // //cout << word[counter]; // word[counter] = lineToChar[counter]; // } // } // else { // //cout << word[counter] << endl; // word[counter] = lineToChar[counter]; // } // }
// for(int j = 0;j <10;j++){ // switch (j) { // case 0: // dates[i] = lines[j] // break; // case 1: // num[i] = lines[j]; // break; // case 2: // winningTeam[i] = lines[j]; // break; // case 3: // winningTeamScore[i] = lines[j]; // break; // case 4: // losingTeam[i] = lines[j]; // break; // case 5: // losingTeamScore[i] = lines[j]; // break; // case 6: // MVP[i] = lines[j]; // break; // case 7: // stadium[i] = lines[j]; // break; // case 8: // stadiumCity[i] = lines[j]; // break; // case 9: // stadiumState[i] = lines[j]; // break; // default: // break; // } // } }
*/ return 0; }
/*----------Remove Spaces Method-----------*/ // https://stackoverflow.com/questions/16329358/remove-spaces-from-a-string-in-c string removeSpaces(string input) { input.erase(std::remove(input.begin(),input.end(),' '),input.end()); return input; }
********* BELOW: originalSBFile.txt ************
5-Feb-17 LI (51) New England Patriots 34 Atlanta Falcons 28 Tom Brady NRG Stadium Houston Texas 7-Feb-16 L (50) Denver Broncos 24 Carolina Panthers 10 Von Miller Levi's Stadium Santa Clara California 1-Feb-15 XLIX (49) New England Patriots 28 Seattle Seahawks 24 Tom Brady University of Phoenix Stadium Glendale Arizona 2-Feb-14 XLVIII (48) Seattle Seahawks 43 Denver Broncos 8 Malcolm Smith MetLife Stadium East Rutherford New Jersey 3-Feb-13 XLVII (47) Baltimore Ravens 34 San Francisco 49ers 31 Joe Flacco Mercedes-Benz Superdome New Orleans Louisiana 5-Feb-12 XLVI (46) New York Giants 21 New England Patriots 17 Eli Manning Lucas Oil Stadium Indianapolis Indiana 6-Feb-11 XLV (45) Green Bay Packers 31 Pittsburgh Steelers 25 Aaron Rodgers Cowboys Stadium Arlington Texas 7-Feb-10 XLIV (44) New Orleans Saints 31 Indianapolis Colts 17 Drew Brees Sun Life Stadium Miami Gardens Florida 1-Feb-09 XLIII (43) Pittsburgh Steelers 27 Arizona Cardinals 23 Santonio Holmes Raymond James Stadium Tampa Florida 3-Feb-08 XLII (42) New York Giants 17 New England Patriots 14 Eli Manning University of Phoenix Stadium Glendale Arizona 4-Feb-07 XLI (41) Indianapolis Colts 29 Chicago Bears 17 Peyton Manning Dolphin Stadium Miami Gardens Florida 5-Feb-06 XL (40) Pittsburgh Steelers 21 Seattle Seahawks 10 Hines Ward Ford Field Detroit Michigan 6-Feb-05 XXXIX (39) New England Patriots 24 Philadelphia Eagles 21 Deion Branch Alltel Stadium Jacksonville Florida 1-Feb-04 XXXVIII (38) New England Patriots 32 Carolina Panthers 29 Tom Brady Reliant Stadium Houston Texas 26-Jan-03 XXXVII (37) Tampa Bay Buccaneers 48 Oakland Raiders 21 Dexter Jackson Qualcomm Stadium San Diego California 3-Feb-02 XXXVI (36) New England Patriots 20 St. Louis Rams 17 Tom Brady Louisiana Superdome New Orleans Louisiana 28-Jan-01 XXXV (35) Baltimore Ravens 34 New York Giants 7 Ray Lewis Raymond James Stadium Tampa Florida 30-Jan-00 XXXIV (34) St. Louis Rams 23 Tennessee Titans 16 Kurt Warner Georgia Dome Atlanta Georgia 31-Jan-99 XXXIII (33) Denver Broncos 34 Atlanta Falcons 19 John Elway Pro Player Stadium Miami Gardens Florida 25-Jan-98 XXXII (32) Denver Broncos 31 Green Bay Packers 24 Terrell Davis Qualcomm Stadium San Diego California 26-Jan-97 XXXI (31) Green Bay Packers 35 New England Patriots 21 Desmond Howard Louisiana Superdome New Orleans Louisiana 28-Jan-96 XXX (30) Dallas Cowboys 27 Pittsburgh Steelers 17 Larry Brown Sun Devil Stadium Tempe Arizona 29-Jan-95 XXIX (29) San Francisco 49ers 49 San Diego Chargers 26 Steve Young Joe Robbie Stadium Miami Gardens Florida 30-Jan-94 XXVIII (28) Dallas Cowboys 30 Buffalo Bills 13 Emmitt Smith Georgia Dome Atlanta Georgia 31-Jan-93 XXVII (27) Dallas Cowboys 52 Buffalo Bills 17 Troy Aikman Rose Bowl Pasadena California 26-Jan-92 XXVI (26) Washington Redskins 37 Buffalo Bills 24 Mark Rypien Metrodome Minneapolis Minnesota 27-Jan-91 XXV (25) New York Giants 20 Buffalo Bills 19 Ottis Anderson Tampa Stadium Tampa Florida 28-Jan-90 XXIV (24) San Francisco 49ers 55 Denver Broncos 10 Joe Montana Louisiana Superdome New Orleans Louisiana 22-Jan-89 XXIII (23) San Francisco 49ers 20 Cincinnati Bengals 16 Jerry Rice Joe Robbie Stadium Miami Gardens Florida 31-Jan-88 XXII (22) Washington Redskins 42 Denver Broncos 10 Doug Williams Jack Murphy Stadium San Diego California 25-Jan-87 XXI (21) New York Giants 39 Denver Broncos 20 Phil Simms Rose Bowl Pasadena California 26-Jan-86 XX (20) Chicago Bears 46 New England Patriots 10 Richard Dent Louisiana Superdome New Orleans Louisiana 20-Jan-85 XIX (19) San Francisco 49ers 38 Miami Dolphins 16 Joe Montana Stanford Stadium Palo Alto California 22-Jan-84 XVIII (18) Los Angeles Raiders 38 Washington Redskins 9 Marcus Allen Tampa Stadium Tampa Florida 30-Jan-83 XVII (17) Washington Redskins 27 Miami Dolphins 17 John Riggins Rose Bowl Pasadena California 24-Jan-82 XVI (16) San Francisco 49ers 26 Cincinnati Bengals 21 Joe Montana Pontiac Silverdome Pontiac Michigan 25-Jan-81 XV (15) Oakland Raiders 27 Philadelphia Eagles 10 Jim Plunkett Louisiana Superdome New Orleans Louisiana 20-Jan-80 XIV (14) Pittsburgh Steelers 31 Los Angeles Rams 19 Terry Bradshaw Rose Bowl Pasadena California 21-Jan-79 XIII (13) Pittsburgh Steelers 35 Dallas Cowboys 31 Terry Bradshaw Orange Bowl Miami Florida 15-Jan-78 XII (12) Dallas Cowboys 27 Denver Broncos 10 Harvey Martin Superdome New Orleans Louisiana 9-Jan-77 XI (11) Oakland Raiders 32 Minnesota Vikings 14 Fred Biletnikoff Rose Bowl Pasadena California 18-Jan-76 X (10) Pittsburgh Steelers 21 Dallas Cowboys 17 Lynn Swann Orange Bowl Miami Florida 12-Jan-75 IX (9) Pittsburgh Steelers 16 Minnesota Vikings 6 Franco Harris Tulane Stadium New Orleans Louisiana 13-Jan-74 VIII (8) Miami Dolphins 24 Minnesota Vikings 7 Larry Csonka Rice Stadium Houston Texas 14-Jan-73 VII (7) Miami Dolphins 14 Washington Redskins 7 Jake Scott Memorial Coliseum Los Angeles California 16-Jan-72 VI (6) Dallas Cowboys 24 Miami Dolphins 3 Roger Staubach Tulane Stadium New Orleans Louisiana 17-Jan-71 V (5) Baltimore Colts 16 Dallas Cowboys 13 Chuck Howley Orange Bowl Miami Florida 11-Jan-70 IV (4) Kansas City Chiefs 23 Minnesota Vikings 7 Len Dawson Tulane Stadium New Orleans Louisiana 12-Jan-69 III (3) New York Jets 16 Baltimore Colts 7 Joe Namath Orange Bowl Miami Florida 14-Jan-68 II (2) Green Bay Packers 33 Oakland Raiders 14 Bart Starr Orange Bowl Miami Florida 15-Jan-67 I (1) Green Bay Packers 35 Kansas City Chiefs 10 Bart Starr Memorial Coliseum Los Angeles California
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
