// Copyright 2009 Bishop Brady Robotics Team 1517 - Made by Lincoln // If you choose to redistribute this program in any way, please // give us some credit! #include #include #include #include using namespace std; //Declared variables string fileName; ofstream scoutFile; ifstream testFile; int iTeamInfo[18][100]; string sTeamInfo[300]; string rowHeaders[] = {" Team number: ", " 1st Partner team's number: ", " 2nd Partner team's number: ", " 1st Opponent team's number: ", " 2nd Opponent team's number: ", " 3rd Opponent team's number: ", " Pickup mechanism description: ", " Autonomous description: ", " Autonomous points scored: ", " Human points scored: ", " # of moon balls scored: ", " # of empty balls scored: ", " Can they use the airlock?: ", " Operator points scored: ", " How many penalties?: ", " Total team points: ", " Total opponent team points: ", "Your personal performance rating (1 to 10): "}; string rowHeaderTypes[] = {"int", "int", "int", "int", "int", "int", "str", "str", "int", "int", "int", "int", "str", "int", "int", "int", "int", "int"}; int posx = 0; int posy = 0; int spos = 1; void wayStation(int ans); void pP() {//pP = "Perfect Pause" system("PAUSE"); system("cls"); } void txtWrite() {//Write to the document for (int i=0; i!=18; i++) { scoutFile << rowHeaders[i]; for (int o=0; o!=99; o++) { int numSpace = 0; for (int c=0; c!=18; c++) {//find out what the longest entry is if (rowHeaderTypes[c] == "str") { if (numSpace < sTeamInfo[iTeamInfo[c][o]].length()) { numSpace = sTeamInfo[iTeamInfo[c][o]].length(); } } else { stringstream converter; converter << iTeamInfo[c][o]; if (numSpace < converter.str().length()) { numSpace = converter.str().length(); } } } if (iTeamInfo[i][o]) { if (rowHeaderTypes[i] == "int") {//if it's an int, we need to convert it to a string to get the length scoutFile << iTeamInfo[i][o]; stringstream converter; converter << iTeamInfo[i][o]; for (int c=0; c < (numSpace - converter.str().length() + 1); c++) { scoutFile << " "; } } else { scoutFile << sTeamInfo[iTeamInfo[i][o]]; for (int c=0; c < (numSpace - sTeamInfo[iTeamInfo[i][o]].length() + 1); c++) { scoutFile << " "; } } } } scoutFile << "\n"; } } void cellEdit() {//Get the information from the user if (posy > 17) posy = 0; for (int i=0; i!=18; i++) { cout << rowHeaders[i]; if (rowHeaderTypes[i] == "int") { cin >> iTeamInfo[posy][posx]; } else { getline(cin, sTeamInfo[spos]); iTeamInfo[posy][posx] = spos; spos++; } cin.clear(); cin.ignore(999, '\n'); posy++; } } void openSheet() { //scoutFile.close(); //NEVER DO THIS BEFORE OPENEING **RAWR**!!!!!!!!!!!!! cout << " Please enter the scouting sheet file's name. If it\n"; cout << "doesn't exist yet, it will be created: "; cin >> fileName; fileName = fileName + ".txt"; //Check if we actually opened the file testFile.open(fileName.c_str(), ifstream::in); testFile.close(); if(testFile.fail()) {//The file doesn't exist testFile.clear(ios::failbit); scoutFile.open (fileName.c_str()); cout << "\nCreated file \""+fileName+"\" successfully!\n"; pP(); } else {//The file exists cout << "\nAre you sure you want to edit \""+fileName+"\"? (yes/no)\n(WARNING: Existing data will be overwritten): "; string ans; cin >> ans; if (ans == "yes") { scoutFile.open (fileName.c_str()); cout << "\n\""+fileName+"\" is now ready for editing..\n"; } else { cout << "Did not open \""+fileName+"\""; } pP(); } } void editSheet() { //Check if we actually have an open file if (! scoutFile.is_open()) { //We didn't open it :( cout << "ERR: Please open/create a file first\n"; pP(); } else { //We opened it! :D cout << "Editing file \""+fileName+"\"\n"; pP(); cellEdit(); posx++; cout << "Continue to the next team?(yes/no): "; string ans; cin >> ans; if (ans == "yes") { system("cls"); wayStation(2); } else { txtWrite(); } } } void wayStation(int ans) { switch (ans) {//goes through each option case 1: openSheet(); break; case 2: editSheet(); break; case 3: break; default: cout << "Please enter a correct menu number\n"; break; } } int main() { //Opening Notice cout << "**======================= NOTE =======================**\n"; cout << "|| The created .txt file will be saved in the ||\n"; cout << "|| same directory as this program.. ||\n"; cout << "|| ||\n"; cout << "|| Also, be sure to use underscores ( _'s ) ||\n"; cout << "|| instead of spaces while entering the filename ||\n"; cout << "**====================================================**\n\n"; //Menu int ans; while (ans!=3) { cout << "**======================= MENU =======================**\n"; cout << "|| 1: Open ||\n"; cout << "|| 2: Edit ||\n"; cout << "|| 3: Exit ||\n"; cout << "**====================================================**\n"; cout << "Your choice: "; cin >> ans; cout << endl; system("cls"); wayStation(ans);//Send answer to the next station system("cls"); } scoutFile.close(); }