



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The outline and tasks for exercise 7 in computer science 106, focusing on user-defined functions in c++. The exercise covers writing programs with user-defined functions, function headers, function bodies, function prototypes, return values, and passing variables to functions by value and reference. The tasks include using the getvalidint function and writing functions from pseudocode to compute maximum days in a month, determine if the year is a leap year, and get valid input on month, day and year.
Typology: Slides
1 / 6
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