// CS1704 Spring 2004 // Project 2 - Multimedia Organizer // // Programmer: J Ulfers // OS: Windows XP Pro // System: Toshiba Satellite 1415-S173 // Compiler: Visual C++ .NET 2003 // Last modified: February 20, 2004 // // PURPOSE // This is a console, command line based Multimedia Organizer. It reads in, organizes and // reports data on various media owned by different persons. // // 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. // - Josiah Ulfers // INCLUDES: #include "commandClass.h" // CONSTANTS: const char* STUDENT_FILE_NAME = "students.data"; // filename to read initial student list const char* MEDIA_FILE_NAME = "items.data"; // filename to read initial item list const char* CMD_FILE_NAME = "commands.data"; // filename to read commands const char* OUT_FILE_NAME = "output.data"; // filename to output result of commands int main() { ifstream commandFile( CMD_FILE_NAME ); // opens the filestream to read in commands ofstream logFile( OUT_FILE_NAME ); // opens the filestream to output results bool loop = true; // flags a quit command string command, // stores first half of command (the command) commandP2; // stores second half of command (the parameter) commandClass organizer( STUDENT_FILE_NAME, MEDIA_FILE_NAME ); // stores the database commandFile >> command; // initial command read while( commandFile && loop ) // loops while quit command is not found and commandFile still holds data { commandFile >> commandP2; // read second part of command // echo command to logFile: logFile << command << ' '; if( command != "quit" ) logFile << commandP2 << '\n'; // execute command: if( command == "print" ) { if( commandP2 == "students" ) // print list of students to logFile logFile << organizer.printStudents(); else if( commandP2 == "items" ) // print list of items to logFil logFile << organizer.printItems(); else // print list of items owned by a given email address logFile << organizer.printSpecific( commandP2 ); } else if( command == "add" ) { if( commandP2 == "student" ) // add a student { studentClass tempStudent; commandFile >> tempStudent; logFile << organizer.add( tempStudent ); } else if( commandP2 == "item" ) // add an item { mediaClass tempMedia; commandFile >> tempMedia; logFile << organizer.add( tempMedia ); } } else if( command == "delete" ) // delete a student and all associated items { logFile << organizer.remove( commandP2 ); } else if( command == "quit" ) // quit { loop = false; } else assert( false ); // stop execution on unrecognized command commandFile >> command; // read next command } // close files: commandFile.close(); logFile.close(); return 666; } string copyCommand( istream& dataStream ) { bool loop = true; // flags when end marker is reached string line; // stores a line temporarily ostringstream tempOStream; // stores data read from dataStream getline( dataStream, line ); // line priming read while( dataStream && line != "@@" ) // loop until end marker or no more data { tempOStream << line << '\n'; getline( dataStream, line ); } return tempOStream.str(); // return copied string } bool operator <<( ofstream& outFile, bool flag ) { const string TRUE = SUCCESS; // string to print to file on true const string FALSE = FAILURE; // string to print to file on false if( flag ) outFile << TRUE; else outFile << FALSE; return outFile; // should always be true }