CS 211:
Introduction to Computer Programming II
Instructor: Brian M. Dennis
Teaching Assistants:
Tom Lechner, Bin Lin, Rachel Goldsborough
http://www.cs.northwestern.edu/~bmd/cs211/

Overloaded Functions
int max(int x, int y) {
return (x <= y) ? y : x;
}
char* max(char* s1, char* s2) {
return (strcmp(s1,s2) < 0) ? s2 : s1;
}
Point max(Point p1, Point p2) {
d1 = sqrt(p1.x() * p1.x() + p1.y() * p1.y());
d2 = sqrt(p2.x() * p2.x() + p2.y() * p2.y())
return (d1 <= d2) ? p2 : p1
}

Overloaded Functions
int max(int x, int y);
char* max(char* s1, char* s2);
Point max(Point p1, Point p2);
int main(int argc, char* argv[]) {
max(100, 11);
max("Panthers", "Patriots");
max(Point(5,5), Point(0,4));
}

That’s a Wrap
Reading
4.9