// Project II for CS 1704 Spring 2004 // // Programmer: Kyle Loder // OS: Windows XP Professional // System: Pentium IV 2.6 GHz, 512 MB Memory // Compiler: Visual Studio .NET 2003 // Last modified: February 23rd, 2004 // // Purpose // Implementation of the mediaLibrary class // #include "mediaLibrary.h" //////////////////////////////////////////////////////////////// mediaLibrary constructor // declares a blank instance of the mediaLibrary class // // Parameters: none // // Pre: used as a constructor // // Post: instance of the mediaLibrary type declared // // Returns: none // // Called by: main // Calls: none // mediaLibrary::mediaLibrary () { numStudents = 0; numItems = 0; } //////////////////////////////////////////////////////////////// readStudents // reads in a list of students from a file to the mediaLibrary // // Parameters: // ifstream &Students: stream to read the student information from // // Pre: "Students" is open for reading // // Post: students put into the "myStudents" array // // Returns: none // // Called by: main // Calls: student "set" functions // void mediaLibrary::readStudents (ifstream &Students) { string input, temp, city = "", state = "", zip = "", line3 = ""; bool EMAIL = false; Student newStudent, blankStudent; while (getline (Students, input)) { //runs while there is still information in the file if (input == "@Name:") { getline (Students, temp); newStudent.setName (temp); } else if (input == "@E-mail:") { getline (Students, temp); newStudent.setEmail (temp); EMAIL = true; } else if (input == "@Address Line 1:") { getline (Students, temp); newStudent.setAddress (temp); } else if (input == "@Address Line 2:") { getline (Students, temp); newStudent.setApartment (temp); } else if (input == "@City:") { getline (Students, city); } else if (input == "@State:") { getline (Students, state); } else if (input == "@Zipcode:") { getline (Students, zip); } else if (input == "@Phone Number:") { getline (Students, temp); newStudent.setNumber (temp); } else if (input == "@Other:") { getline (Students, temp); newStudent.setOther (temp); } else if (input == "@@") { if (EMAIL) { if (city != "" && state != "") line3 = line3 + city + ", " + state + " "; else if (city != "") line3 = line3 + city + " "; else if (state != "") line3 = line3 + state + " "; if (zip != "") line3 = line3 + zip; newStudent.setLine3 (line3); myStudents [numStudents] = newStudent; numStudents++; newStudent = blankStudent; getline (Students, temp); city = ""; state = ""; zip = ""; line3 = ""; } else { newStudent = blankStudent; getline (Students, temp); city = ""; state = ""; zip = ""; line3 = ""; } } } } //////////////////////////////////////////////////////////////// readItems // reads in a list of items from a file to the mediaLibrary // // Parameters: // ifstream &Item: stream to read the item information from // // Pre: "Items" is open for reading // // Post: Items put into the "myItems" array // // Returns: none // // Called by: main // Calls: item "set" functions // void mediaLibrary::readItems (ifstream &Items) { //runs while there is still information in the file string input, temp; Item newItem, blankItem; while (getline (Items, input)) { if (input == "@Item:") { getline (Items, temp); newItem.setTitle (temp); } else if (input == "@Media Type:") { getline (Items, temp); newItem.setType (temp); } else if (input == "@by:") { getline (Items, temp); newItem.setArtist (temp); } else if (input == "@Owner:") { getline (Items, temp); newItem.setOwner (temp); } else if (input == "@Price:") { getline (Items, temp); newItem.setPrice (temp); } else if (input == "@Availability:") { getline (Items, temp); newItem.setAvailability (temp); } else if (input == "@@") { myItems [numItems] = newItem; numItems++; newItem = blankItem; getline (Items, temp); } } } //////////////////////////////////////////////////////////////// printStudents // prints out all the students in "myStudents" // // Parameters: // ofstream &Log: the stream to print the students to // // Pre: "Log" is open for writing // // Post: students formatted to the stream // // Returns: none // // Called by: mediaLibrary::readComands // Calls: Student::printStudent // void mediaLibrary::printStudents (ofstream &Log) { Student blankStudent; for (short i = 0; i < 100; i++) { //runs down the list of students if (myStudents [i] != blankStudent) { myStudents [i].printStudent (Log); Log< 99) { Log< 99) { Log<<"Failure"< 99) Log<<"Failure"< 99) { Log<<"Failure"<>input && !exit) { if (input == "print") { Commands>>input; if (input == "students") {//refers to the "Print students" command Log<<"print students"<>input; if (input == "item") { //refers to the "add item" command Log<<"add item"<>input; Log<<"delete "<