// page166.cpp : 定义控制台应用程序的入口点。
//C++面向对象程序设计
//演示对函数名ave的重载
#include "stdafx.h"
#include <iostream>
double ave(double n1 , double n2);
//返回两个数字n1和n2的平均值
double ave (double n1 , double n2 ,double n3);
//返回三个数字n1,n2,n3的平均值
int _tmain(int argc, _TCHAR* argv[])
{
int a;
using namespace std ;// 预编译指令
//放在这里只能用于该函数的定义
//精确度不同
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(5);
cout << " The average of 2.0 ,3.0, 2.5, and 3.0 is "
<< ave (2.0 , 2.5 , 3.0) << endl ;
//确定精确度不一样
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << " The average of 4.5and 5.5 is "
<< ave(4.5 , 5.5);
cin >> a ;
return 0;
}
double ave(double n1 , double n2)
{
return ((n1 + n2)/2.0);
}
double ave (double n1 , double n2 ,double n3)
{
return ((n1 + n2 + n3)/3.0);
}