Unformatted text preview:

MAIN Driver sample cpp sample test program starter for Date class include iostream include date h using namespace std int main Date d1 Date d2 12 1 2000 should init to 4 10 1992 should default to 1 1 2000 display dates to the screen cout nDate d1 is d1 Show cout nDate d2 is d2 Show cout Now comparing d1 to d2 n cout d1 Compare d2 cout nDate d1 after increment is d1 Increment 335 d1 Show cout nComparing d1 and d2 again n cout d1 Compare d2 endl cout endl d1 Input cout nDate d1 is d1 Show d1 SetFormat L cout nDate d1 is d1 Show d1 SetFormat T cout nDate d1 is d1 Show Allow user to enter a date for d1 change format of d1 to Long format print d1 should show now in long format change format of d1 to Long format and so on Add your own tests to fully test the class functionality END MAIN H include string class Date public Date int m 1 int d 1 int y 2000 constructor bool SetFormat char sets the format for the output bool Set int int int sets the variables for the class void GetMonth const returns month void GetDay const return day void GetYear const returns year void Show const displays information on the screen void Increment int increments number of days based on whats passed in void Input takes input from user int Compare const Date d compares two dates calling object anf onj passed in private int month int day int year char format for the charactor representing the format std string Array 12 stores the values for 12 months bool ValidateDate int int int const validates input END H CPP include iostream include string specifically so i can use the string array include iomanip for the use of setw and other manipulators include date h if m 1 m 12 IfElse sets defaults when bad data using namespace std constructor Date Date int m int d int y Set 1 1 2000 else if d 1 d 31 Set 1 1 2000 else if year 1 Set 1 1 2000 Set m d y sets good data This allows me to increment the date by the amount of days passed in void Date Increment int incDays for int i 0 i incDays i if ValidateDate month day year Set month day year else if ValidateDate month 1 year Set month 1 year else if ValidateDate 1 1 year Set 1 1 year compares two dates int Date Compare const Date d 1 caller comes before calling obj parameter 0 caller is equal to calling obj parameter 1 calling obj parameter comes before caller if year d year else if year d year else if month d month else if month d month else if day d day else if day d day return 1 return 1 return 1 return 1 return 1 return 1 return 0 else get input from a user void Date Input bool valid false string msg do keep asking until a valid input cout Enter a date mm dd yyyy cin month cin ignore 1 ignores the char cin day cin ignore 1 ignores another char cin year if ValidateDate month day year valid true else msg Invalid date range n cout msg while valid check if user input valid info INCLUDING LEAP YEAR bool Date ValidateDate int month int day int year const bool valid false if month 1 month 3 month 5 month 7 month 8 month 10 month 12 if day 1 day 31 valid true if month 4 month 6 month 9 month 11 if day 1 day 30 valid true if month 2 if day 1 day 28 valid true if day 29 if year 4 0 year 100 0 year 400 valid true Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec cout Array month 1 day year endl break year 2digit year 2digit 100 gets the last 2 digits of cout setw 2 setfill 0 month setw 2 setfill 0 day setw 2 setfill 0 year 2digit endl cout month day year endl break bool Date Set int m int d int y bool flag true return false if invalid data 0 return valid void Date Show const string Array int year 2digit year switch format case L case T the year break case D default if m 1 m 12 flag false if d 1 d 31 flag false if year 1 flag false if ValidateDate m d y day d month m year y flag true return flag formats the date to be displayed bool Date SetFormat char c bool flag true switch toupper c case L format L break case T case D default format T break format D break format D flag false break return flag END CPP


View Full Document

FSU COP 3330 - Notes

Download Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?