solve the following problem...

Slides:



Advertisements
Similar presentations
Line Efficiency     Percentage Month Today’s Date
Advertisements

Chubaka Producciones Presenta :.
HOW TO MAKE A CLIMATE GRAPH CLIMATE GRAPHING ASSIGNMENT PT.2.
2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
Problem Session Working in pairs of two, solve the following problem...
WORD JUMBLE. Months of the year Word in jumbled form e r r f b u y a Word in jumbled form e r r f b u y a february Click for the answer Next Question.
DATE POWER 2 INCOME JANUARY 100member X 25.00P2, FEBRUARY 200member X 25.00P5, MARCH 400member X 25.00P10, APRIL 800member.
Non Leap YearLeap Year DateDay NumberMod 7Day NumberMod 7 13-Jan Feb Mar Apr May Jun Jul
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
This is an example text TIMELINE PROJECT PLANNING DecOctSepAugJulyJuneAprilMarchFebJanMayNov 12 Months Example text Go ahead and replace it with your own.
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
Lesson 41 first second third fifth eighth ninth twelfth fifteenth twentieth twenty-first one two three five eight nine twelve fifteen twenty twenty-one.
Jan 2016 Solar Lunar Data.
Primary Longman Elect 3A Chapter 5 Asking about dates.
Unit 1 When is your birthday
Payroll Calendar Fiscal Year
Baltimore.
COSMO Priority Project ”Quantitative Precipitation Forecasts”
Q1 Jan Feb Mar ENTER TEXT HERE Notes
Dictation practice 2nd Form Ms. Micaela-Ms. Verónica.
// simple Date // guarantee initialization with constructor // provide some notational convenience struct Date {           int y, m, d;                            //
Average Monthly Temperature and Rainfall
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
13-block rotation schedule
I.E.S. Universidad Laboral
2018/2019 School Calendar July August September October November
2017 Jan Sun Mon Tue Wed Thu Fri Sat

Gantt Chart Enter Year Here Activities Jan Feb Mar Apr May Jun Jul Aug
2017/18 Payment Calendar Due Date Cut-off Day 1st of every month
Irregularities in DoRIS
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
McDonald’s Kalender 2009.
FY 2019 Close Schedule Bi-Weekly Payroll governs close schedule
PCS Day - Feedback 23th November 2016, Vienna.

Problem Gambling Clicks to Opgr.org
2300 (11PM) September 21 Blue line is meridian..
Jan Sun Mon Tue Wed Thu Fri Sat
2009 TIMELINE PROJECT PLANNING 12 Months Example text Jan Feb March
McDonald’s calendar 2007.
Electricity Cost and Use – FY 2016 and FY 2017
A Climate Study of Daily Temperature Change From the Previous Day
Irregularities in DoRIS
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
JUNE 2010 CALENDAR PROJECT PLANNING 1 Month MONDAY TUESDAY WEDNESDAY
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Value in Health Regional Issues
Text for section 1 1 Text for section 2 2 Text for section 3 3
McDonald’s calendar 2007.
PLAYMATES LEARNING CENTER CALENDAR
Reviewing Abbreviations
Budget Planning Calendar

2009 TIMELINE PROJECT PLANNING 12 Months Example text Jan Feb March
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Habitat Changes and Fish Migration
2015 January February March April May June July August September
Habitat Changes and Fish Migration
solve the following problem...
Presentation transcript:

solve the following problem... Problem Session Working in pairs of two, solve the following problem...

Problem Design a Date class to represent calender dates (e.g., May 1, 2000). Identify the function members needed to operate on Date objects; the data members needed to represent dates. Implement as much of your design as time permits. You may restrict dates to those since 1 AD.

Coding // Date.h declares a ‘bare bones’ Date class // #include directives have been omitted ... class Date { public: Date(); Date(string month, int day, int year); string Month() const; int Day() const; int Year() const; friend istream & operator>>(istream & in, Date & aDate); friend ostream & operator<<(ostream & out, const Date & aDate); private: string myMonth; // January..December int myDay, // 1..31 myYear; // 1..? };

Coding (Ct’d) // ... still in Date.h inline Date::Date() { myMonth = “January”; myDay = 1; myYear = 2000; } bool ValidDate(string month, int day, int year); inline Date::Date(string month, int day, int year) assert(ValidDate(month, day, year)); myMonth = month; myDay = day; myYear = year;

Coding (Ct’d) // ... still in Date.h inline string Date::Month() const { return myMonth; } inline int Date::Day() const return myDay; inline int Date::Year() const return myYear;

Coding (Ct’d) // ... still in Date.h inline ostream & operator<<(ostream & out, const Date & aDate) { out << aDate.myMonth << ‘ ‘ // January <space> << aDate.myDay << “, “ // 1 <comma> << aDate.myYear; // 2000 return out; // allow chaining }

Coding (Ct’d) // Date.cpp defines non-trivial Date function members. // ... #include “Date.h” // class Date bool ValidYear(int year); bool ValidMonth(string month); bool ValidDay(int day); int DaysIn(string month, int year); bool ValidDate(string month, int day, int year) { return ValidMonth(month) && ValidDay(day) && day <= DaysIn(month, year) && ValidYear(year); } bool ValidYear(int year) return year > 0;

Coding (Ct’d) // ... Date.cpp continued bool ValidMonth(string month) { return month == “January” || month == “Jan” || month == “February” || month == “Feb” || month == “March” || month == “Mar” || month == “April” || month == “Apr” || month == “May” || month == “June” || month == “Jun” || month == “July” || month == “Jul” || month == “August” || month == “Aug” || month == “September” || month == “Sep” || month == “October” || month == “Oct” || month == “November” || month == “Nov” || month == “December” || month == “Dec”; }

Coding (Ct’d) // ... Date.cpp continued bool ValidDay(int day) { return day >= 1 && day <= 31; } bool LeapYear(int year) if (year % 4 == 0) if (year % 100 == 0) if (year % 400) == 0) return true; else return false;

Coding (Ct’d) // ... Date.cpp continued int DaysIn(string month, int year) { if (month == “January” || month == “Jan”) return 31; else if (month == “February” || month == “Feb”) if (LeapYear(year)) return 29; else return 28; else if (month == “March” || month == “Mar”) return 31; else if (month == “April” || month == “Apr”) return 30; else if (month == “May”) return 31; else if (month == “June” || month == “Jun”) return 30; else if (month == “July” || month == “Jul”) return 31; else if (month == “August” || month == “Aug”) return 31; else if (month == “September” || month == “Sep”) return 30; else if (month == “October” || month == “Oct”) return 31; else if (month == “November” || month == “Nov”) return 30; else if (month == “December” || month == “Dec”) return 31; }

Coding (Ct’d) // ... Date.cpp continued istream & operator>>(istream & in, Date & aDate) { string month; int day, year; char ch; in >> month >> day; // January 1 in.get(ch); // either comma or space in >> year; // 2000 if (ValidDate(month, day, year)) // if date is ok aDate = Date(month, day, year); // passback values else // otherwise in.setstate(ios::failbit); // set stream’s failbit return in; // allow chaining }