Do you have a question, or just showing code?
Ray
--- Robert Ryan <[EMAIL PROTECTED]> wrote:
> I am still working on this code. I have had to make
> other files: Chono.h, Chono.cpp and season.cpp
> #include "Hw4#4.cpp"
> using namespace Chrono;
> int main()
> {
> cout << "season()" ;
> Date d1(2008, Date::mar, 20);
> cout << d1.season() << endl;
> cout << "\n";
> }
>
>
> Robert Ryan <[EMAIL PROTECTED]> wrote:
> //Change the Date class in the textbook by adding a
> function season()
> //which returns a string depending on the month;
> e.g.,
> // Date d1(2008, Month::mar, 20);
> // cout << d1.season() << endl;
> //should print spring. Use the following
> specification:
> // mar-may spring
> // jun-aug summer
> // sep-nov fall
> // dec-feb winter
> //and also write a main function which tests
> season() on 12 dates,
> //one from each month. Name your program season.cpp.
> #include<iostream>
> #include "Chrono.h"
> using namespace std;
> namespace Chrono {
> Date::Date(Year yy, Month mm, int dd)
> :y(yy), m(mm), d(dd){
> if(check(yy,mm,dd))throw Invalid();
> }
> Date::Date(){}
> void Date::add_day(int n){
> //...
> }
> void Date::add_month(int n){
> //...
> }
> void Date::add_year(int n){
> if(m==feb && d==29 && !leapyear(y+n)){
> m=mar;
> d=1;
> }
> y+=n;
> }
> bool is_date(int y, Date::Month m, int d){
> if(d<=0)return false;
> int days_in_month=30;
> switch(m){
> case Date::jan: case Date::mar: case Date::may:
> case Date::jul: case Date::aug: case Date::oct:
> case Date::dec:
> {
> days_in_month=31;
> break;
> }
> case Date::feb:
> {
> days_in_month=(leapyear(y))?29:28;
> break;
> } default:
> days_in_month=30;
> }
> if(days_in_month<d)return false;
> //return true;
>
> }
> ostream& operator<<(ostream & os, Date& d){
> return
>
os<<'('<<d.year()<<','<<d.month()<<','<<d.day()<<')';
> }
> istream& operator>>(istream & is, Date& dd){
> int y, d;
> //Date::Month m;
> int m;
> char ch1, ch2, ch3, ch4;
> is >> ch1 >> y >> ch2 >> m >> ch3 >> d >> ch4;
> if(!is)return is;
> if(ch1!='(' || ch2!=',' || ch3!=',' || ch4!=')'){
> is.clear(ios_base::failbit);
> return is;
> }
> dd = Date(y,Date::Month(m),d);
> return is;
> }
> //enum Day{sunday, monday, tuesday, wednesday,
> thursday,
> //friday, saturday};
> } //Chrono
> void season()
> {
> enum S_code { SPRING, SUMMER, FALL, WINTER};
> {
> switch (s){
> case SPRING:
> cout << "spring";
> break;
> case SUMMER:
> cout << "summer";
> break;
> case FALL:
> cout << "fall";
> break;
> case WINTER:
> cout << "winter";
> break;
> default:
> cout << "Not a season" << endl;
> }
> }
>
> int main()
> {
> cout << "season()" ;
> }
>
>
>
> $ g++ Hw4#4.cpp
> .cpp:24: parse error before `yy'
> .cpp:67: confused by earlier errors, bailing out
>
> ---------------------------------
> Be a better friend, newshound, and know-it-all with
> Yahoo! Mobile. Try it now.
> ----------
>
> // file Chromo.h
> namespace Chrono {
> class Date {
>
> public:
> enum Month {
> jan=1, feb, mar, apr, may, jun, jul, aug, sep, oct,
> nov, dec
> };
>
> class Invalid { };
>
> Date(int y, Month m, int d);
> Date();
> // the default copy operations are fine
>
> // non-modifying operations
> int day() const {return d; }
> Month month() const {return m; }
> int year() const {return y; }
>
> // modifying operations
> //void add_year(int n);
> void add_day(int n);
> void add_month(int n);
> void add_year(int n);
> private:
> int y;
> Month m;
> int d;
>
> };
>
> bool is_date(int y, Date::Month m, int d);
>
> // true if y is a leap year
> bool leapyear(int y);
>
> bool operator==(const Date& a, const Date& b);
> bool operator!=(const Date& a, const Date& b);
>
> //ostream& operator << (ostream& os, const Date& d);
> //istream& operator >> (istream& is, Date& dd);
> }
>
> [Non-text portions of this message have been
> removed]
>
>
>
>
>
>
> ---------------------------------
> Looking for last minute shopping deals? Find them
> fast with Yahoo! Search.
>
> [Non-text portions of this message have been
> removed]
>
>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search.
http://tools.search.yahoo.com/newsearch/category.php?category=shopping