



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Larry Caretto Computer Science 106
2
3
4
5
6
7
8
9
int getValidInt( int xMin, int xMax, string name );
int year = getValidInt( 1901, 2000,
“year from the twentieth century” );
10
11
12
Larry Caretto Computer Science 106
20
21
22
bool leap( int year ) { if ( year % 4 != 0 ) return false; else if ( year % 400 == 0 ) return true; else if ( year % 100 == 0 ) return false; else return true; }
Header
Body
Name
Type
Argu- ment List (^) Multiple returns
23
bool leap ( year ); // prototype
int main() // examples of use
{ cout << “Enter a year: “;
int y; cin >> y; bool cond = leap( y ); if ( leap( y ) ) if ( leap( y ) && month == 2 )
24
25
// prototype int x2(int& x); // example of use int y = 5; cout << x2( y ) << “ “ << y //function int x2( int& x) { x = 2 * x; return x; } // output: 10 10
// prototype int x2(int x); // example of use int y = 5; cout << x2( y ) << “ “ << y; //function int x2( int x) { x = 2 * x; return x; } // output: 10 5
26
27
28
29
int getMaxDays( int month, int year );
int mIn = 2, yIn = 2004;
int maxDays = getMaxDays( mIn, yIn );
30