第一范文网 - 专业文章范例文档资料分享平台

C primer plus(第6版)中文版编程练习答案第15章

来源:用户分享 时间:2025/5/20 19:56:31 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

channel = maxchannel; }

void Tv::settings()const { cout << \ if (state == On) { cout << \ cout << \ cout << \ cout << \ } }

//use_tv.cpp #include \int main() { Tv s42; Remote grey; grey.mode_show(); cout << \ s42.settings(); s42.onoff(); s42.chanup(); cout << \ s42.settings(); s42.set_rmode(grey); grey.set_chan(s42, 10); grey.volup(s42); grey.volup(s42); cout << \ s42.settings(); Tv s58(Tv::On); s58.set_mode(); grey.set_chan(s58, 28); cout << \ s58.settings(); s58.set_rmode(grey); system(\ return 0; }

2、

//exc_mean.h

#ifndef EXC_MEAN_H_ #define EXC_MEAN_H_ #include #include #include #include using namespace std;

class bad_hmean :public logic_error {

private: string name; public: explicit bad_hmean(const string &n = \ string mesg(); virtual ~bad_hmean()throw(){} };

bad_hmean::bad_hmean(const string &n, const string &s) :name(n), logic_error(s) { }

inline string bad_hmean::mesg() { return \}

class bad_gmean :public logic_error {

private: string name; public: explicit bad_gmean(const string &n = \ string mesg(); virtual ~bad_gmean()throw(){} };

bad_gmean::bad_gmean(const string &n, const string &s) :name(n), logic_error(s) {

}

inline string bad_gmean::mesg() { return \}

#endif //error.cpp

#include \

double hmean(double a, double b); double gmean(double a, double b);

int main() { double x, y, z; cout << \ while (cin >> x >> y) { try{ z = hmean(x, y); cout << \ << \ cout << \ << \ cout << \ } catch (bad_hmean &bg) { cout << bg.what(); cout << \ cout << \ continue; } catch (bad_gmean &hg) { cout << hg.what(); cout << \ cout << \ break; } } cout << \

system(\ return 0; }

double hmean(double a, double b) { if (a == -b) throw bad_hmean(); return 2.0*a*b / (a + b); }

double gmean(double a, double b) { if (a < 0 || b < 0) throw bad_gmean(); return sqrt(a*b); }

3、

//exc_mean.h

#ifndef EXC_MEAN_H_ #define EXC_MEAN_H_ #include #include #include #include using namespace std;

class bad_hmean :public logic_error {

private: string name; public: double v1; double v2; explicit bad_hmean(double a = 0, double b = 0, const string &s = \ void mesg(); virtual ~bad_hmean()throw(){} };

bad_hmean::bad_hmean(double a, double b, const string &s) :v1(a), v2(b), logic_error(s) {

C primer plus(第6版)中文版编程练习答案第15章.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5g4r75djo34n25q6ny0j2r4yi9c8on003tk_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top