/* Project 2 for CS 1704, Spring 2004 Programmer: John Christopher Humphreys OS: Windows XP Professional System: Pentium M, 512 MB Compiler: Microsoft Visual Studio.net 2003 Last Modified: February 14, 2004 Purpose- This program will store student data and data of certain items in two arrays. Classes will be created to hold and manage data of each kind, and a class will manage the arrays. Data can be edited, printed, or cleared by the controlling class, and all commands, taken from an input file, will be processed and executed. Format for Comment Block provided by (http://courses.cs.vt.edu/~cs1704/spring2004/Standards/ProgramHeader.txt) */ #include #include #include #include #include #include using namespace std; #include "Control.h" // Include Control Class Control::Control() /* Control::Control () Constructor Parameters: Student Students[] Item Items[] Pre: All input files, output files, and class definitions are correct and working properly Post: Two arrays, one for students, one for items are created, and filled with data from input files Returns: None Called by: int main() Calls: Item::PrintOwner() // Return Owner of Item Item::AddTitle(string); // Add Title of Item Item::AddType(string); // Add Type of Item Item::AddAuthor(string); // Add Author of Item Item::AddOwner(string); // Add Owner of Item Item::AddPrice(double); // Add Price of Item Item::AddAvailability(string); // Add Availability of Item Student::PrintE_mail() // Return e-mail of Student Student::AddName(string); // Add name of Student Student::AddNumber(__int64); // Add number of Student Student::AddE_mail(string); // Add e-mail of Student Student::AddAddress1(string); // Add address line 1, as described below Student::AddAddress2(string); // Add address line 2, as described below Student::AddCity(string); // Add city of student Student::AddState(string); // Add state of student Student::AddZipcode(int); // Add zipcode of student Student::AddOther(string); // Add Other comment of Student */ { ifstream studentdata ("students.data"); // Inputs Student Data from File ifstream itemdata ("items.data"); // Inputs Item Data assert(studentdata); // Be sure "students.dat" exists and opens correctly assert(itemdata); // Be sure "items.data" exists and opens correctly int StudentCount = 0; int ItemCount = 0; while(studentdata) // Stores all data from file in Students Array { string ToWhere; // string that holds what kind of information will be given getline(studentdata, ToWhere); // Checks to see what kind of information is provided string SD; // string that holds next information SD = Student Data if (ToWhere == "@Name:") // If information is a name, store it as a name { getline(studentdata, SD); // Gets information Students[StudentCount].AddName (SD); } else if (ToWhere == "@Phone Number:") // If information is a Phone Number, store it as a phone number { char StD[20] = {'\b'}; // Array to Hold Number studentdata.getline (StD, 20, '\n'); // Gets information __int64 SiD = 0; // int that will be zipcode string stream = ""; // string to conver to zipcode for (int i = 0; i < 20; i++) { if (StD[i] >= '0' && StD[i] <= '9') // Check to see if character is a number according to ASCII { stream += StD[i]; // Add character to string } } if (stream.length () == 10) // If there are 10 characters (i.e. 10 numbers in zipcode) { istringstream SiDstream (stream); // stringstream to convert string to int SiDstream >> SiD; // Change value to an int and place in array Students[StudentCount].AddNumber (SiD); } } else if (ToWhere == "@E-mail:") // If information is an e-mail address, store it as an e-mail address { getline(studentdata, SD); // Gets information Students[StudentCount].AddE_mail (SD); } else if (ToWhere == "@Address Line 1:") // If information is an address1, store it as address1 { getline(studentdata, SD); // Gets information Students[StudentCount].AddAddress1 (SD); } else if (ToWhere == "@Address Line 2:") // If information is an address2, store it as address2 { getline(studentdata, SD); // Gets information Students[StudentCount].AddAddress2 (SD); } else if (ToWhere == "@City:") // If information is a city, store it as a city { getline(studentdata, SD); // Gets information Students[StudentCount].AddCity (SD); } else if (ToWhere == "@State:") // If information is a state, store it as a state { getline(studentdata, SD); // Gets information Students[StudentCount].AddState (SD); } else if (ToWhere == "@Zipcode:") // If information is a zipcode, store it as a zipcode { int SiD; studentdata >> SiD; // Gets information Students[StudentCount].AddZipcode (SiD); } else if (ToWhere == "@Other:") // If information is Other, store it as other { getline(studentdata, SD); // Gets information Students[StudentCount].AddOther (SD); } else if (ToWhere == "@@") // This signifies the end of a student's data { StudentCount ++; // So add one to the counter for next time getline(studentdata, SD); // Realign Input marker } } while(itemdata) { string ToWhere; // string that holds what kind of information will be given getline(itemdata, ToWhere); // Checks to see what kind of information is provided string ID; // string that holds next information ID = Item Data getline(itemdata, ID); // Gets information if (ToWhere == "@Item:") // If information is an title, save it as a title Items[ItemCount].AddTitle (ID); else if (ToWhere == "@Media Type:") // If information is a type, save it as a type Items[ItemCount].AddType (ID); else if (ToWhere == "@by:") // If information is an author, save it as an author Items[ItemCount].AddAuthor (ID); else if (ToWhere == "@Owner:") // If information is an owner, save it as an owner Items[ItemCount].AddOwner (ID); else if (ToWhere == "@Price:") // If information is a price, save it as a price { double IfD = 0.0; string convertstring = ""; for (int i = 1; i < ID.length(); i++) // Chop off '$' and send to string convertstring += ID[i]; // Put in stringstream and return as a double istringstream convertstream (convertstring); convertstream >> IfD; Items[ItemCount].AddPrice (IfD); } else if (ToWhere == "@Availability:") // If information is an availability,save it as such Items[ItemCount].AddAvailability (ID); else if (ToWhere == "@@") // This signifies the item's information is over, so add one to the counter { ItemCount++; bool present = false; for (int i = 0; i < 100; i ++) // Scroll through the Students array to see if the item's e-mail is present { if (Students[i].PrintE_mail () == Items[ItemCount - 1].PrintOwner ()) present = true; // If so, set the boolean to be true } if (present == false) // If the e-mail did not show up, erase the previous entry { ItemCount--; // Items[ItemCount].DeleteTitle (); // Items[ItemCount].DeleteType (); // Items[ItemCount].DeleteAuthor (); // Items[ItemCount].DeleteOwner (); // Items[ItemCount].DeletePrice (); // Items[ItemCount].DeleteAvailability (); // } } } studentdata.close(); // Close input file itemdata.close(); // Close input file } void Control::PrintStudents(string E_Mail_Test, ostream & outdata) const /* Control::PrintStudents() Accessor Parameters: string E_Mail_Test If empty, all students will be printed, if not, only one will be printed ostream & outdata output file Student Students[] Pre: It has been determined whether all or just one student is to be printed Students array is in proper format Post: All students and their data has been displayed, or all data for one specific student has been outputted, depending on the string input Returns: None Called by: int main() Calls: Student::PrintName(); // Print name of Student Student::PrintNumber(); // Print number of Student Student::PrintE_mail(); // Print e-mail of Student Student::PrintAddress1(); // Print Address line 1, as described below Student::PrintAddress2(); // Print Address line 2, as described below Student::PrintCity(); // Print city of student Student::PrintState(); // Print state of student Student::PrintZipcode(); // Print zipcode of student Student::PrintOther(); // Print Other comment of Student */ { if (E_Mail_Test == "") { outdata << "print students" << endl; // Recall function call into output file for (int i = 0; i < 100; i ++) // Loop through whole students array { if (Students[i].PrintName() != "") { outdata << "Name:\n"; // If Name is present, print it outdata << " " << Students[i].PrintName() << endl; } if (Students[i].PrintNumber() > 0) { outdata << "Phone Number:\n"; // If Phone Number is present, print it __int64 StD = Students[i].PrintNumber (); // Set as the numbers, unformatted string createnumber = ""; // Will be input from string stream string phonenumber = ""; // Will be string of formatted numbers ostringstream StDstream; // Will convert int to string StDstream << StD; // Send the int to the stream createnumber = StDstream.str(); // Take the stream back to a string int zerocount = 0; // Will keep track of how many leading zeros are in the phone number phonenumber += "("; // Add in numbers and proper formats if (StD < 1000000000) // If the first number is a zero { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 100000000) // If the first two numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 10000000) // If the first three numbers are zeroes { phonenumber += "0) "; // Add one in zerocount ++; // Add one to the counter } if (StD < 1000000) // If the first four numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 100000) // If the first five numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 10000) // If the first six numbers are zeroes { phonenumber += "0-"; // Add one in zerocount ++; // Add one to the counter } if (StD < 1000) // If the first seven numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 100) // If the first eight numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 10) // If the first nine numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 1) // If the first ten numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (zerocount == 0) // Add in numbers when no leading zeroes { for (int i = zerocount; i < 3; i++) phonenumber += createnumber[i]; phonenumber += ") "; } else if (zerocount < 3) // Add in numbers after leading zeroes { for (int i = 0; i < (3 - zerocount); i++) phonenumber += createnumber [i]; phonenumber += ") "; } if (zerocount == 0) // Add in numbers when no leading zeroes { for (int i = 3; i < (6 - zerocount); i++) phonenumber += createnumber[i]; phonenumber += "-"; } else if (zerocount < 3) // Add in numbers after leading zeroes { for (int i = (3 - zerocount); i < (6 - zerocount); i++) phonenumber += createnumber[i]; phonenumber += "-"; } else if (zerocount < 6 && zerocount > 2) // Add in numbers after leading zeroes { for (int i = 0; i < (6 - zerocount); i++) phonenumber += createnumber [i+3]; phonenumber += "-"; } if (zerocount == 0) // Add in numbers when no leading zeroes { for (int i = (zerocount + 6); i < (10 - zerocount); i++) phonenumber += createnumber[i]; } else if (zerocount < 3) // Add in numbers after leading zeroes { for (int i = (6 - zerocount); i < (10 - zerocount); i++) phonenumber += createnumber[i]; } else if (zerocount < 10 && zerocount > 5) // Add in numbers after leading zeroes { for (int i = 0; i < (10 - zerocount); i++) phonenumber += createnumber [i+6]; } outdata << " " << phonenumber << endl; // Print string of formatted number } if (Students[i].PrintE_mail() != "") { outdata << "Email:\n"; // If E-mail is present, print it outdata << " " << Students[i].PrintE_mail() << endl; } if (Students[i].PrintAddress1 () != "" || Students[i].PrintAddress2 () != "" || Students[i].PrintCity () != "" || Students[i].PrintState () != "" || Students[i].PrintZipcode () != 0) // Sets up Address Lines { outdata << "Address:\n"; if (Students[i].PrintAddress1 () != "") outdata << " " << Students[i].PrintAddress1 () << endl; // If Address Line 1 is present, print it if (Students[i].PrintAddress2 () != "") outdata << " " << Students[i].PrintAddress2 () << endl; // If Address Line 2 is present, print it if (Students[i].PrintCity () != "" || Students[i].PrintState () != "" || Students[i].PrintZipcode () != 0) // Sets up Address Line 3 { outdata << " "; if (Students[i].PrintCity () != "") outdata << Students[i].PrintCity (); // If City is present, print it if (Students[i].PrintCity () != "" && (Students[i].PrintState () != "" || Students[i].PrintZipcode () != 0)) outdata << ", "; // This will only add a comma if a city and something after it on the same line exists if (Students[i].PrintState () != "") outdata << Students[i].PrintState () << " "; // If State is present, print it if (Students[i].PrintZipcode () != 0) { if (Students[i].PrintZipcode () < 10000) outdata << "0"; if (Students[i].PrintZipcode () < 1000) outdata << "0"; // Add in leading zeroes if Zipcode isn't 5 digits if (Students[i].PrintZipcode () < 100) outdata << "0"; if (Students[i].PrintZipcode () < 10) outdata << "0"; outdata << Students[i].PrintZipcode (); // If Zipcode is present, print it } outdata << endl; } } if (Students[i].PrintOther () != "") { outdata << "Other:\n"; // If Other is present, print it outdata << " " << Students[i].PrintOther () << endl; } if (Students[i].PrintName() != "" || Students[i].PrintNumber() != 0 || Students[i].PrintE_mail() != "" || Students[i].PrintAddress1 () != "" || Students[i].PrintAddress2 () != "" || Students[i].PrintCity () != "" || Students[i].PrintState () != "" || Students[i].PrintZipcode () != 0 || Students[i].PrintOther () != "") outdata << endl; // aesthetic adjustment } } else { outdata << "print " << E_Mail_Test << endl; bool ispresent = false; // Used to test progress of print function. for (int i = 0; i < 100; i ++) // Search through whole array { if (Students[i].PrintE_mail () == E_Mail_Test) { ispresent = true; // Means the e-mail does exist if (Students[i].PrintName() != "") { outdata << "Name:\n"; // If Name is present, print it outdata << " " << Students[i].PrintName() << endl; } if (Students[i].PrintNumber() > 0) { outdata << "Phone Number:\n"; // If Phone Number is present, print it __int64 StD = Students[i].PrintNumber (); // Set as the numbers, unformatted string createnumber = ""; // Will be input from string stream string phonenumber = ""; // Will be string of formatted numbers ostringstream StDstream; // Will convert int to string StDstream << StD; // Send the int to the stream createnumber = StDstream.str(); // Take the stream back to a string int zerocount = 0; // Will keep track of how many leading zeros are in the phone number phonenumber += "("; // Add in numbers and proper formats if (StD < 1000000000) // If the first number is a zero { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 100000000) // If the first two numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 10000000) // If the first three numbers are zeroes { phonenumber += "0) "; // Add one in zerocount ++; // Add one to the counter } if (StD < 1000000) // If the first four numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 100000) // If the first five numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 10000) // If the first six numbers are zeroes { phonenumber += "0-"; // Add one in zerocount ++; // Add one to the counter } if (StD < 1000) // If the first seven numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 100) // If the first eight numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 10) // If the first nine numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (StD < 1) // If the first ten numbers are zeroes { phonenumber += '0'; // Add one in zerocount ++; // Add one to the counter } if (zerocount == 0) // Add in numbers when no leading zeroes { for (int i = zerocount; i < 3; i++) phonenumber += createnumber[i]; phonenumber += ") "; } else if (zerocount < 3) // Add in numbers after leading zeroes { for (int i = 0; i < (3 - zerocount); i++) phonenumber += createnumber [i]; phonenumber += ") "; } if (zerocount == 0) // Add in numbers when no leading zeroes { for (int i = 3; i < (6 - zerocount); i++) phonenumber += createnumber[i]; phonenumber += "-"; } else if (zerocount < 3) // Add in numbers after leading zeroes { for (int i = (3 - zerocount); i < (6 - zerocount); i++) phonenumber += createnumber[i]; phonenumber += "-"; } else if (zerocount < 6 && zerocount > 2) // Add in numbers after leading zeroes { for (int i = 0; i < (6 - zerocount); i++) phonenumber += createnumber [i+3]; phonenumber += "-"; } if (zerocount == 0) // Add in numbers when no leading zeroes { for (int i = (zerocount + 6); i < (10 - zerocount); i++) phonenumber += createnumber[i]; } else if (zerocount < 3) // Add in numbers after leading zeroes { for (int i = (6 - zerocount); i < (10 - zerocount); i++) phonenumber += createnumber[i]; } else if (zerocount < 10 && zerocount > 5) // Add in numbers after leading zeroes { for (int i = 0; i < (10 - zerocount); i++) phonenumber += createnumber [i+6]; } outdata << " " << phonenumber << endl; // Print string of formatted number } if (Students[i].PrintE_mail() != "") { outdata << "Email:\n"; // If E-mail is present, print it outdata << " " << Students[i].PrintE_mail() << endl; } if (Students[i].PrintAddress1 () != "" || Students[i].PrintAddress2 () != "" || Students[i].PrintCity () != "" || Students[i].PrintState () != "" || Students[i].PrintZipcode () != 0) // Sets up Address Lines { outdata << "Address:\n"; if (Students[i].PrintAddress1 () != "") outdata << " " << Students[i].PrintAddress1 () << endl; // If Address Line 1 is present, print it if (Students[i].PrintAddress2 () != "") outdata << " " << Students[i].PrintAddress2 () << endl; // If Address Line 2 is present, print it if (Students[i].PrintCity () != "" || Students[i].PrintState () != "" || Students[i].PrintZipcode () != 0) // Sets up Address Line 3 { outdata << " "; if (Students[i].PrintCity () != "") outdata << Students[i].PrintCity () << ", "; // If City is present, print it if (Students[i].PrintState () != "") outdata << Students[i].PrintState () << " "; // If State is present, print it if (Students[i].PrintZipcode () != 0) { if (Students[i].PrintZipcode () < 10000) outdata << "0"; if (Students[i].PrintZipcode () < 1000) outdata << "0"; // Add in leading zeroes if Zipcode isn't 5 digits if (Students[i].PrintZipcode () < 100) outdata << "0"; if (Students[i].PrintZipcode () < 10) outdata << "0"; outdata << Students[i].PrintZipcode (); // If Zipcode is present, print it } outdata << endl; } } if (Students[i].PrintOther () != "") { outdata << "Other:\n"; // If Other is present, print it outdata << " " << Students[i].PrintOther () << endl; } outdata << endl; } } if (ispresent == false) outdata << E_Mail_Test << " not found.\n"; // Output error message } } void Control::PrintItems(string E_Mail_Test, ostream & outdata) const /* Control::PrintItems() Accessor Parameters: string E_Mail_Test If empty, all items will be printed, if not, only items for specific e-mail will be printed ostream & outdata output file Item Items[] Pre: It has been determined whether all or just one set of data is to be printed Items array is in proper format Post: All items and their data has been displayed, or all items for one specific e-mail has been outputted, depending on the string input Returns: None Called by: int main() Calls: Item::PrintTitle(); // Print Title of Item Item::PrintType(); // Print Type of Item Item::PrintAuthor(); // Print Author of Item Item::PrintOwner(); // Print Owner of Item Item::PrintPrice(); // Print Price of Item Item::PrintAvailability(); // Print Availability of Item */ { if (E_Mail_Test == "") { cout << "blank"; outdata << "print items" << endl; // Recall function into output file for (int i = 0; i < 100; i++) // Loop through hole items array { if (Items[i].PrintTitle () != "") { outdata << "Item:" << endl; // If Title is present, print it outdata << " " << Items[i].PrintTitle () << endl; } if (Items[i].PrintType () != "") { outdata << "Media Type:" << endl; // If Type is present, print it outdata << " " << Items[i].PrintType () << endl; } if (Items[i].PrintAuthor () != "") { outdata << "by:" << endl; // If Author is present, print it outdata << " " << Items[i].PrintAuthor () << endl; } if (Items[i].PrintOwner () != "") { outdata << "Owner:" << endl; // If Owner is present, print it outdata << " " << Items[i].PrintOwner () << endl; } if (Items[i].PrintPrice () > 0.001) { outdata << "Price:" << endl; // If Price is present, print it outdata << fixed << setprecision(2) << " $" << Items[i].PrintPrice () << endl; } if (Items[i].PrintAvailability () != "") { outdata << "Availability:" << endl; // If Availability is present, print it outdata << " " << Items[i].PrintAvailability () << endl; } if (Items[i].PrintTitle () != "" || Items[i].PrintType () != "" || Items[i].PrintAuthor () != "" || Items[i].PrintOwner () != "" || Items[i].PrintPrice () > 0.001 || Items[i].PrintAvailability () != "") outdata << endl; // Aesthetic adjustment } } else { for (int i = 0; i < 100; i ++) // Search through whole array { if (Items[i].PrintOwner () == E_Mail_Test) { if (Items[i].PrintTitle () != "") { outdata << "Item:" << endl; // If Title is present, print it outdata << " " << Items[i].PrintTitle () << endl; } if (Items[i].PrintType () != "") { outdata << "Media Type:" << endl; // If Type is present, print it outdata << " " << Items[i].PrintType () << endl; } if (Items[i].PrintAuthor () != "") { outdata << "by:" << endl; // If Author is present, print it outdata << " " << Items[i].PrintAuthor () << endl; } if (Items[i].PrintPrice () > 0.001) { outdata << "Price:" << endl; // If Price is present, print it outdata << " $" << Items[i].PrintPrice () << endl; } if (Items[i].PrintAvailability () != "") { outdata << "Availability:" << endl; // If Availability is present, print it outdata << " " << Items[i].PrintAvailability () << endl; } outdata << endl; } } } } void Control::AddItem(istream & commanddata, ostream & outdata) /* Control::AddItem() Mutator Parameters: istream commanddata where data for item will be found ostream outdata output file Student Students[] Item Items[] Pre: All input files, output files, and class definitions are correct and working properly Post: If the item belongs to an existing student, it will be added to the items array If a student of the item does not exist, the item will not be added Returns: None Called by: int main() Calls: Item::AddTitle(string); // Add Title of Item Item::AddType(string); // Add Type of Item Item::AddAuthor(string); // Add Author of Item Item::AddOwner(string); // Add Owner of Item Item::AddPrice(double); // Add Price of Item Item::AddAvailability(string); // Add Availability of Item Item::PrintTitle(); // Print Title of Item Item::PrintType(); // Print Type of Item Item::PrintAuthor(); // Print Author of Item Item::PrintOwner(); // Print Owner of Item Item::PrintPrice(); // Print Price of Item Item::PrintAvailability(); // Print Availability of Item Student::PrintE_mail() // Return e-mail of Student */ { outdata << "add item" << endl; // Echo function call int i = 0; bool whentostop = false; // aids in breaking the loop, switched when an empty space is found while(!whentostop && i < 100) { if (Items[i].PrintTitle() == "" && Items[i].PrintType() == "" && Items[i].PrintAuthor() == "" && Items[i].PrintOwner () == "" && Items[i].PrintPrice () < 0.001 && Items[i].PrintAvailability () == "") { string ToWhere = ""; // string that holds what kind of information will be given string ID = ""; // string that holds next information ID = Item Data string filler = ""; // string will help to readjust istream position whentostop = true; // will make outer loop break getline(commanddata, filler); // Readjust istream position getline(commanddata, ToWhere); // Checks to see what kind of information is provided getline(commanddata, ID); // Gets information while (ToWhere != "@@") { if (ToWhere == "@Item:") // If information is a title, store it as a title Items[i].AddTitle (ID); else if (ToWhere == "@Media Type:") // If information is a Media Type, store it as a Media Type Items[i].AddType (ID); else if (ToWhere == "@by:") // If information is an Author, store it as an Author Items[i].AddAuthor (ID); else if (ToWhere == "@Owner:") // If information is an Owner, store it as Owner Items[i].AddOwner (ID); else if (ToWhere == "@Price:") // If information is an Price, store it as Price { double IfD = 0.0; string convertstring = ""; for (int j = 1; j < ID.length(); j++) // Chop off $ and put the number in a string convertstring += ID[j]; // Send string to stringstream and return as double istringstream convertstream (convertstring); convertstream >> IfD; Items[i].AddPrice (IfD); } else if (ToWhere == "@Availability:") // If information is a Availability, store it as a Availability Items[i].AddAvailability (ID); getline(commanddata, ToWhere); // Checks to see what kind of information is provided getline(commanddata, ID); // Gets information } } i++; } bool present = false; for (int j = 0; j < 100; j ++) // Scroll through the Students array to see if the item's e-mail is present { if (Students[j].PrintE_mail () == Items[i-1].PrintOwner ()) present = true; // If so, set the boolean to be true } if (present == false) // If the e-mail did not show up, erase the previous entry { string empty = ""; // double zero = 0.0; // Items[i-1].AddTitle (empty); // Items[i-1].AddType (empty); // Items[i-1].AddAuthor (empty); // Items[i-1].AddOwner (empty); // Items[i-1].AddPrice (zero); // Items[i-1].AddAvailability (empty); // } if (whentostop == false || present == false) outdata << "Failure" << endl; // Progress report else outdata << "Success" << endl; // Progress report } void Control::AddStudent(istream & commanddata, ostream & outdata) /* Control::AddStudent() Mutator Parameters: istream & commanddata input file to take student data from ostream & commanddata output file Student Students[] Pre: All input files, output files, and class definitions are correct and working properly Post: Student has been added to the next open spot in Students array Returns: None Called by: int main() Calls: Student::PrintName(); // Print name of Student Student::PrintNumber(); // Print number of Student Student::PrintE_mail(); // Print e-mail of Student Student::PrintAddress1(); // Print Address line 1, as described below Student::PrintAddress2(); // Print Address line 2, as described below Student::PrintCity(); // Print city of student Student::PrintState(); // Print state of student Student::PrintZipcode(); // Print zipcode of student Student::PrintOther(); // Print Other comment of Student Student::AddName(string); // Add name of Student Student::AddNumber(__int64); // Add number of Student Student::AddE_mail(string); // Add e-mail of Student Student::AddAddress1(string); // Add address line 1, as described below Student::AddAddress2(string); // Add address line 2, as described below Student::AddCity(string); // Add city of student Student::AddState(string); // Add state of student Student::AddZipcode(int); // Add zipcode of student Student::AddOther(string); // Add Other comment of Student */ { outdata << "add student" << endl; // Echo Function int i = 0; bool whentostop = false; // aids in breaking the loop, switched when an empty space is found while(!whentostop && i < 100) { if (Students[i].PrintName() == "" && Students[i].PrintNumber() == 0 && Students[i].PrintE_mail() == "" && Students[i].PrintAddress1 () == "" && Students[i].PrintAddress2 () == "" && Students[i].PrintCity () == "" && Students[i].PrintState () == "" && Students[i].PrintZipcode () == 0 && Students[i].PrintOther () == "") { string ToWhere = ""; // string that holds what kind of information will be given string SD = ""; // string that holds next information SD = Student Data string filler = ""; // string will help to readjust istream position whentostop = true; // will make outer loop break getline(commanddata, filler); // Readjust istream position getline(commanddata, ToWhere); // Checks to see what kind of information is provided while (ToWhere != "@@") { if (ToWhere == "@Name:") // If information is a name, store it as a name { getline(commanddata, SD); // Gets information Students[i].AddName (SD); } else if (ToWhere == "@Phone Number:") // If information is a Phone Number, store it as a phone number { char StD[20] = {'\b'}; // Array to Hold Number commanddata.getline (StD, 20, '\n'); // Gets information __int64 SiD = 0; // int that will be zipcode string stream = ""; // string to conver to zipcode for (int j = 0; j < 20; j++) { if (StD[j] >= '0' && StD[j] <= '9') // Check to see if character is a number according to ASCII stream += StD[j]; // Add character to string } if (stream.length () == 10) // If there are 10 characters (i.e. 10 numbers in zipcode) { istringstream SiDstream (stream); // stringstream to convert string to int SiDstream >> SiD; // Change value to an int and place in array Students[i].AddNumber (SiD); } } else if (ToWhere == "@E-mail:") // If information is an e-mail address, store it as an e-mail address { getline(commanddata, SD); // Gets information Students[i].AddE_mail (SD); } else if (ToWhere == "@Address Line 1:") // If information is an address1, store it as address1 { getline(commanddata, SD); // Gets information Students[i].AddAddress1 (SD); } else if (ToWhere == "@Address Line 2:") // If information is an address2, store it as address2 { getline(commanddata, SD); // Gets information Students[i].AddAddress2 (SD); } else if (ToWhere == "@City:") // If information is a city, store it as a city { getline(commanddata, SD); // Gets information Students[i].AddCity (SD); } else if (ToWhere == "@State:") // If information is a state, store it as a state { getline(commanddata, SD); // Gets information Students[i].AddState (SD); } else if (ToWhere == "@Zipcode:") // If information is a zipcode, store it as a zipcode { int SiD; commanddata >> SiD; Students[i].AddZipcode (SiD); } else if (ToWhere == "@Other:") // If information is Other, store it as other { getline(commanddata, SD); // Gets information Students[i].AddOther (SD); } getline(commanddata, ToWhere); // Checks to see what kind of information is provided } } i++; } if (whentostop == false) outdata << "Failure\n"; // Outputs results of the function else outdata << "Success\n"; } void Control::DeleteAllE_Mail(string E_Mail_Test, ostream & outdata) /* Control::Control () Constructor Parameters: string E_Mail_Test string to find all entries to be deleted ostream outdata output file Student Students[] Item Items[] Pre: All input files, output files, and class definitions are correct and working properly Post: Any entries with e-mail E_Mail_Test will be cleared of their data Returns: None Called by: int main() Calls: Item::DeleteTitle(); // Delete Title of Item Item::DeleteType(); // Delete Type of Item Item::DeleteAuthor(); // Delete Author of Item Item::DeleteOwner(); // Delete Owner of Item Item::DeletePrice(); // Delete Price of Item Item::DeleteAvailability(); // Delete Availability of Item Student::DeleteName(); // Delete name of Student Student::DeleteNumber(); // Delete number of Student Student::DeleteE_mail(); // Delete e-mail of Student Student::DeleteAddress1(); // Delete Address line 1, as described below Student::DeleteAddress2(); // Delete Address line 2, as described below Student::DeleteCity(); // Delete city of student Student::DeleteState(); // Delete state of student Student::DeleteZipcode(); // Delete zipcode of student Student::DeleteOther(); // Delete Other comment of Student */ { outdata << "delete " << E_Mail_Test << endl; // Echo Function bool ispresent = false; // Used for progress report for (int i = 0; i < 100; i ++) // Search through all arrays { if (Students[i].PrintE_mail () == E_Mail_Test) { ispresent = true; // Means the function was a success Students[i].DeleteName (); Students[i].DeleteNumber (); Students[i].DeleteE_mail (); Students[i].DeleteAddress1 (); // Clear all elements of Students array at [i] when the specified e-mail is present Students[i].DeleteAddress2 (); Students[i].DeleteCity (); Students[i].DeleteState (); Students[i].DeleteZipcode (); Students[i].DeleteOther (); } if (Items[i].PrintOwner () == E_Mail_Test) { ispresent = true; // Means the function was a success Items[i].DeleteTitle (); Items[i].DeleteType (); Items[i].DeleteOwner (); // Clear all elements of Students array at [i] when the specified e-mail is present Items[i].DeletePrice (); Items[i].DeleteAuthor (); Items[i].DeleteAvailability (); } } if (ispresent == false) outdata << "Failure\n"; // Display results of the delete else outdata << "Success\n"; } /*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 or unmodified. - If any C++ language code or documentation used in my program was obtained from another source, such as a textbook 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. */