Parameters and Overloading

Parameters and Overloading - Lecture 2: Parameters and...

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

View Full Document Right Arrow Icon
Lecture 2: Parameters and Overloading CS256 – Fall 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
Outline Parameters Call by value and call by reference Overloading Default arguments Default arguments and overloading Coverage: Chapter 4 of textbook
Background image of page 2
Function definition and declaration Function declaration double f(int x, int y); Function definition double f(int x, int y) {return (x+y)/2.0); }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Parameters Call by value parameters double total (int feet, int inches) { inches = 12*feet + inches; return inches; } Call by reference parameters cout << “enter a real number as input number\n”; cin >> data; return; } Exercises swap example Self-test exercise 3 (p143)
Background image of page 4
Overloading Function overloading double average (double n1, double n2) { return (n1+n2)/2.0; } double average (double n1, double n2, double n3) { return (n1+n2+n3)/3.0; } cout << average(3.5, 2.5); cout << average(3.5, 2.5, 2.0);
Background image of page 5

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

View Full DocumentRight Arrow Icon
Function’s Signature A function’s signature is the function’s
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/18/2008 for the course CS 256 taught by Professor Dr. yang during the Fall '08 term at Cal Poly Pomona.

Page1 / 14

Parameters and Overloading - Lecture 2: Parameters and...

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

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