// Project 1 for CS 1704 SPRING 04 // // Programmer: Andrew Scharf // OS: Windows XP Professional // Last modified: Feb 23, 2004 // // Purpose // // This program stores the information of students and also holds // the media that they own. This program also adds and deletes students and media // and prints the output // // *** On my honor, i have given nor recieved any help on this project. // Andrew Nicholas Scharf *** // #include #include #include #include #include "Controller.h" #include "Students.h" using namespace std; void readCommands(Controller&); //////////////////////////////////////////////////////////////// // // // Parameters: // // Pre: None. // // Post: program has been completed, all data is stored // // Returns: none // // Called by: none // Calls: // int main() { Controller Cobject; // Controller object which manages the two arrays: students and items Cobject.readSdata(); Cobject.readMdata(); readCommands(Cobject); return 0; } //////////////////////////////////////////////////////////////// // // // Parameters: // // Pre: None. // // Post: quits program and closes output file // // Returns: none // // Called by: main() // Calls: // void readCommands(Controller& Cobject) { ifstream infile; // infile variable infile.open("commands.data"); string data; // string variable read in to the functions string eolch; // dummy variable that gets the whitespace character while(infile) { if(!infile.eof()) { infile >> data; if(data == "delete") { getline(infile, eolch, ' '); getline(infile, data, '\n'); Cobject.deleteAll(data); } else if(data == "add") { infile >>data; getline(infile, eolch, '\n'); if(data == "student") { Students addStud; getline(infile, data, '\n'); while(data != "@@") { if(data == "@Name:") { getline(infile, data, '\n'); addStud.setSname(data); } if(data == "@E-mail:") { getline(infile, data, '\n'); addStud.setEmail(data); } else if(data == "@Address Line 2:") { getline(infile, data, '\n'); addStud.setApt(data); } else if(data == "@Address Line 1:") { getline(infile, data, '\n'); addStud.setStreetAdd(data); } else if(data == "@Phone Number:") { getline(infile, data, '\n'); addStud.setPhone(data); } else if(data == "@City:") { getline(infile, data, '\n'); addStud.setCity(data); } else if(data == "@State:") { getline(infile, data, '\n'); addStud.setState(data); } else if(data == "@Zipcode:") { getline(infile, data, '\n'); addStud.setZip(data); } else if(data == "@Other:") { getline(infile, data, '\n'); addStud.setOther(data); } else getline(infile, data, '\n'); } getline(infile, data, '\n'); Cobject.addStudent(addStud); } else { MultItem addItem; getline(infile, data, '\n'); while(data != "@@") { if(data == "@Item:") { getline(infile, data, '\n'); addItem.setMname(data); } else if(data == "@Media Type:") { getline(infile, data, '\n'); addItem.setType(data); } else if(data == "@by:") { getline(infile, data, '\n'); addItem.setAuthor(data); } else if(data == "@Owner:") { getline(infile, data, '\n'); addItem.setOwner(data); } else if(data == "@Price:") { getline(infile, data, '\n'); addItem.setPrice(data); } else if(data == "@Availability:") { getline(infile, data, '\n'); addItem.setAvailability(data); } getline(infile, data, '\n'); } getline(infile, data, '\n'); Cobject.addMItem(addItem); } } else if(data == "print") { infile >> data; if(data == "students") { Cobject.printStudents(); getline(infile, data, '\n'); } else if(data == "items") { Cobject.printItems(); getline(infile, data, '\n'); } else { Cobject.printInfo(data); getline(infile, data, '\n'); } } else Cobject.quit(); } } }