//////////////////////////////////////////////////---------------- // CS1704_PROJ_002 - SPRING_2004 - MULTIMEDIA |//////||\\\\\\| // |/////\||/\\\\\| // Programmer: Spencer Rinehart ||---ANUBIS---|| // OS: Windows XP |\\\\\/||\/////| // System: Pentium IV 3.2GHz 1024MB RAM |\\\\\\||//////| // Compiler: Visual C++ 6.0 ---------------- // Last modified: 02-23-04 // // Purpose // To represent a multimedia library where students can be // created and destroyed and may include their multimedia in the // library for other students to see. #include #include #include #include using namespace std; /////////////////////////////////////////////////////////// student // Represents a student class student { public: student(); bool print(ostream &out); bool set(string pname, string pphone, string pemail, string pstreet, string papt, string pcity, string pstate, string pzip, string pother); string get_email() const {return email;} bool isset() const {return filled;} bool unset(); private: bool filled; string name, phone, email, street, apt, city, state, zip, other; }; /////////////////////////////////////////////////////////// item // Represents an item class item { public: item(); bool print(ostream &out, bool print_email); bool set(string pname, string ptype, string pauthor, string powner, string pprice, string pavailability); string get_owner() const {return owner;} bool isset() const {return filled;} bool unset(); private: bool filled; string name, type, author, owner, price, availability; }; /////////////////////////////////////////////////////////// library // Represents a multimedia library with students and items class library { public: library(string i_students, string i_items, string o_outp); bool print_items(ostream &out); bool print_students(ostream &out); bool print_student(ostream &out, string email); bool add_student(string name, string phone, string email, string street, string apt, string city, string state, string zip, string other); bool add_item(string name, string type, string author, string owner, string price, string availability); bool delete_student(string email); private: student students[100]; item items[100]; ifstream stu, ite; ofstream o_out; }; student::student() { filled=false; } //////////////////////////////////////////////////////////////// student::print // Prints the students information to the provided stream // // Parameters: // out - stream to print to // // Pre: Student must be set and output stream must be opened // // Post: Students data will be outputted // // Returns: true on success, false on failure // // Called by: library::print_student, library::print_students // Calls: bool student::print(ostream &out) { if(!filled) { return false; } if(name!="") { out<<"Name:\n\t"< bool student::set(string pname, string pphone, string pemail, string pstreet, string papt, string pcity, string pstate, string pzip, string pother) { if(pemail=="") { return false; } //cout<<"Add ["< // // Pre: // // Post: Student will be unset // // Returns: true on success, false on failure // // Called by: library::delete_student // Calls: bool student::unset() { //cout<<"delete ["< bool item::print(ostream &out, bool print_email) { if(!filled) { return false; } if(name!="") { out<<"Item:\n\t"< bool item::set(string pname, string ptype, string pauthor, string powner, string pprice, string pavailability) { if(powner=="") { return false; } name=pname; type=ptype; author=pauthor; owner=powner; if(pprice[0]=='$') { for(int x=1;x // // Post: Item will be emptied // // Returns: true on success, false on failure // // Called by: library::delete_student // Calls: bool item::unset() { name=type=author=owner=price=availability=""; filled=false; return true; } library::library(string i_students, string i_items, string o_outp) { string line, name, phone, email, street, apt, city, state, zip, other, item, type, author, owner, price, availability; ite.open(i_items.c_str()); stu.open(i_students.c_str()); o_out.open(o_outp.c_str(), ios::app); assert(ite&&stu&&o_out); while(stu) { getline(stu, line); if(line[0]=='@') { line=line.substr(1); if(line=="@") { add_student(name, phone, email, street, apt, city, state, zip, other); name=phone=email=street=apt=city=state=zip=other=""; } if(line=="Name:") { getline(stu, name); } if(line=="Phone Number:") { getline(stu, phone); } if(line=="E-mail:") { getline(stu, email); } if(line=="Address Line 1:") { getline(stu, street); } if(line=="Address Line 2:") { getline(stu, apt); } if(line=="City:") { getline(stu, city); } if(line=="State:") { getline(stu, state); } if(line=="Zipcode:") { getline(stu, zip); } if(line=="Other:") { getline(stu, other); } } } while(ite) { getline(ite, line); if(line[0]=='@') { line=line.substr(1); if(line=="@") { add_item(item, type, author, owner, price, availability); item=type=author=owner=price=availability=""; } if(line=="Item:") { getline(ite, item); } if(line=="Media Type:") { getline(ite, type); } if(line=="by:") { getline(ite, author); } if(line=="Owner:") { getline(ite, owner); } if(line=="Price:") { getline(ite, price); } if(line=="Availability:") { getline(ite, availability); } } } } ///////////////////////////////////////////////////////////library::print_items // Prints all of the set items in the library // // Parameters: // out - stream to print to // // Pre: // // Post: All of the items will be outputted with email addresses // // Returns: true on success, false on failure // // Called by: main // Calls: item::print, item::isset bool library::print_items(ostream &out) { for(int x=0;x<100;x++) { if(items[x].isset()) { items[x].print(out, true); } } return true; } ////////////////////////////////////////////////////////library::print_students // Prints all of the set students in the library // // Parameters: // out - stream to print to // // Pre: // // Post: All of the students will be outputted with no items outputted // // Returns: true on success, false on failure // // Called by: main // Calls: student::print, student::isset bool library::print_students(ostream &out) { for(int x=0;x<100;x++) { if(students[x].isset()) { students[x].print(out); } } return true; } /////////////////////////////////////////////////////////library::print_student // Prints a student with all of his items // // Parameters: // out - stream to print to // email - email address of student to print // // Pre: student is set and output stream is opened // // Post: Student is outputted along with his items // // Returns: true on success, false on failure // // Called by: main // Calls: student::print, item::print, student::isset, item::isset, // student::get_email bool library::print_student(ostream &out, string email) { for(int x=0;x<100;x++) { if(students[x].isset()&&students[x].get_email()==email) { students[x].print(out); for(int y=0;y<100;y++) { if(items[y].get_owner()==email) { items[y].print(out, false); } } return true; } } return false; } ///////////////////////////////////////////////////////////library::add_student // Adds a student to the library // // Parameters: // name, phone, email, address, and other info for student // // Pre: email is set // // Post: Student will be added to library // // Returns: true on success, false on failure // // Called by: main // Calls: student::isset, student::set bool library::add_student(string name, string phone, string email, string street, string apt, string city, string state, string zip, string other) { //cout<<"?Add ["< // // Post: Student will be removed from library along with his items // // Returns: true on success, false on failure // // Called by: main // Calls: student::isset, student::get_email, student::unset, // item::isset, item::get_owner, item::unset bool library::delete_student(string email) { for(int x=0;x<100;x++) { if(students[x].isset()&&students[x].get_email()==email) { students[x].unset(); for(int y=0;y<100;y++) { if(items[y].isset()&&items[y].get_owner()==email) { items[y].unset(); } } return true; } } return false; } int main() { ifstream in_in("commands.data"); ofstream out_out("output.data", ios::app); library lib("students.data", "items.data", "output.data"); string line, line2, command, next, name, phone, email, street, apt, city, state, zip, other, item, type, author, owner, price, availability; assert(in_in&&out_out); while(in_in) { getline(in_in, line); istringstream s_in(line); out_out<>command; if(command=="print") { s_in>>next; if(next=="students") { lib.print_students(out_out); } else if(next=="items") { lib.print_items(out_out); } else { if(!lib.print_student(out_out, next)) { out_out<>next; if(next=="student") { name=phone=email=street=apt=city=state=zip=other=line2=""; while(line2!="@") { getline(in_in, line2); line2=line2.substr(1); //cout<<"*("<>email; out_out<<(lib.delete_student(email)?"Success\n":"Failure\n"); } if(command=="quit") { in_in.close(); out_out.close(); return 0; } getline(in_in, line); } return 0; } //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. //Spencer Rinehart