当前位置: 首页 > news >正文

网站建设开发网站wrrgbdd关键词优化如何

网站建设开发网站wrrgbdd,关键词优化如何,网站建设的报价,设计包装公司1.对Tv 和 Remote 类做如下修改: a,让它们互为友元; b.在 Remote类中添加一个状态变量成员,该成员描述遥控器是处于常规模式还是互动模式: c,在 Remote 中添加一个显示模式的方法 d.在T类中添加一个对 Remote 中新成员进行切换的方法&#xf…

1.对Tv 和 Remote 类做如下修改:
a,让它们互为友元;
b.在 Remote类中添加一个状态变量成员,该成员描述遥控器是处于常规模式还是互动模式:
c,在 Remote 中添加一个显示模式的方法
d.在T类中添加一个对 Remote 中新成员进行切换的方法,该方法应仅当 TV 处于打开状态时才能运行。
编写一个小程序来测试这些新特性。

#include <iostream>
#include "tv.h"int main()
{using std::cout;Tv s42;cout << "Initial settings for 42\" TV:\n";s42.settings();s42.onoff();s42.chanup();cout << "\nAdjusted settings for 42\" TV:\n";s42.settings();Remote grey;grey.set_chan(s42, 10);grey.volup(s42);grey.volup(s42);s42.set_status(grey);cout << "\n42\" settings after using remote:\n";s42.settings();grey.show_status();Tv s58(Tv::On);s58.set_mode();grey.set_chan(s58, 28);s58.set_status(grey);cout << "\n58\" settings:\n";s58.settings();grey.show_status();return 0;
}
#ifndef TV_H_
#define TV_H_
#include <iostream>class Remote; //先声明Remote类然后再定义, 以便编译器有足够的信息编译使用Remote类的方法;class Tv
{
public:friend class Remote;enum { Off, On };enum { MinVal, MaxVal = 20 };enum { Antenna, Cable };enum { TV, DVD };Tv(int s = Off, int mc = 125) : state(s), volume(5),maxchannel(mc), channel(2), mode(Cable), input(TV) {}void onoff() { state = (state == On) ? Off : On; }bool ison() const { return state == On; }bool volup();bool voldown();void chanup();void chandown();void set_mode() { mode = (mode == Antenna) ? Cable : Antenna; }void set_input() { input = (input == TV) ? DVD : TV; }void settings() const;void set_status(Remote &r); //对Remote类中状态成员进行切换的方法;private:int state;int volume;int maxchannel;int channel;int mode;int input;
};class Remote
{
private:int mode;int status; //状态变量成员;public:friend class Tv;enum { Convention, Interaction }; //Convention表示常规模式, Interaction表示互动模式;Remote(int m = Tv::TV, int s = Convention) : mode(m), status(s) {} //默认为常规模式;bool volup(Tv &t) { return t.volup(); }bool voldown(Tv &t) { return t.voldown(); }void onoff(Tv &t) { t.onoff(); }void chanup(Tv &t) { t.chanup(); }void chandown(Tv &t) { t.chandown(); }void set_chan(Tv &t, int c) { t.channel = c; }void set_mode(Tv &t) { t.set_mode(); }void set_input(Tv &t) { t.set_input(); }void show_status() const;
};inline void Tv::set_status(Remote &r)
{if (ison()){r.status = Remote::Convention == r.status ? Remote::Interaction : Remote::Convention;}
}inline void Remote::show_status() const
{std::cout << "Status = " << (status == Convention ? "Convention" : "Interaction") << std::endl;
}#endif
#include <iostream>
#include "tv.h"bool Tv::volup()
{if (volume < MaxVal){volume++;return true;}return false;
}bool Tv::voldown()
{if (volume > MinVal){volume--;return true;}return false;
}void Tv::chanup()
{channel = channel < maxchannel ? 1 + channel : 1;
}void Tv::chandown()
{channel = channel > 1 ? channel - 1 : maxchannel;
}void Tv::settings() const
{using std::cout;using std::endl;cout << "TV is " << (state == Off ? "Off" : "On") << endl;if (state == On){cout << "Volume setting = " << volume << endl;cout << "Channel setting = " << channel << endl;cout << "Mode = ";cout << (mode == Antenna ? "antenna" : "cable") << endl;cout << "Input = ";cout << (input == TV ? "TV" : "DVD") << endl;}
}

2.修改程序清单 15.11,使两种异常类型都是从头文件stdexcepi>提供的 logic_error 类派生出来的类让每个 what()方法都报告函数名和问题的性质。异常对象不用存储错误的参数值,而只需支持 what()方法

#include <iostream>
#include <cmath>
#include "exc_mean.h"double hmean(double a, double b);
double gmean(double a, double b);int main()
{using std::cin;using std::cout;using std::endl;double x, y, z;cout << "Enter two numbers: ";while (cin >> x >> y){try{z = hmean(x, y);cout << "Harmonic mean of " << x << " and " << y;cout << " is " << z << endl;z = gmean(x, y);cout << "Geometric mean of " << x << " and " << y;cout << " is " << z << endl;cout << "Enter next set of numbers <q to quit>: ";}catch (bad_hmean &bg){cout << bg.what(); //调用what方法打印hmean中的异常;cout << "Try again.\n";continue;}catch (bad_gmean &hg){cout << hg.what(); //调用what方法打印gmean中的异常;cout << "Sorry, you don't get to play any more.\n";break;}}cout << "Bye!\n";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 std::sqrt(a * b);
}
#ifndef EXC_MEAN_H_
#define EXC_MEAN_H_
#include <iostream>
#include <string>
#include <stdexcept>
using namespace std;class bad_hmean : public logic_error
{
public:explicit bad_hmean(const string &s = "Error in bad_hmean object\nhmean() arguments should be a != -b\n") : logic_error(s) {}
};class bad_gmean : public logic_error
{
public:explicit bad_gmean(const string &s = "Error in bad_hmean object\ngmean() arguments should be >= 0\n") : logic_error(s) {}
};#endif

3.这个练习与编程练习2相同,但异常类是从一个这样的基类派生而来的:它是从 logic_crror 派生而来的,并存储两个参数值。异常类应该有一个这样的方法:报告这些值以及函数名。程序使用一个 catch块来捕获基类异常,其中任何一种从该基类异常派生而来的异常都将导致循环结束。

#include <iostream>
#include <cmath>
#include "exc_mean.h"double hmean(double a, double b);
double gmean(double a, double b);int main()
{using std::cin;using std::cout;using std::endl;double x, y, z;cout << "Enter two numbers: ";while (cin >> x >> y){try{z = hmean(x, y);cout << "Harmonic mean of " << x << " and " << y;cout << " is " << z << endl;z = gmean(x, y);cout << "Geometric mean of " << x << " and " << y;cout << " is " << z << endl;cout << "Enter next set of numbers <q to quit>: ";}catch (mean &m) //捕获基类以及派生类的任何异常;{cout << "Sorry, you don't get to play any more.\n";break;}}cout << "Bye!\n";return 0;
}double hmean(double a, double b)
{if (a == -b){bad_hmean temp("hmean", a, b);temp.mesg();throw temp;}return 2.0 * a * b / (a + b);
}double gmean(double a, double b)
{if (a < 0 || b < 0){bad_gmean temp("gmean", a, b);temp.mesg();throw temp;}return std::sqrt(a * b);
}
#ifndef EXC_MEAN_H_
#define EXC_MEAN_H_
#include <iostream>
#include <string>
#include <stdexcept>
using namespace std;class mean : public logic_error
{
private:double v1;double v2;public:mean(const string &s = "none", double a = 0.0, double b = 0.0) : logic_error(s), v1(a), v2(b) {}const double &val1() const { return v1; }const double &val2() const { return v2; }
};class bad_hmean : public mean
{
public:bad_hmean(const string &s = "none", double a = 0.0, double b = 0.0) : mean(s, a, b) {}void mesg() const;
};inline void bad_hmean::mesg() const
{cout << "hmean(" << val1() << ", " << val2() << "):" << endl;cout << "hmean() arguments should be a != b" << endl;
}class bad_gmean : public mean
{
public:bad_gmean(const string &s = "none", double a = 0.0, double b = 0.0) : mean(s, a, b) {}void mesg() const;
};inline void bad_gmean::mesg() const
{cout << "gmean(" << val1() << ", " << val2() << "):" << endl;cout << "gmean() arguments should be >= 0" << endl;
}#endif

4.程序清单 15.16 在每个 ty 后面都使用两个 catch 块,以确保 nbad index 异常导致方法 abel_val()被调用。请修改该程序在每个 ty 块后面只使用一个 catch 块并使用 RTTI 来确保合适时调用 abel_val()

#include <iostream>
#include "sales.h"int main()
{using std::cin;using std::cout;using std::endl;double vals1[12] ={1220, 1100, 1122, 2212, 1232, 2334,2884, 2393, 3302, 2922, 3002, 3544};double vals2[12] ={12, 11, 22, 21, 32, 34,28, 29, 33, 29, 32, 35};Sales sales1(2011, vals1, 12);LabeledSales sales2("Blogstar", 2012, vals2, 12);cout << "First try block:\n";try{int i;cout << "Year = " << sales1.Year() << endl;for (i = 0; i < 12; ++i){cout << sales1[i] << ' ';if (i % 6 == 5){cout << endl;}}cout << "Year = " << sales2.Year() << endl;cout << "Label = " << sales2.Label() << endl;for (i = 0; i <= 12; ++i){cout << sales2[i] << ' ';if (i % 6 == 5){cout << endl;}}cout << "End of try block 1.\n";}catch (Sales::bad_index &bad){cout << bad.what();LabeledSales::nbad_index *ni;if (ni = dynamic_cast<LabeledSales::nbad_index *>(&bad)) //RTTI识别类型;{cout << "Company: " << ni->label_val() << endl;cout << "bad index: " << ni->bi_val() << endl;}else{cout << "bad index: " << bad.bi_val() << endl;}}cout << "\nNext try block:\n";try{sales2[2] = 37.5;sales1[20] = 23345;cout << "End of try block 2.\n";}catch (Sales::bad_index &bad){cout << bad.what();LabeledSales::nbad_index *ni;if (ni = dynamic_cast<LabeledSales::nbad_index *>(&bad)) //RTTI识别类型;{cout << "Company: " << ni->label_val() << endl;cout << "bad index: " << ni->bi_val() << endl;}else{cout << "bad index: " << bad.bi_val() << endl;}}cout << "done\n";return 0;
}

http://www.hrbkazy.com/news/42799.html

相关文章:

  • 做网站推广每天加班哈尔滨网站制作软件
  • 微商产品做网站免费外链网站
  • 石家庄网站模板建站热点军事新闻
  • css3 特效网站免费十八种禁用网站
  • 汽车网站制作seo搜索引擎优化兴盛优选
  • 微信网站怎么写搜索引擎优化核心
  • php网站开发说明文档济南网站seo哪家公司好
  • 用vue-cli做的网站网站制作的基本流程是什么
  • wordpress clean options抖音seo怎么做的
  • 策划网络营销活动方案seo怎么收费
  • 在线客服免费咨询seo优化费用
  • 贵州网站制作品牌公司今天新闻摘抄十条
  • 国家企业信用信息查询官网系统百度广告优化师
  • 做食品那些网站好seo教程排名第一
  • 万达网站建设seo快速推广窍门大公开
  • 有做装修效果图赚钱的网站吗广告免费发布信息
  • 网站建设多长时间网站代运营价格
  • 广州做网站那家好口碑营销渠道
  • 网站建设厌倦微信营销平台哪个好
  • wamp建设网站大致步骤公司网站推广
  • 网站开发 高级认证搜狗优化排名
  • 淄博做网站推广哪家好广告联盟平台自动赚钱
  • 网站内容被攻击该怎么做seo优化排名软件
  • 做设计一般用什么素材网站软文新闻发稿平台
  • 如何验证网站济南网站优化排名
  • 网站品牌词如何优化长沙seo计费管理
  • 外贸网站建设注意今天重大新闻事件
  • 太湖网站建设帮平台做推广怎么赚钱
  • 建筑网站网页设计google搜索首页
  • 武汉网站维护制作免费b站推广入口2023