// Project 2 for CS 1704 Spring 2004 // // Programmer: John Puckett // OS: Windows XP Professional // System: Pentium 4 2.4Ghz, 1 GB Memory // Compiler: Visual C++ 7.1, Service Pack 4 // Last modified: February 24, 2004 // // Purpose // This program reads a list of student names and items from two input files // creates 2 arrays from the data, then uses another input file to run different // algorithms on the arrays // // The program then writes the given commands and the results to // an output file #include #include #include #include #include #include"manager.h" using namespace std; //Constructor manager::manager(ifstream &student, ifstream &item) { int ct = 0; int t = 0; char input[50]; string temp; while(!student.eof()) //reads in all data frin students.data { student.getline(input, 40, '\n'); if(input[1] == '@') { ct++; student.getline(input, 40, '\n'); } else { switch(input[1]) //selects proper function to excecute { case 'N': student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateName(temp); break; case 'E': student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateEmail(temp); break; case 'P': student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updatePhone(temp); break; case 'A': if(input[14] == '1') { student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateAdd1(temp); } else { student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateAdd2(temp); } break; case 'C': student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateCity(temp); break; case 'S': student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateState(temp); break; case 'Z': student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateZip(temp); break; case 'O': student.getline(input, 40, '\n'); temp = input; arrayStud[ct].updateInfo(temp); break; } } } while(item.eof()) { item.getline(input, 40, '\n'); if(input[1] == '@') t++; else { switch(input[1]) //selects proper function to excecute { case 'I': item.getline(input, 40, '\n'); temp = input; arrayItem[t].updateItem(temp); break; case 'M': item.getline(input, 40, '\n'); temp = input; arrayItem[t].updateType(temp); break; case 'b': item.getline(input, 40, '\n'); temp = input; arrayItem[t].updateAuthor(temp); break; case 'O': item.getline(input, 40, '\n'); temp = input; arrayItem[t].updateOwner(temp); break; case 'P': item.getline(input, 40, '\n'); temp = input; arrayItem[t].updatePrice(temp); break; case 'A': item.getline(input, 40, '\n'); temp = input; arrayItem[t].updateAvail(temp); break; } } } student.close(); item.close(); } manager::~manager() {} //Modifier methods //////////////////////////////////////////////////////////////// addStudent //updates student array // // Parameters: // string addname, string addphone, string addemail, string addaddress1, // string addaddress2, string addcity, string addstate, string addzipCode, string addinfo, ofstream &oFile // // Pre: // // Post: // // Returns: None // // Called by: main // Calls: none // void manager::addStudent(string addname, string addphone, string addemail, string addaddress1, string addaddress2, string addcity, string addstate, string addzipCode, string addinfo, ofstream &oFile) { oFile << "add student" << '\n'; int ct = 0; while(arrayStud[ct].getEmail() != "none" && ct < 100) { ct++; } if(ct != 99) { arrayStud[ct].updateName(addname); arrayStud[ct].updatePhone(addphone); arrayStud[ct].updateEmail(addemail); arrayStud[ct].updateAdd1(addaddress1); arrayStud[ct].updateAdd2(addaddress2); arrayStud[ct].updateCity(addcity); arrayStud[ct].updateState(addstate); arrayStud[ct].updateZip(addzipCode); arrayStud[ct].updateInfo(addinfo); oFile << "Success" << '\n'; } else oFile << "Failure" << '\n'; } //////////////////////////////////////////////////////////////// addItem // adds an Item tot the array // // Parameters: // string additem, string addtype, string addauthor, string addowner, // string addprice, string addavail, ofstream &oFile // // Pre: array[Stud[] and arrayItem[] exist // // Post: item is added to list if given valid email of student // // Returns: none // // Called by: main.cpp // Calls: multimedia.h accessor functions // void manager::addItem(string additem, string addtype, string addauthor, string addowner, string addprice, string addavail, ofstream &oFile) { oFile << "add item" << '\n'; int t = 0; bool found = false; for(int ctwin = 0; ctwin < 100; ctwin ++) { if(arrayStud[ctwin].getEmail() == addowner) found = true; } if(found) { while(arrayItem[t].getOwner() != "none" && t < 100) { t++; } if(t != 99) { arrayItem[t].updateItem(additem); arrayItem[t].updateType(addtype); arrayItem[t].updateAuthor(addauthor); arrayItem[t].updateOwner(addowner); arrayItem[t].updatePrice(addprice); arrayItem[t].updateAvail(addavail); oFile << "Success" << '\n'; } } else oFile << "Failure" << '\n'; } //////////////////////////////////////////////////////////////// deleteEmail // deletes specified email, prints success or failure too // // Parameters: // string delemail, ofstream &oFile // // Pre: arrayStud[] and arrayItem[] exist // // Post: if the email was vaild, it's delete along with all its items // // Returns: none // // Called by: main.cpp // Calls: students.h and multimedia.h accessor functions // void manager::deleteEmail(string delemail, ofstream &oFile) { oFile << "delete " << delemail << '\n'; int ctwin = 0; int found = 0; for(ctwin = 0; ctwin < 100; ctwin ++) { if(arrayStud[ctwin].getEmail() == delemail) found = ctwin; } assert(found < 100); if(arrayStud[found].getEmail() == delemail) { arrayStud[found].updateName(" "); arrayStud[found].updatePhone("7035698461"); arrayStud[found].updateEmail("none"); arrayStud[found].updateAdd1(" "); arrayStud[found].updateAdd2(" "); arrayStud[found].updateCity(" "); arrayStud[found].updateState(" "); arrayStud[found].updateZip("66666"); arrayStud[found].updateInfo("W00T"); for(ctwin = 0; ctwin < 100; ctwin++) { if(arrayItem[ctwin].getOwner() == delemail) { arrayItem[ctwin].updateOwner("none"); } } oFile << "Success" << '\n'; } else oFile << "Failure" << '\n'; } //Accessor methods //////////////////////////////////////////////////////////////// printStudents // outputs all students in the array // // Parameters: // ofstream &oFile // // Pre: arrayStud[] exists // // Post: prints arrayStud[] to oFile // // Returns: none // // Called by: main.cpp // Calls: students.h functions // void manager::printStudents(ofstream &oFile) const { oFile << "print students" << '\n'; for(int twin = 0; twin < 100; twin++) { if(arrayStud[twin].getEmail() != "none") { if(arrayStud[twin].getName() != " ") oFile << "Name:" << '\n' << '\t' << arrayStud[twin].getName() << '\n'; if(arrayStud[twin].getPhone() != "7035698461") oFile << "Phone Number:" << '\n' << '\t' << arrayStud[twin].getPhone() << '\n'; oFile << "Email:" << '\n' << '\t' << arrayStud[twin].getEmail() << '\n'; if(arrayStud[twin].hasAdd()) { oFile << "Address:" << '\n' << '\t'; if(arrayStud[twin].getAdd1() != " ") oFile << arrayStud[twin].getAdd1() << '\n' << '\t'; if(arrayStud[twin].getAdd2() != " ") oFile << arrayStud[twin].getAdd2() << '\n' << '\t'; if(arrayStud[twin].getCity() != " ") oFile << arrayStud[twin].getCity() << ", "; if(arrayStud[twin].getState() != " ") oFile << arrayStud[twin].getState() << " "; if(arrayStud[twin].getZip() != "66666") oFile << arrayStud[twin].getZip(); oFile << '\n'; } if(arrayStud[twin].getInfo() != "W00T") oFile << "Other:" << '\n' << '\t' << arrayStud[twin].getInfo() << '\n'; else oFile << '\n'; } } oFile << '\n'; } //////////////////////////////////////////////////////////////// printItems // outputs all items in the array // // Parameters: // ofstream &oFile // // Pre: arrayItem[] exists // // Post: prints all items in array order // // Returns: Describe what value the function returns, if any. // // Called by: main.cpp // Calls: multimedia.h functions // void manager::printItems(ofstream &oFile) const { oFile << "print items" << '\n'; for(int draw = 0; draw < 100; draw++) { if(arrayItem[draw].getOwner() != "none") { if(arrayItem[draw].getItem() != " ") oFile << "Item:" << '\n' << '\t' << arrayItem[draw].getItem() << '\n'; if(arrayItem[draw].getType() != " ") oFile << "Media Type:" << '\n' << '\t' << arrayItem[draw].getType() <<'\n'; if(arrayItem[draw].getAuthor() != " ") oFile << "by:" << '\n' << '\t' << arrayItem[draw].getAuthor() << '\n'; oFile << "Owner:" << '\n' << '\t' << arrayItem[draw].getOwner() << '\n'; if(arrayItem[draw].getPrice() != "0.0") oFile << "Price:" << '\n' << '\t' << arrayItem[draw].getPrice() << '\n'; if(arrayItem[draw].getAvail() != " ") oFile << "Availability:" << '\n' << '\t' << arrayItem[draw].getAvail() << '\n'; } } oFile << '\n'; } //////////////////////////////////////////////////////////////// printEmail // prints specified email if email exists // // Parameters: // string printemail, ofstream &oFile // // Pre: printemail and oFile exist // // Post: ouputs to the oFile // // Returns: None // // Called by: main.cccp // Calls: students.h and multimedia.h functions // void manager::printEmail(string printemail, ofstream &oFile) const { int success = 0; oFile << "print " << printemail << '\n'; for(int twin = 0; twin < 100; twin++) { if(arrayStud[twin].getEmail() == printemail) { success = 1; if(arrayStud[twin].getName() != " ") oFile << "Name:" << '\n' << '\t' << arrayStud[twin].getName() << '\n'; if(arrayStud[twin].getPhone() != "7035698461") oFile << "Phone Number:" << '\n' << '\t' << arrayStud[twin].getPhone() << '\n'; oFile << "Email:" << '\n' << '\t' << arrayStud[twin].getEmail() << '\n'; if(arrayStud[twin].hasAdd()) { oFile << "Address:" << '\n' << '\t'; if(arrayStud[twin].getAdd1() != " ") oFile << arrayStud[twin].getAdd1() << '\n' << '\t'; if(arrayStud[twin].getAdd2() != " ") oFile << arrayStud[twin].getAdd2() << '\n' << '\t'; if(arrayStud[twin].getCity() != " ") oFile << arrayStud[twin].getCity() << ", "; if(arrayStud[twin].getState() != " ") oFile << arrayStud[twin].getState() << " "; if(arrayStud[twin].getZip() != "66666") oFile << arrayStud[twin].getZip(); oFile << '\n'; } if(arrayStud[twin].getInfo() != "W00T") oFile << "Other:" << '\n' << '\t' << arrayStud[twin].getInfo() << '\n'; else oFile << '\n'; } assert(twin < 100); } for(int draw = 0; draw < 100; draw++) { if(arrayItem[draw].getOwner() == printemail) { if(arrayItem[draw].getItem() != " ") oFile << "Item:" << '\n' << '\t' << arrayItem[draw].getItem() << '\n'; if(arrayItem[draw].getType() != " ") oFile << "Media Type:" << '\n' << '\t' << arrayItem[draw].getType() << '\n'; if(arrayItem[draw].getAuthor() != " ") oFile << "by:" << '\n' << '\t' << arrayItem[draw].getAuthor() << '\n'; if(arrayItem[draw].getPrice() != "0.0") oFile << "Price:" << '\n' << '\t' << arrayItem[draw].getPrice() << '\n'; if(arrayItem[draw].getAvail() != " ") oFile << "Availability:" << '\n' << '\t' << arrayItem[draw].getAvail() << '\n'; oFile << '\n'; } } if(success == 0) oFile << printemail << " not found." << '\n'; }