c++ - Pseudocode for date function definition -


pseudocode recieved:

date& operator++(){     //add 1 d  //tomorrow, unless @ end of month     //if is_date false     //            //need change first of next month     //  set d 1     //  if m december     //            //need change next year           //    set m january     //    increment y     //  else     //    increment m     return *this; 

}

my interpretation:

date& date::operator++(){      if (is_date==false){          m=m+1;          d=1;      }      if (m==dec && d==29){          m=jan;          y=y+1;      }      else{          m=m+1;      }      d=d+1;  } 

does ok? i'm doing hw assignment based off of stroustrups book. needed verification

let's increment 2010-03-10:

    if (is_date==false){          m=m+1;          d=1;      }  

we assume is_date true, no action happens.

    if (m==dec && d==29){          m=jan;          y=y+1;      }  

m not dec , d not 29, no action happens.

    else{          m=m+1;      }  

wait! m incremented.

    d=d+1; 

so d.

we have 2010-04-11 - not wanted.

look again @ pseudocode - first thing happens adding day. else only happens if is_date false. is_date should not interpreted static value, instead should implemented check if date valid (e.g. have 32. day after incrementation). if new date isn't valid month and/or year incremented.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -