///////////////////////////////////////////////////////////////////////// // 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 the C++ language code obtained from another student, // or any unauthorized source, either modifed or unmodified. // // - If any C++ language code or documentation used in my program // was obtained from another source, such as a text book 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. // // Allan T. Ventii ///////////////////////////////////////////////////////////////////////// //Program: Multimedia Organiser //Programmer: Allan Ventii // 2 February 2004 //About: Organising student information and items for selling, buying, borrowing #include #include #include #include #include #include #include using namespace std; ///class 1 for student info. a member will open and read the student information //and then save them into the values class StudentInfo { //allows Manage class access to data friend class Manage; string Name; //student name string Email; //student email string Address1; //address string Address2; string City; string State; string Other; //other info int areaCode; //areacode int phoneNum; //int for phone num int Zip; //zip code public: //default constructor StudentInfo (); };//end of studentinfo class StudentInfo::StudentInfo() { } ///class 2 for item info. A member will open and read the student information //and then save them into the values class ItemInfo { //allows Manage class access to data friend class Manage; string Item; //item name string Type; //its type string By; //its author string Owner; //its owner string Available; //its availability int Price; //its price public: //default constructor ItemInfo(); };//end of iteminfo class ItemInfo::ItemInfo(){ } ///class 3 for managing other 2 classes //and then save them into the values class Manage { //the two arrays for holding the students and items info are declared here ItemInfo IList[100]; StudentInfo SList[100]; public: Manage(); //default constructor void PrintSpecific(ofstream& outFile, string& Com2); //member for printing specified email void PrintStudents(ofstream& outfile); //member for printing all students void PrintItems(ofstream& outFile); //member for printing all items void AddItem(string, string, string, string, string, int, ofstream& outFile); //member for adding student void AddStudent(string, string, string, string, string, string, string, int, int, int, ofstream& outFile); //member for adding item void Delete(ofstream& outFile, string& Com2); //member for deleting student and his/her items }; //functions for Manage class void Manage::Delete(ofstream& outFile, string& Com2) { //read in the email given, scan students and if email found, set everything at that array //position to # //scan items and if email found, set everything at that array //position to # int checkstat=0; outFile << "delete " << Com2 << endl; for (int count=0; count <100; count++) { if (SList[count].Email == Com2) { assert ((count >=0)&&(count <100)); //assert statement 1 SList[count].Name = "#"; SList[count].phoneNum = 0; SList[count].areaCode = 0; SList[count].Email = "#"; SList[count].Address1 = "#"; SList[count].Address2 = "#"; SList[count].City = "#"; SList[count].State = "#"; SList[count].Zip = 0; SList[count].Other = "#"; checkstat=1; } } for (int count=0; count <100; count++) { if (IList[count].Owner == Com2) { IList[count].Item = "#"; IList[count].Type = "#"; IList[count].By = "#"; IList[count].Owner = "#"; IList[count].Price = 0; IList[count].Available = "#"; checkstat=1; } } if (checkstat==1) outFile << "Success" << endl; else outFile << "Failure" << endl; }//end delete void Manage::PrintSpecific(ofstream& outFile, string& Com2) { //call method in manage class that prints the students info //and all the items s/he has int checkstat=0; //file not found check outFile << "print " << Com2 << endl; //if file found and its not a blank spot then print out student info for (int count=0; count <100; count++) { if (SList[count].Email == Com2) { checkstat=1; assert ((count >=0)&&(count <100)); //assert statement 2 if(SList[count].Name != "#") outFile << "Name:" << endl << SList[count].Name << endl; if (SList[count].phoneNum != 0) outFile << "Phone Number:" << endl << "(" << setw(3) << setfill('0') << SList[count].areaCode << ") " << setw(3) << setfill('0') << SList[count].phoneNum/10000 << "-" << SList[count].phoneNum%10000 << endl; if (SList[count].Email != "#") outFile << "Email:" << endl << SList[count].Email << endl; if (SList[count].Address1 != "#" || SList[count].Address2 != "#" || SList[count].City != "#" || SList[count].State != "#" || SList[count].Zip != 0) outFile << "Address:" << endl; if (SList[count].Address1 != "#") outFile << SList[count].Address1 << endl; if (SList[count].Address2 != "#" ) { outFile << SList[count].Address2 << endl; } if (SList[count].City != "#" && SList[count].State != "#" && SList[count].Zip != 0) outFile << SList[count].City << ", " << SList[count].State << " " << SList[count].Zip << endl; else if (SList[count].City != "#" && SList[count].State != "#") outFile << SList[count].City << ", " << SList[count].State << endl; else if (SList[count].City != "#" && SList[count].Zip != 0) outFile << SList[count].City << ", " << setw(5) << setfill('0') << SList[count].Zip << endl; else if (SList[count].State != "#" && SList[count].Zip != 0) outFile << SList[count].State << " " << setw(5) << setfill('0') << SList[count].Zip << endl; else if (SList[count].State != "#") outFile << SList[count].State << endl; else if (SList[count].City != "#") outFile << SList[count].City << endl; else if (SList[count].Zip != 0) outFile << setw(5) << setfill('0') << SList[count].Zip << endl; if (SList[count].Other != "#") outFile << "Other:" << endl << SList[count].Other << endl; outFile << endl; break; } }//end of for loop //here prints out all student items for (int count=0; count <100; count++) { if (IList[count].Owner == Com2) { assert ((count >=0)&&(count <100)); //assert statement 3 if(IList[count].Item != "#") outFile << "Item:" << endl << IList[count].Item << endl; if (IList[count].Type != "#") outFile << "Media Type:" << endl << IList[count].Type << endl; if (IList[count].By != "#") outFile << "by:" << endl << IList[count].By << endl; if (IList[count].Price != 0) outFile << "Price:" << endl << "$" << IList[count].Price/100 << "." << setw(2) << setfill('0') << IList[count].Price%100 << endl; if (IList[count].Available != "#") { outFile << "Availability:" << endl << IList[count].Available << endl; } outFile << endl; } } if (checkstat==0) outFile << Com2 << " not found." << endl; }//end of manage void Manage::PrintStudents(ofstream& outFile) { //check email position first, if email is = #, skip that array position //call method in manage class that prints the students outFile << "print students" << endl; for(int count=0; count<100; count++) { if(SList[count].Email != "#") { if(SList[count].Name != "#") outFile << "Name:" << endl << SList[count].Name << endl; if (SList[count].phoneNum != 0) outFile << "Phone Number:" << endl << "(" << setw(3) << setfill('0') << SList[count].areaCode << ") " << setw(3) << setfill('0') << SList[count].phoneNum/10000 << "-" << setw(4) << setfill('0') << SList[count].phoneNum%10000 << endl; if (SList[count].Email != "#") outFile << "Email:" << endl << SList[count].Email << endl; if (SList[count].Address1 != "#" || SList[count].Address2 != "#" || SList[count].City != "#" || SList[count].State != "#" || SList[count].Zip != 0) outFile << "Address:" << endl; if (SList[count].Address1 != "#") outFile << SList[count].Address1 << endl; if (SList[count].Address2 != "#" ) { outFile << SList[count].Address2 << endl; } if (SList[count].City != "#" && SList[count].State != "#" && SList[count].Zip != 0) outFile << SList[count].City << ", " << SList[count].State << " " << SList[count].Zip << endl; else if (SList[count].City != "#" && SList[count].State != "#") outFile << SList[count].City << ", " << SList[count].State << endl; else if (SList[count].City != "#" && SList[count].Zip != 0) outFile << SList[count].City << ", " << setw(5) << setfill('0') << SList[count].Zip << endl; else if (SList[count].State != "#" && SList[count].Zip != 0) outFile << SList[count].State << " " << setw(5) << setfill('0') << SList[count].Zip << endl; else if (SList[count].State != "#") outFile << SList[count].State << endl; else if (SList[count].City != "#") outFile << SList[count].City << endl; else if (SList[count].Zip != 0) outFile << setw(5) << setfill('0') << SList[count].Zip << endl; if (SList[count].Other != "#") outFile << "Other:" << endl << SList[count].Other << endl; outFile << endl; } }//end of for loop } void Manage::PrintItems(ofstream& outFile) { //check email position first, if email is = #, skip that array position //call method in manage class that prints the items outFile << "print items" << endl; for(int count=0; count<100; count++) { if(IList[count].Owner != "#") { if(IList[count].Item != "#") outFile << "Item:" << endl << IList[count].Item << endl; if (IList[count].Type != "#") outFile << "Media Type:" << endl << IList[count].Type << endl; if (IList[count].By != "#") outFile << "by:" << endl << IList[count].By << endl; if (IList[count].Owner != "#") outFile << "Owner:" << endl << IList[count].Owner << endl; if (IList[count].Price != 0) outFile << "Price:" << endl << "$" << IList[count].Price/100 << "." << setw(2) << setfill('0') << IList[count].Price%100 << endl; if (IList[count].Available != "#") outFile << "Availability:" << endl << IList[count].Available << endl; outFile << endl; } }//end of for loop } void Manage::AddItem(string I, string MT, string B, string Ow, string Av, int P, ofstream& outFile) { //scan thru array and see if any empty spots (email=#) //add student to first empty array position int checkstat=0; //for success/failure method for(int count=0; count<100; count++) { if(SList[count].Email == Ow) { if(IList[count].Owner == "#") { IList[count].Owner = Ow; IList[count].Item = I; IList[count].Type = MT; IList[count].By = B; IList[count].Available = Av; IList[count].Price = P; checkstat=1; break; } } } outFile << "add item" << endl; if (checkstat==0) outFile << "Failure" << endl; else if(checkstat==1) outFile << "Success" << endl; }//end add item void Manage::AddStudent(string N, string E, string A1, string A2, string C, string S, string O, int pN, int aC, int Z, ofstream& outFile) { //read in the info given, if i reach @@ line without finding "@Owner", discard add. //scan thru array and see if any empty spots (email=#) //add item to first empty array position int checkstat=0; //for success/failure method for(int count=0; count<100; count++) { if(SList[count].Email == "#") { SList[count].Email = E; SList[count].Name = N; SList[count].phoneNum = pN; SList[count].Address1 = A1; SList[count].Address2 = A2; SList[count].City = C; SList[count].areaCode = aC; SList[count].State = S; SList[count].Zip = Z; SList[count].Other = O; checkstat=1; break; } } outFile << "add student" << endl; if (checkstat==0) outFile << "Failure" << endl; else outFile << "Success" << endl; }//end add student Manage::Manage() { string Command; //reads in the name of item part before we read in teh actual data, eg "@Name:" string Value; //actual value, eg Solomon Gifford int IntValue, areaCode; //ints for reading the phone number as an int int temp=0, temp2=0; //for converting phone number into specified format int counter=0; //counter for while loop ifstream inFile; //input file stream object, then input file opened inFile.open("students.data"); //initialize all values of student info to "#" for deleting function later on and printing for (int count=0; count < 100; count++) { SList[count].Email = "#"; SList[count].Name = "#"; SList[count].phoneNum = 0; SList[count].Address1 = "#"; SList[count].Address2 = "#"; SList[count].City = "#"; SList[count].areaCode = 0; SList[count].State = "#"; SList[count].Zip = 0; SList[count].Other = "#"; } counter=0; //next we will be reading in the command and then if there is a value we will read that in //and store it into the array getline(inFile, Command, '\n'); while (inFile && (counter <100)) { if (Command == "@Name:") { getline(inFile, Value, '\n'); //read in name and store to class SList[counter].Name = Value; } else if (Command == "@Phone Number:") { inFile.ignore(INT_MAX, '('); inFile >> areaCode; inFile.ignore(INT_MAX, ' '); inFile >> IntValue; IntValue = IntValue*10000; inFile.ignore(INT_MAX, '-'); inFile >> temp; IntValue = IntValue+temp; inFile.ignore(INT_MAX, '\n'); SList[counter].areaCode = areaCode; SList[counter].phoneNum = IntValue; } else if (Command == "@E-mail:") { getline(inFile, Value, '\n'); SList[counter].Email = Value; if (Value.find('@') == std::string::npos){ counter++; SList[counter].Email = "#"; break; } } else if (Command == "@Address Line 1:") { getline(inFile, Value, '\n'); SList[counter].Address1 = Value; } else if (Command == "@Address Line 2:") { getline(inFile, Value, '\n'); SList[counter].Address2 = Value; } else if (Command == "@City:") { getline(inFile, Value, '\n'); SList[counter].City = Value; } else if (Command == "@State:") { getline(inFile, Value, '\n'); SList[counter].State = Value; } else if (Command == "@Zipcode:") { inFile >> IntValue; SList[counter].Zip = IntValue; inFile.ignore(INT_MAX, '\n'); } else if (Command == "@Other:") { getline(inFile, Value, '\n'); SList[counter].Other = Value; } else if (Command == "@@") { inFile.ignore(INT_MAX, '\n'); counter++; } else { inFile.ignore(INT_MAX, '\n'); } getline(inFile, Command, '\n'); }//end of while loop inFile.close(); //close students file ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// //now read in items file the same way as students. read in //the command, then value and then store it in the items array //declare input file stream for items and open items file ifstream inFile2; inFile2.open("items.data"); //variables for reading in items string I="#", MT="#", B="#", Ow="#", Av="#"; int P=0; //initialize all values of email to "#" for deleting function later on for (int count=0; count < 100; count++) { IList[count].Owner = "#"; IList[count].Item = "#"; IList[count].Price = 0; IList[count].By = "#"; IList[count].Available = "#"; IList[count].Type = "#"; } counter=0; getline(inFile2, Command, '\n'); while (inFile2 && (counter <100)) { if (Command == "@Item:") { getline(inFile2, Value, '\n'); //read in item and store to class I = Value; } else if (Command == "@Price:") { inFile2.ignore(INT_MAX, '$'); inFile2 >> temp; temp = temp*100; inFile2.ignore(INT_MAX, '.'); inFile2 >> temp2; P = temp+temp2; inFile2.ignore(INT_MAX, '\n'); } else if (Command == "@Owner:") { getline(inFile2, Value, '\n'); Ow = Value; if (Value.find('@') == std::string::npos){ counter++; Ow = "#"; break; } } else if (Command == "@Media Type:") { getline(inFile2, Value, '\n'); MT = Value; } else if (Command == "@by:") { getline(inFile2, Value, '\n'); B = Value; } else if (Command == "@Availability:") { getline(inFile2, Value, '\n'); Av = Value; } else if (Command == "@@") { inFile2.ignore(INT_MAX, '\n'); counter++; } else { inFile2.ignore(INT_MAX, '\n'); } //checks here to c if a student with that email exists for (int count=0; count<100; count++) { if(SList[count].Email == Ow) { IList[counter].Item = I; IList[counter].Price = P; IList[counter].Owner = Ow; IList[counter].Type = MT; IList[counter].By = B; IList[counter].Available = Av; break; } } getline(inFile2, Command, '\n'); }//end of while loop inFile2.close(); //close items file }//end manage students ///////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////// FUNCTIONS //////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// int main () { Manage List; //calls class 3 //declare file stream 3 and opens comands file for parsing ifstream inFile3; inFile3.open("commands.data"); //declare output file stream and then output file is opened ofstream outFile; outFile.open("output.data"); //variables for adding items string I="#", MT="#", B="#", Ow="#", Av="#"; int P=0; //variables for adding student string N="#", E="#", A1="#", A2="#", C="#", S="#", O="#"; int aC=0, pN=0, Z=0; string Com, Com2; //com reads in the first word of the command....com2 reads the 2nd string Command; //command reads teh first int temp=0, temp2=0; //temp and temp2 are for converting the price and phone numbers int Check=0; //check is for checking if the email exists in the arrays char Letter; string part2="#"; //from here on, we simply read in the commands and call the appropriate member //some extra input is done for adding itmes and students. those values are then passed //to the appropriate member inFile3 >> Com; while (inFile3 && (Com != "quit")) { if (Com == "print") { inFile3 >> Com2; if (Com2 == "students") List.PrintStudents(outFile); else if (Com2 == "items") List.PrintItems(outFile); else List.PrintSpecific(outFile, Com2); } else if (Com == "add") { inFile3 >> Com2; inFile3.ignore(INT_MAX, '\n'); if(Com2 == "item") { getline(inFile3, Command, '\n'); while (Command != "@@") { if (Command == "@Item:") { getline(inFile3, I, '\n'); } else if (Command == "@Media Type:") { getline(inFile3, MT, '\n'); } else if (Command == "@by:") { getline(inFile3, B, '\n'); } else if (Command == "@Price:") { inFile3.ignore(INT_MAX, '$'); inFile3 >> temp; temp = temp*100; inFile3.ignore(INT_MAX, '.'); inFile3 >> temp2; P = temp+temp2; inFile3.ignore(INT_MAX, '\n'); } else if (Command == "@Availability:") { getline(inFile3, Av, '\n'); } else if (Command == "@Owner:") { getline(inFile3, Ow, '\n'); if (Ow.find('@') != std::string::npos){ //set check =1 for checkin if there is an email Check=1; } } getline(inFile3, Command, '\n'); } //above: read in the info given, if i reach @@ line without finding an email, discard add. if (Check =1) List.AddItem(I, MT, B, Ow, Av, P, outFile); //this resets the variables to nothing I="#", MT="#", B="#", Ow="#", Av="#", P=0; } else if (Com2 == "student") { getline(inFile3, Command, '\n'); while (Command != "@@") { if (Command == "@Name:") { getline(inFile3, N, '\n'); } else if (Command == "@Phone Number:") { inFile3.ignore(INT_MAX, '('); inFile3 >> aC; inFile3.ignore(INT_MAX, ' '); inFile3 >> temp; temp = temp*10000; inFile3.ignore(INT_MAX, '-'); inFile3 >> temp2; temp = temp+temp2; inFile3.ignore(INT_MAX, '\n'); pN = temp; } else if (Command == "@E-mail:") { getline(inFile3, E, '\n'); if (E.find('@') != std::string::npos){ //set check =1 for checkin if there is an email Check=1; } } else if (Command == "@Address Line 1:") { getline(inFile3, A1, '\n'); } else if (Command == "@Address Line 2:") { getline(inFile3, A2, '\n'); } else if (Command == "@City:") { getline(inFile3, C, '\n'); } else if (Command == "@State:") { getline(inFile3, S, '\n'); } else if (Command == "@Zipcode:") { inFile3 >> Z; inFile3.ignore(INT_MAX, '\n'); } else if (Command == "@Other:") { getline(inFile3, O, '\n'); } getline(inFile3, Command, '\n'); } //read in the info given, if i reach @@ line without finding an email, discard add. if (Check =1) List.AddStudent(N, E, A1, A2, C, S, O, pN, aC, Z, outFile); //this resets the other variables to nothing N="#", E="#", A1="#", A2="#", C="#", S="#", O="#", aC=0, pN=0, Z=0; } }//end if add else if (Com == "delete") { inFile3 >> Com2; List.Delete(outFile, Com2); } else inFile3.ignore(INT_MAX, '\n'); //ignore line and go to next command inFile3.ignore(INT_MAX, '\n'); inFile3 >> Com; Check=0; }//end of while outFile << "quit"; inFile3.close(); return 0; }//end of main