Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

i need a little help

killer84killer84 Member Posts: 2
i have an assignment due. the prof. supplied us with a couple functions that we have to use. the assignment is to convert a date (ie July 21, 2001) to the day number (ie day 214), and vice-versa.

we need to write 2 functions. 1 to convert to day number, just a regular function. the second function to convert a day number to a date, because it is going to return 2 values, call by reference is required.

however, that is not where my question lies. it is in the functions he supplies to us, one of htem makes little sense to me. below are the functions that are supplied:

QUOTE
// returns true if the year is a leap year
bool year_is_leap (int year) {

return ((year % 4) == 0) &&
(((year % 100) != 0) || ((year % 400) == 0));
}


int days_in_year (int year) {

if (year_is_leap(year)) {
return 366;
} else {
return 365;
}

}


// January = month 1, February = month 2, etc.
int days_in_month (int month, int year) {

const int days_table [12] =
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

// look after the special case
if ((month == 2) && year_is_leap(year)) {
return 29;
}

return days_table[month - 1];

}


in total there are 3 functions. the first is used to decide if the given year is a leap year, it returns true if it is a leap year. the second funcion is used to calculate the number of days. it uses the first function to decide whether there is 365 or 366 days in the year.

the third function is the one i don't get. i understand that the numbers are the days in the month, but how does the computer deal with this table? what happens when this function is called?

any help would be greatly appreciated.


just in case you want to know:

the only things we have learned are: while loops, if's, do whiles (i don't like do whiles though), for loops, infinite loops, cin.ignore, cin.fail, cin.clear, funcitions...call by value and call by reference. that is all, so please don't explain it to me by using arrays, and all that still unknown stuff to me.

Comments

  • killer84killer84 Member Posts: 2
    oh, i am also using c++. 2 months ago the only thing i knew about c++ was its name, so i have no idea if there are enourmous differences in c and c++.

    later
  • Justin BibJustin Bib USAMember Posts: 0

    _ < http://forcoder.org /> free ebooks and video tutorials about | PL/SQL Python Swift C C# Visual Basic Assembly Scratch Perl Java Go R Delphi PHP Objective-C C++ JavaScript Ruby Visual Basic .NET MATLAB Prolog Rust Kotlin Julia Scheme Crystal Dart Lisp SAS Lua Erlang Apex Logo ML ABAP Scala LabVIEW COBOL Bash Awk VBScript Alice F# Transact-SQL Ada D FoxPro Hack Fortran Clojure | _______

Sign In or Register to comment.