cpp11.10
来源:互联网 发布:抓包后怎么看mac地址 编辑:程序博客网 时间:2024/05/16 03:21
mytime3.h
#pragma once#include<iostream>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 n) const;friend Time operator*(double m, const Time & t) {return t*m;}friend std::ostream & operator<<(std::ostream & os, const Time & t);};
mytime3.cpp
#include "mytime3.h"Time::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;}std::ostream & operator<<(std::ostream & os, const Time & t){os << t.hours << " hours, " << t.minutes << " minutes";return os;}
usetime3.cpp
#include<iostream>#include "mytime3.h"int main(){using std::cout;using std::endl;Time aida(3, 35);Time tosca(2, 48);Time temp;cout << "Aida andTosca:\n";cout << aida << "; " << tosca << endl;temp = aida + tosca;cout << "Aida + Tosca: " << temp << endl;temp = aida*1.17;cout << "Aida * 1.17: " << temp << endl;cout << "10.0* Tosca: " << 10.0*tosca << endl;system("pause");return 0;}
0 0
- cpp11.10
- cpp11.3
- Design: cpp11-migrate
- C++11 CPP11 学习
- 用Cpp11新template feature尝试metaprogramming
- CPP11中的atomic类以及memory_order
- cpp11新特性详解与应用
- cpp11 的变量类型自动推断
- 10
- 10
- 10
- 10
- 10
- 10
- 10
- 10
- 10%
- 10
- 【opencv】二值图像细化
- javascript 数组常用方法整理
- RabbitMQ三种Exchange模式(fanout,direct,topic)
- C++的学习
- Web Uploader基本用法
- cpp11.10
- Retrofit API 中文
- iscroll块遇到原生滑动不能滑
- webpack打包react和过程遇到的问题
- strings命令
- RefreshControl
- 数据结构基础-栈-铁轨uva514
- Array
- c语言中的空指针与野指针