// Tony Pitale VS.NET 2003 Windows XP Pro 2/19/04 9044-14007 /* array class implements all commands passed from apitale (main), inputs the original items and student data. Provides functionality for: Delete: Removes an individual student record matching email as well as all items with the same owner, caled by main. Add: Add student - adds a new individual student record. Add item - adds new individual item if owner exists. Input: students - inputs original student input file into array items - inputs original item input file into array if owner exists Print students - prints all students that aren't "empty" in the array. items - prints all items that aren't "empty" in the array. individual - prints specified student and all owned items. searchEmail - search all array locations in student array for specified email searchEmpty - search for empty student array location searchEmptyItem - search for empty item array location */ #include #include #include #include "array.h" using namespace std; array::array(ifstream& inFile1, ifstream& inFile2) { inFile1.open("students.data"); // opens the students input file inFile2.open("items.data"); // opens the items input file isEmptyStud.setEmail("empty"); // original initialized to empty isEmptyStud.setCity("empty"); isEmptyStud.setName("empty"); isEmptyStud.setOther("empty"); isEmptyStud.setPhone("empty"); isEmptyStud.setState("empty"); isEmptyStud.setStreet("empty"); isEmptyStud.setZip("empty"); isEmptyStud.setApt("empty"); isEmptyMulti.setOwner("empty"); // original initialized to empty isEmptyMulti.setAvail("empty"); isEmptyMulti.setBy("empty"); isEmptyMulti.setItem("empty"); isEmptyMulti.setPrice("empty"); isEmptyMulti.setType("empty"); for(int x = 0; x < 100; x++) { studentArray[x] = isEmptyStud; // original passed to every array location multimediaArray[x] = isEmptyMulti; } studArrayCount = -1; // used with inputs itemArrayCount = -1; foundAt = -1; } array::~array() { } void array::inputItems(ifstream& inFile1, ifstream& inFile2) { string tempitem = "empty"; string temptype = "empty"; string tempby = "empty"; string tempowner = "empty"; string tempprice = "empty"; string tempavail = "empty"; string check = "empty"; char ch; assert(tempitem == "empty" && temptype == "empty" && tempby == "empty" && tempowner == "empty" && tempprice == "empty" && tempavail == "empty"); if(inFile2.peek() == '@') { itemArrayCount++; inFile2.get(ch); getline(inFile2, check, '\n'); while(inFile2 && itemArrayCount < 100) { if(check == "Item:") { getline(inFile2, tempitem, '\n'); inFile2 >> ws; } else if(check == "Media Type:") { inFile2 >> temptype; inFile2 >> ws; } else if(check == "@") { inFile2 >> ws; if(searchEmail(tempowner) != 100 && tempowner != "empty") { if(tempitem != "empty") { multimediaArray[itemArrayCount].setItem(tempitem); } if(temptype != "empty") { multimediaArray[itemArrayCount].setType(temptype); } if(tempby != "empty") { multimediaArray[itemArrayCount].setBy(tempby); } if(tempowner != "empty") { multimediaArray[itemArrayCount].setOwner(tempowner); } if(tempprice != "empty") { multimediaArray[itemArrayCount].setPrice(tempprice); } if(tempavail != "empty") { multimediaArray[itemArrayCount].setAvail(tempavail); } } tempitem = "empty"; temptype = "empty"; tempby = "empty"; tempowner = "empty"; tempprice = "empty"; tempavail = "empty"; check = "empty"; itemArrayCount++; } else if(check == "by:") { getline(inFile2, tempby, '\n'); inFile2 >> ws; } else if(check == "Owner:") { getline(inFile2, tempowner, '\n'); inFile2 >> ws; } else if(check == "Price:") { getline(inFile2, tempprice, '\n'); inFile2 >> ws; } else if(check == "Availability:") { getline(inFile2, tempavail, '\n'); inFile2 >> ws; } check = "empty"; inFile2.get(ch); getline(inFile2, check, '\n'); } } inFile2.close(); } void array::inputStudent(ifstream& inFile1, ifstream& inFile2) { string tempname = "empty"; string tempphone = "empty"; string tempemail = "empty"; string tempstreet = "empty"; string tempapt = "empty"; string tempcity = "empty"; string tempstate = "empty"; string tempzip = "empty"; string tempother = "empty"; string check = "empty"; char ch; if(inFile1.peek() == '@') { studArrayCount++; inFile1.get(ch); getline(inFile1, check, '\n'); while(inFile1 && studArrayCount < 100) { if(check == "Name:") { getline(inFile1, tempname, '\n'); studentArray[studArrayCount].setName(tempname); inFile1 >> ws; } else if(check == "E-mail:") { inFile1 >> tempemail; studentArray[studArrayCount].setEmail(tempemail); inFile1 >> ws; } else if(check == "@") { inFile1 >> ws; studArrayCount++; } else if(check == "Address Line 2:") { getline(inFile1, tempapt, '\n'); studentArray[studArrayCount].setStreet(tempapt); inFile1 >> ws; } else if(check == "Phone Number:") { getline(inFile1, tempphone, '\n'); studentArray[studArrayCount].setPhone(tempphone); inFile1 >> ws; } else if(check == "City:") { getline(inFile1, tempcity, '\n'); studentArray[studArrayCount].setCity(tempcity); inFile1 >> ws; } else if(check == "Other:") { getline(inFile1, tempother, '\n'); studentArray[studArrayCount].setOther(tempother); inFile1 >> ws; } else if(check == "Zipcode:") { getline(inFile1, tempzip, '\n'); studentArray[studArrayCount].setZip(tempzip); inFile1 >> ws; } else if(check == "State:") { getline(inFile1, tempstate, '\n'); studentArray[studArrayCount].setState(tempstate); inFile1 >> ws; } else if(check == "Address Line 1:") { getline(inFile1, tempapt, '\n'); studentArray[studArrayCount].setApt(tempapt); inFile1 >> ws; } tempname = "empty"; tempphone = "empty"; tempemail = "empty"; tempstreet = "empty"; tempapt = "empty"; tempcity = "empty"; tempstate = "empty"; tempzip = "empty"; tempother = "empty"; check = "empty"; inFile1.get(ch); getline(inFile1, check, '\n'); } } inputItems(inFile1, inFile2); inFile1.close(); } void array::addItem(string& tempitem, string& temptype, string& tempby, string& tempowner, string& tempprice, string& tempavail) { ofstream outFile("output.data", ios::app); outFile << "add item\t" << endl; bool checkSuccess = false; bool foundEmail = false; int x; x = searchEmptyItem(); if(itemArrayCount < 100 && searchEmail(tempowner) != 100 && tempowner != "empty") { multimediaArray[x].setOwner(tempowner); checkSuccess = true; if(tempitem == "empty") { } else { multimediaArray[x].setItem(tempitem); } if(temptype == "empty") { } else { multimediaArray[x].setType(temptype); } if(tempby == "empty") { } else { multimediaArray[x].setBy(tempby); } if(tempprice == "empty") { } else { multimediaArray[x].setPrice(tempprice); } if(tempavail == "empty") { } else { multimediaArray[x].setAvail(tempavail); } itemArrayCount++; } if(checkSuccess == false) { outFile << "Failure" << endl;; } else if(checkSuccess == true) { outFile << "Success" << endl; } outFile.close(); } void array::addStudent(string& tempname, string& tempphone, string& tempemail, string& tempstreet, string& tempapt, string& tempcity, string& tempstate, string& tempzip, string& tempother) { ofstream outFile("output.data", ios::app); outFile << "add student\t" << endl; bool checkSuccess = false; int x; x = searchEmpty(); if(studArrayCount < 100) { if(tempname == "empty") { } else { studentArray[x].setName(tempname); } if(tempphone == "empty") { } else { studentArray[x].setPhone(tempphone); } if(tempemail == "empty") { checkSuccess = false; } else { studentArray[x].setEmail(tempemail); checkSuccess = true; } if(tempstreet == "empty") { } else { studentArray[x].setStreet(tempstreet); } if(tempapt == "empty") { } else { studentArray[x].setApt(tempapt); } if(tempcity == "empty") { } else { studentArray[x].setCity(tempcity); } if(tempstate == "empty") { } else { studentArray[x].setState(tempstate); } if(tempzip == "empty") { } else { studentArray[x].setZip(tempzip); } if(tempother == "empty") { } else { studentArray[x].setOther(tempother); } studArrayCount++; } if(checkSuccess == false) { outFile << "Failure" << endl; } else if(checkSuccess == true) { outFile << "Success" << endl; } outFile.close(); } void array::printItems() { ofstream outFile("output.data", ios::app); outFile << "print items\t" << endl; bool checkSuccess = false; for(int x = 0; x < 100; x++) { if(multimediaArray[x].getOwner() == "empty") { } else { checkSuccess = true; if(multimediaArray[x].getItem() == "empty") { } else { outFile << "Item:\n\t" << multimediaArray[x].getItem() << endl; } if(multimediaArray[x].getType() == "empty") { } else { outFile << "Media Type:\n\t" << multimediaArray[x].getType() << endl; } if(multimediaArray[x].getBy() == "empty") { } else { outFile << "by:\n\t" << multimediaArray[x].getBy() << endl; } outFile << "Owner:\n\t" << multimediaArray[x].getOwner() << endl; if(multimediaArray[x].getPrice() == "empty") { } else { outFile << "Price:\n\t" << multimediaArray[x].getPrice() << endl; } if(multimediaArray[x].getAvail() == "empty") { outFile << endl; } else { outFile << "Availability:\n\t" << multimediaArray[x].getAvail() << endl << endl; } } } outFile.close(); } void array::printStudents() { ofstream outFile("output.data", ios::app); bool checkSuccess = false; outFile << "print students\t" << endl; for(int x = 0; x < 100; x++) { if(studentArray[x].getEmail() == "empty") { } else { checkSuccess = true; if(studentArray[x].getName() == "empty") { } else { outFile << "Name:\n\t" << studentArray[x].getName() << endl; } if(studentArray[x].getPhone() == "empty") { } else { outFile << "Phone Number:\n\t" << studentArray[x].getPhone() << endl; } outFile << "Email:\n\t" << studentArray[x].getEmail() << endl; if(studentArray[x].getApt() != "empty" || studentArray[x].getStreet() != "empty") { outFile << "Address:\n\t"; } else if(studentArray[x].getCity() != "empty" || studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty") { outFile << "Address:\n"; } if(studentArray[x].getApt() == "empty") { } else { outFile << studentArray[x].getApt(); } if(studentArray[x].getApt() != "empty" && studentArray[x].getStreet() != "empty") { outFile << "\n\t"; } if(studentArray[x].getStreet() == "empty") { } else { outFile << studentArray[x].getStreet(); } if(studentArray[x].getApt() != "empty" || studentArray[x].getStreet() != "empty") { outFile << endl; } if(studentArray[x].getCity() != "empty" || studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty") { outFile << '\t'; } if(studentArray[x].getCity() == "empty") { } else { outFile << studentArray[x].getCity(); } if(studentArray[x].getCity() != "empty" && (studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty")) { outFile << ", "; } if(studentArray[x].getState() == "empty") { } else { outFile << studentArray[x].getState(); } if(studentArray[x].getZip() != "empty" && studentArray[x].getState() != "empty") { outFile << ' '; } if(studentArray[x].getZip() == "empty") { } else { outFile << studentArray[x].getZip(); } if(studentArray[x].getCity() != "empty" || studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty") { outFile << endl; } if(studentArray[x].getOther() == "empty") { outFile << endl; } else { outFile << "Other:\n\t" << studentArray[x].getOther() << endl << endl; } } } outFile.close(); } void array::printIndivid(string& tempemail) { ofstream outFile("output.data", ios::app); outFile << "print\t" << tempemail << endl; bool checkSuccess = false; int x; x = searchEmail(tempemail); if(x != 100) { checkSuccess = true; if(studentArray[x].getName() == "empty") { } else { outFile << "Name:\n\t" << studentArray[x].getName() << endl; } if(studentArray[x].getPhone() == "empty") { } else { outFile << "Phone Number:\n\t" << studentArray[x].getPhone() << endl; } outFile << "Email:\n\t" << studentArray[x].getEmail() << endl; if(studentArray[x].getApt() != "empty" || studentArray[x].getStreet() != "empty") { outFile << "Address:\n\t"; } else if(studentArray[x].getCity() != "empty" || studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty") { outFile << "Address:\n"; } if(studentArray[x].getApt() == "empty") { } else { outFile << studentArray[x].getApt(); } if(studentArray[x].getApt() != "empty" && studentArray[x].getStreet() != "empty") { outFile << "\n\t"; } if(studentArray[x].getStreet() == "empty") { } else { outFile << studentArray[x].getStreet(); } if(studentArray[x].getApt() != "empty" || studentArray[x].getStreet() != "empty") { outFile << endl; } if(studentArray[x].getCity() != "empty" || studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty") { outFile << '\t'; } if(studentArray[x].getCity() == "empty") { } else { outFile << studentArray[x].getCity(); } if(studentArray[x].getCity() != "empty" && (studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty")) { outFile << ", "; } if(studentArray[x].getState() == "empty") { } else { outFile << studentArray[x].getState(); } if(studentArray[x].getZip() != "empty" && studentArray[x].getState() != "empty") { outFile << ' '; } if(studentArray[x].getZip() == "empty") { } else { outFile << studentArray[x].getZip(); } if(studentArray[x].getCity() != "empty" || studentArray[x].getState() != "empty" || studentArray[x].getZip() != "empty") { outFile << endl; } if(studentArray[x].getOther() == "empty") { outFile << endl; } else { outFile << "Other:\n\t" << studentArray[x].getOther() << endl << endl; } } for(int y = 0; y < 100; y++) { if(multimediaArray[y].getOwner() == tempemail) { if(multimediaArray[y].getItem() == "empty") { } else { outFile << "Item:\n\t" << multimediaArray[y].getItem() << endl; } if(multimediaArray[y].getType() == "empty") { } else { outFile << "Media Type:\n\t" << multimediaArray[y].getType() << endl; } if(multimediaArray[y].getBy() == "empty") { } else { outFile << "by:\n\t" << multimediaArray[y].getBy() << endl; } if(multimediaArray[y].getPrice() == "empty") { } else { outFile << "Price:\n\t" << multimediaArray[y].getPrice() << endl; } if(multimediaArray[y].getAvail() == "empty") { outFile << endl; } else { outFile << "Availability:\n\t" << multimediaArray[y].getAvail() << endl << endl; } } } if(checkSuccess == false) { outFile << tempemail << " not found." << endl; } outFile.close(); } void array::deleteIndivid(string& tempemail) { ofstream outFile("output.data", ios::app); outFile << "delete\t" << tempemail << endl; bool checkSuccess = true; int x; x = searchEmail(tempemail); if(x != 100) { studentArray[x] = isEmptyStud; studArrayCount--; } else { checkSuccess = false; } for(int y = 0; y < 100; y++) { if(multimediaArray[y].getOwner() == tempemail && checkSuccess == true) { multimediaArray[y] = isEmptyMulti; itemArrayCount--; } } if(checkSuccess == false) { outFile << "Failure" << endl; } else if(checkSuccess == true) { outFile << "Success" << endl; } outFile.close(); } int array::searchEmail(string& tempemail) { int x = 0; int found = 0; while(found == 0 && x < 100) { if(tempemail == studentArray[x].getEmail()) { found = 1; } else { x++; } } return(x); } int array::searchEmpty() { int x = 0; int found = 0; while(found == 0 && x <100) { if(studentArray[x].getEmail() == "empty") { found = 1; } else { x++; } } return(x); } int array::searchEmptyItem() { int x = 0; int found = 0; while(found == 0 && x < 100) { if(multimediaArray[x].getOwner() == "empty") { found = 1; } else { x++; } } return(x); }