208 Day 12 Functions2

208 Day 12 Functions2 - 4002-208 Intro. to Prog. [in C++]...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 4002-208 Intro. to Prog. [in C++] Day 12 More on Functions Objectives • Models of function uses • Documentation 4002-208 2 Model of a function … 0 or more parameters Named block of code 0 or 1 return value 4002-208 3 Output Functions … 1 or more parameters Print information No return value 4002-208 4 Print age void printAge( int age ) { cout << “Age is “ << age << endl; } 4002-208 5 Input Function No parameters Read input 1 return value 4002-208 6 Read age int readAge( void ) { int age = 0; cout << “Enter age: “; cin >> age; while ( age <= 0 ) { cout << “Invalid age – must be > 0” << endl; cout << “Enter age: “; cin >> age; } return age; } //end readAge 4002-208 7 Processing function … 1 or more parameters Compute something 1 return value 4002-208 8 Calculate Interest double calcInterest( double amt, double intRate, double months ) { double monthIntRate = (intRate / 100.0) / 12.0; double interest = amt * monthIntRate * months; return interest; } //end calcInterest 4002-208 9 Function Documentation //--------------------------------------------//Name: <name of function> //Purpose: <describe what function does> //Parameter: <one line per parameter> //Return: <describe return value or none> //--------------------------------------------- 4002-208 10 calcInterest Function //----------------------------------------//Name: calcInterest //Purpose: calculate simple interest //Parameter: // amt – amount of money invested // intRate – annual interest rate as percent // months – length of period in months //Return: amount of interest for given months //----------------------------------------4002-208 11 ...
View Full Document

Page1 / 11

208 Day 12 Functions2 - 4002-208 Intro. to Prog. [in C++]...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online