#include <iostream>
#include <cstdio> using namespace std; class MyTime
{
private:
int hour;
int minute;
int second;
public:
MyTime(){hour=;minute=;second=;}
MyTime(int,int,int);
void Register(int,int,int);
void Show_12();
void Show_24();
void Sub(int,int,int);
void Add(int,int,int);
}; MyTime::MyTime(int a, int b, int c)
{
hour=a;
minute=b;
second=c;
} void MyTime::Show_12()
{
if(hour>)
{
printf("%02d:%02d:%02d PM\n",hour-,minute,second);
}
else
{
printf("%02d:%02d:%02d AM\n",hour,minute,second);
}
return;
} void MyTime::Show_24()
{
printf("%02d:%02d:%02d\n",hour,minute,second);
return;
} void MyTime::Sub(int a, int b, int c)
{
hour-=a;
minute-=b;
second-=c;
while(second<)
{
second+=;
minute-=;
}
while(minute<)
{
minute+=;
hour-=;
}
while(hour<)
{
hour+=;
}
return;
} void MyTime::Add(int a, int b, int c)
{
hour+=a;
minute+=b;
second+=c;
while(second>)
{
second-=;
minute+=;
}
while(minute>)
{
minute-=;
hour+=;
}
while(hour>)
{
hour-=;
}
return;
} void MyTime::Register(int a,int b, int c)
{
hour=a;
minute=b;
second=c;
return;
} int main()
{
MyTime one,two(,,);
int a,b,c,x,y,z;
cin>>a>>b>>c>>x>>y>>z;
one.Show_12();
one.Show_24();
two.Show_12();
two.Show_24();
one.Register(a,b,c);
one.Add(x,y,z);
two.Sub(x,y,z);
one.Show_12();
one.Show_24();
two.Show_12();
two.Show_24();
return ;
}

设计一个多功能的MyTime类 代码参考的更多相关文章

  1. 设计MyTime类 代码参考

    #include <iostream> #include <cstdio> using namespace std; class MyTime { private: int h ...

  2. 设计一个 Java 程序,自定义异常类,从命令行(键盘)输入一个字符串,如果该字符串值为“XYZ”。。。

    设计一个 Java 程序,自定义异常类,从命令行(键盘)输入一个字符串,如果该字符串值为“XYZ”,则抛出一个异常信息“This is a XYZ”,如果从命令行输入 ABC,则没有抛出异常.(只有 ...

  3. 一个简单的php分页类代码(转载)

    入门级php分页类 原文地址:http://www.xfcodes.com/php/fenye/3608.htm 时间:2015-12-16 20:52:00来源:网络 php分页类. 复制代码代码如 ...

  4. 一个基类Person的多个派生类 代码参考

    #include <iostream> #include <cstring> using namespace std; class Person { protected: ch ...

  5. 设计带构造函数的Dog类 代码参考

    #include <iostream> #include <string> using namespace std; class Dog { private: string n ...

  6. 设计Dog类 代码参考

    #include <iostream> #include <string> using namespace std; class Dog { private: string n ...

  7. 设计Person类 代码参考

    #include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...

  8. 设计并测试Trapezium类 代码参考

    #include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...

  9. 设计Weekday类 代码参考

    #include <iostream> using namespace std; class Weekday { private: int num; public: void SetDay ...

随机推荐

  1. mysql-case..when知识点总结

    case...when..有两种语法: 第一种: case  case_value when when_value  then statement_list [when when_value  the ...

  2. 面试中的volatile关键字

    在Java的面试当中,面试官最爱问的就是volatile关键字相关的内容.经过多次面试之后,你是否思考过,为什么他们那么爱问volatile关键字相关的问题?而对于你,如果作为面试官,是否也会考虑采用 ...

  3. python基础的一些题目

    第一部分: 第二部分: 第三部分:

  4. windows下flume 采集如何支持TAILDIR和tail

    一.问题:Windows 下 flume采集配置TAILDIR的时候,会报如下错误: agent.sources.seqGenSrc.type = TAILDIR agent.sources.seqG ...

  5. 前端——Vue.js学习总结一

    一.什么是Vue.js 1.Vue.js 是目前最火的一个前端框架,React是最流行的一个前端框架 2.Vue.js 是前端的主流框架之一,和Angular.js.React.js 一起,并成为前端 ...

  6. P3467(矩形覆盖问题)

    描述:https://www.luogu.com.cn/problem/P3467 1.考虑如果整个建筑物链是等高的,一张高为链高,宽为整个建筑物宽的海报即可完全覆盖: 2.若有两个不等高的元素组成建 ...

  7. 简单ajax跨域请求

    最近遇到需要ajax跨域的需求 首先看下不做任何处理特别处理的ajax跨域请求会出现什么样的错误 客户端代码: <script type="text/javascript"& ...

  8. Android中限制输入框最大输入长度

    通常情况下只需要在布局文件中加入maxlength这一属性即可 <EditText android:inputType="text" android:singleLine=& ...

  9. FOC 电流采样方案对比(单电阻/双电阻/三电阻)

    如果本文帮到了你,帮忙点个赞: 如果本文帮到了你,帮忙点个赞: 如果本文帮到了你,帮忙点个赞: 创作不易 谢谢支持 文章目录 1 电流采样的作用 2 硬件架构 3 采样关键 4 采样方案 5 三电阻采 ...

  10. [hdu5312]数的拆分,数学推导

    题意:给定一个序列,a[n]=3n(n-1)+1,n>=1,求给定的m(m<=1e9)最少可以用几个a里面的数表示(可以重复) 思路:对答案分类 (1)假定答案为1,则m必定是a中的某一个 ...