// Programmer: Postell Carter // Last Modified: June 6, 2003 // Compiler: Visual C++.NET // This programs creates a multimedia organizer that hold a list of students and their // multimedia items. The programs utilizes three classes, one for the student object, // one for the item object and one for the organizer object. The organizer will be able // to handle a few commands that manipulate data in the organizer, such as print student, // add student and delete student. The program must also incorporate at least 3 testing // switches and 3 assert statements. // // 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 of unmodified. // // - If any C++ language code or documentation used in my program // was obtained from another source, such as a text book 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. // // Postell Carter // #include // For input from and output to the screen #include // For testing switches #include // For input and output file streams #include // For STRING data #include // For string stream #include // For assert command using namespace std; const int MAXSIZE = 100; // Holds Student Information class Student { friend class Organizer; public: Student(); ~Student(); private: string stName; // For student name string stNumber; // For student phone number string stEmail; // For student email string stAddrLine1; // Next 5 variables for student address string stAddrLine2; string stCity; string stState; string stZipcode; string stOther; // For extra data about student bool isEmpty; // To show whether the cell is empty or not }; // Default Constructor - Initializes each Student object Student::Student() { stName = "Empty"; stNumber = "Empty"; stEmail = "Empty"; stAddrLine1 = "Empty"; stAddrLine2 = "Empty"; stCity = "Empty"; stState = "Empty"; stZipcode = "Empty"; stOther = "Empty"; isEmpty = true; } // class Destructor Student::~Student() {} // Holds Item information class Item { friend class Organizer; public: Item(); ~Item(); private: string itemName; // For name of item string itemType; // For type of item string itemArtist; // For name of Artist string itemEmail; // For owner's email string itemPrice; // For price of item string itemAvail; // For item's availability status bool isEmpty; // To show whether cell is empty or filled }; // Default constuctor - Initializes Item object Item::Item() { itemName = "Empty"; itemType = "Empty"; itemArtist = "Empty"; itemEmail = "Empty"; itemPrice = "Empty"; itemAvail = "Empty"; isEmpty = true; } // class Destructor Item::~Item() {} // Holds arrays of both Student and Items objects and the functions that access or modify them class Organizer { public: Organizer(); ~Organizer(); void printStudents(ofstream&) const; void printItems(ofstream&) const; void printStudItems(ofstream&, string) const; void addStudent(ifstream&, ofstream&); void addItem(ifstream&, ofstream&); void deleteStudItems(ofstream&, string); private: Student studList[MAXSIZE]; Item itemList[MAXSIZE]; }; // class Constructor - Reads student information from students.data and item information // from items.data and inserts the information into the appropriate array Organizer::Organizer() { ifstream Infile("students.data"); string fieldToAdd; // To determine which field the data is for string name; // Next 9 variables are temporary variables to string number; // hold student data until it is input in a student string studEmail; // object string addr1; string addr2; string city; string state; string zip; string other; bool stillData = true; // Variable ends loop when the end of input file is found getline(Infile, fieldToAdd); while(stillData == true) { while (fieldToAdd != "@@") { if (fieldToAdd == "@Name:") getline(Infile, name); else if (fieldToAdd == "@Phone Number:") getline(Infile, number); else if (fieldToAdd == "@E-mail:") getline(Infile, studEmail); else if (fieldToAdd == "@Address Line 1:") getline(Infile, addr1); else if (fieldToAdd == "@Address Line 2:") getline(Infile, addr2); else if (fieldToAdd == "@City:") getline(Infile, city); else if (fieldToAdd == "@State:") getline(Infile, state); else if (fieldToAdd == "@Zipcode:") getline(Infile, zip); else if (fieldToAdd == "@Other:") getline(Infile, other); getline(Infile, fieldToAdd); } int i = 0; // counter variable bool studAdded = false; // Holds whether the information was input into the array if (studEmail != "") { while( i=0) && (i=0) && (i=0) && (i=0) && (i=0) && (i1 && atoi(argv[1])==1) { cout << "Prior to getting command." << endl; cin >> screenPause; } getCommand(); if (argc>1 && atoi(argv[1])==2) { cout << "After commands are finished." << endl; cin >> screenPause; } if (argc>1 && atoi(argv[1])==3) { cin >> screenPause; } return 0; } ////////////////////////////////////////////////////////////////////////////////////////////////// // Reads command from input file and calls the appropriate function to handle the request // // Parameters: // argc, A - both variables are for testing switches // // Returns: // nothing // // Pre: nothing // // Post: All commands have been read and all functions completed // // Called by: main() // void getCommand() { Organizer multOrganizer; // Organizer that holds Student and Item arrays string commandLine; // To hold command from input file string command1; // Variables hold to hold command after it is seperated into 2 parts string command2; ifstream Infile("commands.data"); ofstream Outfile("output.data"); getline(Infile, commandLine); istringstream dbCommand( commandLine ); dbCommand >> command1 >> command2; while (command1 != "quit") { if (command1 == "print") { if (command2 == "students") { multOrganizer.printStudents(Outfile); Infile.ignore(INT_MAX, '\n'); } else if (command2 == "items") { multOrganizer.printItems(Outfile); Infile.ignore(INT_MAX, '\n'); } else { multOrganizer.printStudItems(Outfile, command2); Infile.ignore(INT_MAX, '\n'); } } else if (command1 == "add") { if (command2 == "student"){ multOrganizer.addStudent(Infile, Outfile); Infile.ignore(INT_MAX, '\n'); } else if (command2 == "item") { multOrganizer.addItem(Infile, Outfile); Infile.ignore(INT_MAX, '\n'); } } else { multOrganizer.deleteStudItems(Outfile, command2); Infile.ignore(INT_MAX, '\n'); } getline(Infile, commandLine); istringstream dbCommand( commandLine ); dbCommand >> command1 >> command2; } Outfile.close(); }