// // NCAA_Stats.cpp: performs a search of a NCAA database // // Programmer: Kyle Stratton, kydostra@vt.edu // Modified: Kyle Stratton, kydostra@vt.edu // Date: 4/28/11 // Section : CS1044: #11990 // Compiler: MS Visual C++ Express version 2010 // Platform: Intel(R) Core(TM) i7 CPU 2.67GHz / Windows 7 Professional 64-bit (6.1, Build 7600) // // Purpose of the program: // // The program will analyze two input files (NCAAdata.txt and NCAAinfo.txt). The info file will contain search commands that will // search certain things in the data file. This will all be output to an output file (NCAAlog.txt). /* Top-Down Analysis I. Beginning A. Declare variables 1. make structure B. Opens treams II. Array of Strctures A. Take values for structure B. Order values for structure III. While loops A. check which command is called 1. call appropriate function i. margin - sums margin values and divides by margin of years ii. year - tells runner up or winner one year iii. titles - shows number of titles someone won IV. Output */ //C++ libraries #include #include #include #include #include #include #include using namespace std; //made this stuff global because it wouldnt work otherwise struct Data { int Year; //year of the championship string Winner; //winner's name of the championship int WinnerScore; //score of the winner string RunnerUp; //runner up's name int RunnerUpScore; //runner up's score }; /////////////////////////////////////////////////////////////// // Sorting // // Description of the method: // sorts things in order // Parameters: // i: first index parameter // j: second index parameter // smallestIndex: keps track of smallest index // temp: temporarily holds an index // Championship[]: the array of structures // ChampAmounts: the total number of championships // // Summons: main() // /////////////////////////////////////////////////////////////// void sortByYear(Data Championship[], int ChampAmounts) { int i, j, smallestIndex; Data temp; //cout << "aaa1" << endl; for (i=0; i< ChampAmounts; i++){ smallestIndex = i; for (j = i+1; j < ChampAmounts; j++){ //cout << "aaa2 " << i << " " << j << endl; if (Championship[j].Year < Championship[smallestIndex].Year) smallestIndex = j; } if (smallestIndex != i){ temp = Championship[i]; Championship[i] = Championship[smallestIndex]; Championship[smallestIndex] = temp; } } //cout << "aaa3 " << i << " " << j << endl; // return temp; } /////////////////////////////////////////////////////////////// // YearCommand // // Description of the method: // does the year command for the info file by cycling through the array for the year desired // Parameters: // i: index parameter // Year: the value of the year // TeamName: the name of the team // Championship[]: the array of structures // ChampAmounts: the total number of championships // YearValue: the year being issued in the command // TeamValue: the number (1 or 2) being issued in the command for the team // // Summons: main() // /////////////////////////////////////////////////////////////// string YearCommand (Data Championship[], int YearValue, int TeamValue, int ChampAmounts) { int i=0; int Year=Championship[i].Year; string TeamName; bool found = false; for(int j = 0; j < ChampAmounts; j++){ if(Championship[j].Year==YearValue){ cout << "found" << YearValue << endl; found = true; break;} i++; } if (found == true){ if (TeamValue==1) { TeamName=Championship[i].Winner; return "Champion: " + TeamName; } else{ TeamName=Championship[i].RunnerUp; return "Runner-Up: " + TeamName; }} else{ cout << "not found " << YearValue << endl; //convert int to string string temp; stringstream out; out << YearValue; return out.str() +" not found"; }} /////////////////////////////////////////////////////////////// // Winning // // Description of the method: // does the title command for winning for the info file by cycling through the // Parameters: // i: index parameter // TitleTeam: name of the team // Championship[]: the array of structures // ChampAmounts: the total number of championships // Winners: number of times winning // // Summons: main() // /////////////////////////////////////////////////////////////// int Winning(Data Championship[], string TitleTeam, int ChampAmounts) { int Winners=0; for(int i=0;i> ChampAmounts; //taking the amount of championships cout << ChampAmounts << endl; Data *Championship = new Data[ChampAmounts]; //the array struct of the championships DataFile.ignore(INT_MAX,'\n'); //ignoring the next line for(int n=0;n> Championship[n].Year; //year DataFile.ignore(INT_MAX,'\t'); //ignore getline(DataFile, Championship[n].Winner,'\t'); //winner DataFile >> Championship[n].WinnerScore; //winerscore DataFile.ignore(INT_MAX,'\t'); //ignore getline(DataFile, Championship[n].RunnerUp,'\t'); //runnerup DataFile >> Championship[n].RunnerUpScore; //runnerup score } cout << "zzz1" << endl; for(int x=0; x<8; x++) { cout << Championship[x].Year << ":" << Championship[x].Winner << ":" << Championship[x].WinnerScore; cout << ":" << Championship[x].RunnerUp << ":" << Championship[x].RunnerUpScore << endl; } sortByYear(Championship, ChampAmounts); //calling the sorting function sortByYear cout << "Sorted: " << endl; for(int x=0; x<8; x++) { cout << Championship[x].Year << ":" << Championship[x].Winner << ":" << Championship[x].WinnerScore; cout << ":" << Championship[x].RunnerUp << ":" << Championship[x].RunnerUpScore << endl; } cout << "zzz2" << endl; //closing first input stream DataFile.close(); //opening new input stream ifstream InfoFile; InfoFile.open("NCAAinfo.txt"); //header LogFile << "Programmer: Kyle Stratton" << endl << "CS 1044 Project Spring 2011 Project 5" << endl; LogFile << "Women's NCAA Champions" << endl << "------------------------------------------------------------" << endl; while (InfoFile){ //while loop to analyze the info file commands i++; //adding to the index parameter getline(InfoFile, Command,'\t'); //getting the command if (Command=="year") { //if command is year, do this InfoFile >> YearValue >> TeamValue; //getting rest of command values LogFile << "00" << i << "\t" << "year" << "\t" <> YearValue >> MarginValue; LogFile << "00" << i << "\t" << "margin" <<"\t"<< YearValue<< "\t"<< MarginValue<< endl; //outputting everything Output=Margin(Championship,YearValue,MarginValue,ChampAmounts); //call the Margin function LogFile << Output << endl << "------------------------------------------------------------" << endl; //outputting useless stuff InfoFile.ignore(INT_MAX, '\n'); } } //closing those streams InfoFile.close(); LogFile.close(); delete [] Championship; return 0; } //ending main