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

网站建设需要的技术路线百度问问我要提问

网站建设需要的技术路线,百度问问我要提问,北京到安阳高速费多少钱,网站开发与应用案例教程我们知道C可以对函数进行重载#xff0c;让同名的函数来完成相同的基本操作。其实运算符也是可以重载的#xff0c;而且有的运算符已经在使用了#xff0c;就像*#xff0c;既可以用于地址#xff0c;又可以用于乘法。 下面是一个计算时间的类 #ifndef MYTIME_H #define…我们知道C可以对函数进行重载让同名的函数来完成相同的基本操作。其实运算符也是可以重载的而且有的运算符已经在使用了就像*既可以用于地址又可以用于乘法。 下面是一个计算时间的类 #ifndef MYTIME_H #define MYTIME_H#include iostreamusing namespace std;class Time { private:int hours;int minutes;public:Time();Time(int h, int m 0);void AddMin(int m);void AddHr(int h);void Reset(int h 0, int m 0);Time Sum(const Time t) const;void Show() const; };#endif // MYTIME_H#include mytime.hTime::Time() {hours minutes 0; }Time::Time(int h, int m) {hours h;minutes m; }void Time::AddMin(int m) {minutes m;hours minutes/60;minutes % 60; }void Time::AddHr(int h) {hours h; }void Time::Reset(int h, int m) {hours h;minutes m; }Time Time::Sum(const Time t) const {Time sum;sum.minutes minutes t.minutes;sum.hours hours t.hours sum.minutes/60;sum.minutes % 60;return sum; }void Time::Show() const {cout hours hours, minutes minutes.\n; } #include iostream #include mytime.husing namespace std;int main() {Time planning;Time coding(2, 40);Time fixing(5, 55);Time total;cout planning time ;planning.Show();cout endl;cout coding time ;coding.Show();cout endl;cout fixing time ;fixing.Show();cout endl;total coding.Sum(fixing);cout coding.Sum(fixing) ;total.Show();cout endl;return 0; } 输出结果 planning time 0 hours, 0 minutes.coding time 2 hours, 40 minutes.fixing time 5 hours, 55 minutes.coding.Sum(fixing) 8 hours, 35 minutes. 添加加法运算符 将Time类转换为重载的加法运算法很容易只要将Sum()的名称改为operator ()即可。只要把运算符放在operator的后面 #ifndef STOCK_H #define STOCK_H #include stringusing namespace std;class stock { private:string company;long shares;double share_val;double total_val;void set_tot() {total_val shares * share_val;}public:void buy(long num, double price);void sell(long num, double price);void update(double price);void show() const;const stock topval(const stock s) const;stock(const string co, long n, double pr);stock();~stock(); };#endif // STOCK_H#include mytime.hTime::Time() {hours minutes 0; }Time::Time(int h, int m) {hours h;minutes m; }void Time::AddMin(int m) {minutes m;hours minutes/60;minutes % 60; }void Time::AddHr(int h) {hours h; }void Time::Reset(int h, int m) {hours h;minutes m; }//运算符重载 Time Time::operator(const Time t) const {Time sum;sum.minutes minutes t.minutes;sum.hours hours t.hours sum.minutes/60;sum.minutes % 60;return sum; }void Time::Show() const {cout hours hours, minutes minutes.\n; } operator(const Time t) const与Sum(const Time t) const效果完全一样可以理解operator()就是一个函数也可以被调用。就像下面的语句一样。 total coding.operator(fixing); 但是可以进一步简化 total coding fixing; 这两种方法都讲使用operator()函数运算符左侧的coding是调用对象右边的fixing是参数被传递的对象。 #include iostream #include mytime.husing namespace std;int main() {Time planning;Time coding(2, 40);Time fixing(5, 55);Time total;cout planning time ;planning.Show();cout endl;cout coding time ;coding.Show();cout endl;cout fixing time ;fixing.Show();cout endl;//total coding.operator(fixing);total coding fixing;cout coding.Sum(fixing) ;total.Show();cout endl;return 0; }输出结果没有变化 planning time 0 hours, 0 minutes.coding time 2 hours, 40 minutes.fixing time 5 hours, 55 minutes.coding.Sum(fixing) 8 hours, 35 minutes. 运算符重载的限制 1、重载后的运算符必须至少有一个操作数是用户定义的类型 2、使用运算符使不能违反运算符原来的句法规则 3、不能创建新的运算符 4、有些运算符不能被重载如sizeof, ?:, ::等 5、大多数运算符都可以通过成员或者非成员函数进行重载但、、[]、-只能通过成员函数进行重载。 、-、 *重载的应用 #ifndef MYTIME_H #define MYTIME_H#include iostreamusing namespace std;class Time { private:int hours;int minutes;public:Time();Time(int h, int m 0);void AddMin(int m);void AddHr(int h);void Reset(int h 0, int m 0);Time operator(const Time t) const;Time operator-(const Time t) const;Time operator*(double mult) const;void Show() const; };#endif // MYTIME_H #include mytime.hTime::Time() {hours minutes 0; }Time::Time(int h, int m) {hours h;minutes m; }void Time::AddMin(int m) {minutes m;hours minutes/60;minutes % 60; }void Time::AddHr(int h) {hours h; }void Time::Reset(int h, int m) {hours h;minutes m; }//运算符重载 Time Time::operator(const Time t) const {Time sum;sum.minutes minutes t.minutes;sum.hours hours t.hours sum.minutes/60;sum.minutes % 60;return sum; }Time Time::operator-(const Time t) const {Time diff;int tot1, tot2;tot1 t.minutes 60 * t.hours;tot2 minutes 60 * hours;diff.minutes (tot2 - tot1) % 60;diff.hours (tot2 - tot1) / 60;return diff; }Time Time::operator*(double mult) const {Time result;long totalminutes hours * mult *60 minutes * mult;result.hours totalminutes / 60;result.minutes totalminutes % 60;return result; }void Time::Show() const {cout hours hours, minutes minutes.\n; } #include iostream #include mytime.husing namespace std;int main() {Time weeding(4, 35);Time waxing(2, 47);Time total;Time diff;Time adjusted;cout weeding time ;weeding.Show();cout endl;cout waxing time ;waxing.Show();cout endl;cout total working time ;total weeding waxing;total.Show();cout endl;diff weeding - waxing;cout weeding time - waxing time ;diff.Show();cout endl;adjusted total * 1.5;cout adjusted work time ;adjusted.Show();cout endl;return 0; }输出结果 weeding time 4 hours, 35 minutes.waxing time 2 hours, 47 minutes.total working time 7 hours, 22 minutes.weeding time - waxing time 1 hours, 48 minutes.adjusted work time 11 hours, 3 minutes.
http://www.ho-use.cn/article/10815781.html

相关文章:

  • 网站建设 云南做网站如何更新百度快照
  • 站长工具ip查询12306网站建设
  • 简要描述网站开发过程沈阳唐朝网络推广
  • 网站页面分析作业注册公司需要怎么注册
  • 安徽网站建设流程设计平台兼职
  • 企业网站的完整性包括哪些优酷wordpress建站教程
  • wordpress 子目录建站嘉兴秀宏建设公司网站
  • 盐城网站开发江苏优化网站价格
  • 十大创意网站前端与移动开发
  • 如何制作网站主页建筑工程网上保健网站
  • 做调查的网站推荐软文写作要求
  • 重庆建设工程招标网站如何攻击网站
  • 昆山seo网站优化软件苏州怎么制作网页网站
  • 网站建设的项目计划模仿软件下载wordpress
  • 设计一个自己的电商网站亚马逊注册没有公司网站怎么做
  • 打赏网站开发设计类专业好找工作吗
  • 维修网站源码出口外贸交易平台
  • 站长数据男女做污污的网站
  • 制作网站演示wordpress剑侠情缘主题
  • 响应式网站编码怎吗设置网站建设最新技术及发展趋势
  • 如何上传图片到网站wordpress扫光
  • 小红书网站建设目的重庆网站制作哪家好
  • 资阳做网站做网站有什么用出
  • 齐齐哈尔市建设工程监察网站程序员代做网站违法
  • 昆明市环保局建设网站企业网站适合响应式嘛
  • 广东网站建设包括什么地区网站建设服务周到
  • 甘肃住房和城乡建设部网站安卓app开发平台
  • 菜鸟教程网站中国建筑网官网查证
  • 做oa系统的网站蝙蝠做等级的网站
  • wordpress外链缩略图seo 培训教程