chapter15test3
来源:互联网 发布:漫步者淘宝旗舰店 编辑:程序博客网 时间:2024/05/20 08:01
mean.h
#include<iostream>
#include<stdexcept>
class base :public std::logic_error
{
private:
double x; double y;
public:
base(double a = 0, double b = 0) :x(a), y(b),logic_error(0){}
double xr(){ return x; }
double yr(){ return y; }
};
class bad_hmean:public base
{
public:
bad_hmean(double a,double b) :base(a,b){}
void what();
};
inline void bad_hmean::what()
{
std::cout << "You can't process Hmean() with x= " << xr() << ",y= " << yr() << std::endl;
}
class bad_gmean :public base
{
public:
bad_gmean(double a = 0, double b = 0) :base(a,b){}
void what();
};
inline void bad_gmean::what()
{
std::cout << "You can't process Gmean() with x= " << xr() << ",y= " << yr() << std::endl;
}
user.cpp
#include<iostream>
#include<cmath>
#include"mean.h"
using namespace std;
double hmean(double a, double b);
double gmean(double a, double b);
int main()
{
double x, y, z;
cout << "Enter two numbaers :\n";
while (cin >> x >> y)
{
try{z = hmean(x, y);
cout << "Hmean(" << x << "," << y << ")=" << z << endl;
cout << "Gmean(" << x << "," << y << ")=" << gmean(x,y) << endl;
}
catch(bad_hmean &h)
{
h.what();
break;
}
catch (bad_gmean &g)
{
g.what();
break;
}
}
cout << "Finished .\n";
}
double hmean(double a, double b)
{
if (a != -b)
return 2.0*a*b / (a + b);
else
throw bad_hmean(a,b);
}
double gmean(double a, double b)
{
if (a > 0 && b > 0)
return sqrt(a*b);
else
throw bad_gmean(a, b);
}
- chapter15test3
- GIT学习链接
- java下载文件名中带有中文字符乱码的处理
- Android环境在C代码中使用logcat获取log
- Hyper-V 高可用性 (添加及配置群集)
- Android onTouch事件与手势操作
- chapter15test3
- 97.Interleaving String (二维动态规划,没想明白)
- GIT学习链接
- Java学习篇之---Mysql中varchar类型总结
- Mysql:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
- 第一个技术
- androidのPULL方式解析XML
- java简单抓取网页源代码
- expected unqualified-id before numeric constant