// Project 2 for CS 1704 Spring II 2004 // // Programmer: Mason Shea // OS: Windows XP // System: Pentium III 500, 256 MB Memory // Compiler: Visual C++ 6.0, Service Pack 4 // Last modified: February 27, 2004 // // Purpose // This program first creates an objecct of type organizer, which contains // two arrays of student and item objects, each with space for 100 of these. // After obtaining all the student and item info possible from those two input // files, the program starts to read from a command input file, and depending // on the command input, performs 6 different functions, each of which is first // echoed to the output file and then run, and in the case of adding or deleteing // students or items, "Success" or "Failure" is printed out as well. The last // three functions in the command file prints out all the students and items, and // then quits. #include #include #include "organizer.h" int main() { Organizer org; ifstream inCommandFile; inCommandFile.open("commands.data"); //open the input command file assert ( inCommandFile.is_open() ); //check with an assert ofstream outCommandFile; outCommandFile.open("output.data"); //open the output file assert ( outCommandFile.is_open() ); //check with an assert string input; int n, p, e, a1, a2, c, s, z, o; inCommandFile>>input; while ( inCommandFile ) { if(input == "add") { string type; inCommandFile>>type; //check which type of add it is string nothing; getline(inCommandFile, nothing); if(type == "student") { n = 0; p = 0; e =0; a1 = 0; a2 = 0; c = 0; s = 0; z = 0; o = 0; string in; string Name, PhoneNumber, Email, AddressLine1, AddressLine2, City, State, Other; int Zipcode; getline(inCommandFile, in); while(in != "@@") //get the student's info the same way the organizer constructor did { if(in == "@Name:") { getline(inCommandFile, Name); n++; } else if(in == "@Phone Number:") { getline(inCommandFile, PhoneNumber); p++; } else if(in == "@E-mail:") { getline(inCommandFile, Email); e++; } else if(in == "@Address Line 1:") { getline(inCommandFile, AddressLine1); a1++; } else if(in == "@Address Line 2:") { getline(inCommandFile, AddressLine2); a2++; } else if(in == "@City:") { getline(inCommandFile, City); c++; } else if(in == "@State:") { getline(inCommandFile, State); s++; } else if(in == "@Zipcode:") { string Temp; getline(inCommandFile, Other); Temp=Other; istringstream ss(Temp); ss >>Zipcode; z++; } else if(in == "@Other:") { getline(inCommandFile, Other); o++; } else { break; } getline(inCommandFile, in); } if(n == 0) { Name = "nothing"; } if(p == 0) { PhoneNumber = "nothing"; } if(e ==0) { Email = "nothing"; } if(a1 == 0) { AddressLine1 = "nothing"; } if(a2 == 0) { AddressLine2 = "nothing"; } if(c == 0) { City = "nothing"; } if(s == 0) { State = "nothing"; } if(z == 0) { Zipcode = 0; } if(o == 0) { Other = "nothing"; } Student student(Name, PhoneNumber, Email, AddressLine1, AddressLine2, City, State, Zipcode, Other); //call the constructor for the Student class outCommandFile<< "add student " << endl; //echo the command org.AddStudent(student, outCommandFile); //run that function! } else if(type == "item") //go through the get the item's data just like the organizer constructor did { string check; int i, m, b, own, pri, a; i = 0; m = 0; b = 0; own = 0; pri = 0; a = 0; string Title, MediaType, By, Owner, Availability; double Price; getline(inCommandFile, check); while(check != "@@") { if(check == "@Item:") { getline(inCommandFile, Title); i++; } else if(check == "@Media Type:") { getline(inCommandFile, MediaType); m++; } else if(check == "@by:") { getline(inCommandFile, By); b++; } else if(check == "@Owner:") { getline(inCommandFile, Owner); own++; } else if(check == "@Price:") { inCommandFile.ignore(1, '$'); inCommandFile>>Price; getline(inCommandFile, check); pri++; } else if(check == "@Availability:") { getline(inCommandFile, Availability); a++; } else { break; } getline(inCommandFile, check); } if(i == 0) { Title = "nothing"; } if(m == 0) { MediaType = "nothing"; } if(b == 0) { By = "nothing"; } if(own == 0) { Owner = "nothing"; } if(pri == 0) { Price = 0.0; } if(a == 0) { Availability = "nothing"; } Item item(Title, MediaType, By, Owner, Price, Availability); //call constructor for the Item class outCommandFile<< "add item " << endl;//echo the command org.AddItem(item, outCommandFile); //run that function! } } else if(input == "delete") { string Email; inCommandFile>>Email; outCommandFile<< "delete " << Email << endl; //echo the command org.Delete(Email, outCommandFile); //run that function! } else if(input == "print") { string kind; inCommandFile>>kind; //get which type of print needs to be performed if(kind == "students") { outCommandFile<< "print students " << endl; //echo the command org.PrintStudents(outCommandFile); //run that function!! } else if(kind == "items") { outCommandFile<< "print items " << endl; //echo the command org.PrintItems(outCommandFile); //run that function! } else { string Email; Email = kind; //get the email, whcih will be the word after print in this case outCommandFile<< "print " << Email << endl; //echo the command org.PrintEmail(Email, outCommandFile); //run that function! } } else if(input == "quit") { outCommandFile<< "quit " << endl; //echo the command } inCommandFile>>input; } inCommandFile.close(); //close all files opened in main outCommandFile.close(); return 0; }