// The Designer decides upon the following data and actions (i.e. Functions) // and places the class in the file event.h #ifndef EVENT_H #define EVENT_H class event { public: event(void); // default constructor event(long, const char [],int d, int m, int y); // 5 argument constructor event(const event &); // copy constructor void keyBoardInput(void); // Assume no blanks in the desc long getSource(void) const; // return source void setSource(long); // change source void setDate(int d, int m, int y); // set day, month, year void copyTo( event & ) const; // copy invoking instance to parameter void incrementDate(void); // advance the date by ONE day You can assume 30 days in each month void print(ostream &, int dateFormat) const; // print all fields // dateFormat == 1 month/day/year // dateFormat == 2 day/month/year ~event(); // destructor - indicate the address of the variable that is leaving private: // private functions - only the implementer can use these functions void setMonth(int); void setDay(int); void setYear(int); int getMonth(void) const; int getDay(void) const; int getYear(void) const; // data long source; // id of the person scheduling the event char *desc; // description of the event int day; // day, month, and year when the event int month; // will happen int year; }; #endif //----------------------------------------drhw2.cpp (main file)-------------------------------------------------------------- // CIS 235 Revised - Homework 2 // Given the class definition for an event // -- Write the member functions for the class event // -- Write the 3 NONMEMBER functions: makeEvent, getSource, and advanceDate // -- Write a main program to test all member functions for the class and the 3 nonmember functions: makeEvent, getSource and advanceDate #include using std::ostream; #include using std::endl; using std::cin; using std::cout; #include // Needed for string functions #include "event.h" /*The implementer will write all of the member functions and place these functions in a separate file "event.cpp" The Client, i.e. User, will create the file drhw2.cpp and prototype, write, and use the following 3 functions */ event makeEvent(long, const char [], int d, int m, int y); long getSource(const event &); event advanceDate( const event &, int numberOfDays); void main()// The client will test the 3 function above along with all of the member functions { event a,b; long source; char *desc; int d, m, y; ostream x; cout << "Please input your ID " << endl; cin >> source; cout << "Please input the Description " << endl; cin >> *desc; cout << "Please input the day followed by the month followed by the year" << endl; cin >> d >> m >> y; a = makeEvent(source, desc, d, m, y); cout << "Your source is " << getSource(a) << endl; cout << "Current date: " << d << "/" << m << "/" << y << endl; b = advanceDate(a,10); cout << "Event with advanced date:\n"; b.print(x,2); event c,f; long s1,s2; int d1,d2,m1,m2,y1,y2; cout << "Testing member functions.\n"; cout << "Enter source and date of event 1:\n"; cin >> s1 >> d1 >> m1 >> y1; cout << "Enter source and date of event 2:\n"; cin >> s2 >> d2 >> m2 >> y2; c.setSource(s1); f.setSource(s2); c.setDate(d1,m1,y1); f.setDate(d2,m2,y2); c.keyBoardInput(); f.keyBoardInput(); c.print(x,1); f.print(x,1); c.copyTo(f); c.print(x,2); f.print(x,2); f.incrementDate(); c.print(x,1); f.print(x,1); system("Pause"); return; } // Client places the code for makeEvent, getSource and advanceDate here event makeEvent(long s, const char n[], int d, int m, int y) { event a(s,n,d,m,y); return a; } long getSource(const event & e) // will return the source in the parameter { long whattheboat; whattheboat = e.getSource(); return whattheboat; } event advanceDate( const event & e, int numberOfDays) { // The following function will return an event with the same source and desc // as the parameter event. The day, month, and year will reflect numberOfDays // into the future. event whatthebert(e); for(int count=0; count <= numberOfDays; count++){ whatthebert.incrementDate(); } return whatthebert; }