AverageOfSeveral

AverageOfSeveral - << endl ; cout...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> using namespace std ; double avg (double v1, double v2) { return (v1 + v2) / 2 ; } double avg (double v1, double v2, double v3) { return (v1 + v2 + v3) / 3 ; } double avg (double v1, double v2, double v3, double v4) { return (v1 + v2 + v3 + v4) / 4 ; } double avg (double v1, double v2, double v3, double v4, double v5) { return (v1 + v2 + v3 + v4 + v5) / 5 ; } int main() { cout << "Using function overloading to simplify an average function."
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &lt;&lt; endl ; cout &lt;&lt; &quot;The average of 1.3 and 2.4 is &quot; &lt;&lt; avg(1.3, 2.4) &lt;&lt; endl ; cout &lt;&lt; &quot;The average of 1.3, 2.4 and 5.6 is &quot; &lt;&lt; avg(1.3, 2.4, 5.6) &lt;&lt; endl ; cout &lt;&lt; &quot;The average of 1.3, 2.4, 5.6 and 7.8 is &quot; &lt;&lt; avg(1.3, 2.4, 5.6, 7.8) &lt;&lt; endl ; cout &lt;&lt; &quot;The average of 1.3, 2.4, 5.6, 7.8 and 9.5 is &quot; &lt;&lt; avg(1.3, 2.4, 5.6, 7.8, 9.5) &lt;&lt; endl ; }...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online