// Project 2 for CS 1704 Spring 2004 // // Programmer: Phil Wallace // OS: Windows XP Professional // System: Pentium 4 2200, 768 MB Memory // Compiler: Visual C++ .NET // Last modified: February 22, 2004 // // Purpose: // The purpose of this program is to implement a crude multimedia organizer // using the student, item and storage classes /* 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. Phil Wallace*/ #include #include "storage.h" using namespace std; void read_commands(storage &organizer); //read in the commands from a file int main() { storage organizer; read_commands(organizer); //run program // organizer.print_items(); return 0; } //////////////////////////////////////////////////////////////// read_commands // implements commands from file // // Parameters: // organizer - data structure containing organizer information // // Pre: none // Post: implements commands // Returns: nothing // // Called by: main // Calls: print_students, print_items, print_email, add_item, add_student, delete_email // void read_commands(storage &organizer) { ifstream cmdFile("commands.data"); //open commands file assert(!cmdFile.fail()); //kicks out of the program if the file fails string cmd; //grabs command from file istringstream command; //used to hold the line of the command while(getline(cmdFile,cmd)) //gets successive lines from file { command.clear(); command.str(cmd); //copies string to string stream command>>cmd; //get first word of command if(cmd.compare("print") == 0) //print commands { command>>cmd; //get next part of command if(cmd.compare("students") == 0) //print students { organizer.print_students(); } else if(cmd.compare("items") == 0) //print items { organizer.print_items(); } else //assume print email is command { command>>cmd; //get email organizer.print_email(cmd); //print email } } else if(cmd.compare("add") == 0) //add commands { command>>cmd; //get next part of command if(cmd.compare("student") == 0) //check for add student { organizer.add_student(cmd,cmdFile); //perform add } else if(cmd.compare("item") == 0) { organizer.add_item(cmd,cmdFile); //add item info } } else if(cmd.compare("delete") == 0) { command>>cmd; //peel off email address organizer.delete_email(cmd); //delete email } else if(cmd.compare("quit") == 0) //quit program { ofstream File("output.data",ios::app); File<<"quit"; return; } getline(cmdFile,cmd); //eliminate white space } }