// Project 2 for CS 1704 Spring 2004 // // Programmer: Robert Houtman // OS: Windows XP Professional // Last modified: 24 FEB 2004 // // Purpose // This program reads a list of students and multimedia collections that // each student has. // // The program then gets commands from an input file to manage the // database. #include #include #include #include "Info.h" //includes Info class definition from header file using namespace std; int main() { ofstream oFile("output.data"); //Opens the output file ifstream iFile("commands.data"); //Opens the student input data file assert(iFile); Info Database; Database.FirstAddS(oFile); string command; //string to hold command int commandcase; //variable to hold command case so it can be used for the switch statement string email; //variable to hold email address getline(iFile, command, ' '); //puts command into the command variable while (iFile) { //This if else if statement gives the ability to use a switch statement to call //each specific function according to the command given if(command == "print" || command == "print ") { commandcase = 1; } else if(command == "add"|| command == "add ") { commandcase = 2; } else if(command == "delete" || command == "delete ") { commandcase = 3; } else if(command == "quit" || command == "quit ") { commandcase = 4; } else { commandcase = 5; } switch (commandcase) { case 1: getline(iFile, command, '\n'); oFile << "print " << command << endl;//outputs command Database.Print(oFile, command);//calls print function break; case 2: getline(iFile, command, '\n'); //gets next word in command line oFile << "add " << command << endl; //outputs command //This if else if statement determines which method should be called if(command == "student" || command == "student ") { Database.AddStud(iFile, oFile); //calls StudInfo add function } else if(command == "item" || command == "item ") { Database.AddItem(iFile, oFile); //calls ItemInfo add function } else { oFile << "Cannot add " << command << endl; //default output } break; case 3: iFile >> command; oFile << "delete " << command << endl;//outputs command email = command;//transfers command variable to email variable so //it can be passed into the function Database.Delete(email, oFile); //calls remove functions break; case 4: oFile << "quit\n"; //outputs command iFile.close(); oFile.close(); //closes file streams return 0; //ends program case 5: oFile << "Invalid command\n";//default output break; } iFile >> command; iFile.ignore(1, ' '); } } //On my honor: //- I have not discussed the C++ language code in my program with anyone other than my instructor //or the teaching assistants assigned to this course. //- I have not used C++ language code obtained from another student, or any other //unauthorized source, either modified or unmodified. //- If any C++ language code or documentation used in my program was obtained //from another source, such as a textbook or course notes, that has been clearly noted with a proper citation in the comments of my program. //- I have not designed this program in such a way as to defeat or interfere //with the normal operation of the Curator System. //Robert Houtman