#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. 配置Ansible加速

    下载安装包 wget https://files.pythonhosted.org/packages/source/m/mitogen/mitogen-0.2.7.tar.gz tar axf mit ...

  2. SpringBoot系列(十三)统一日志处理,logback+slf4j AOP+自定义注解,走起!

    往期精彩推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件详解 SpringBoot系列(四)we ...

  3. P1790 矩形分割(隐含的电风扇)

    描述:https://www.luogu.com.cn/problem/P1790 有一个长为a,宽为b的矩形(1≤a≤6,2≤b≤6).可以把这个矩形看作是a*b个小方格. 我们现在接到了这样的一个 ...

  4. .NET Attribute在数据校验上的应用

    Attribute(特性)的概念不在此赘述了,相信有点.NET基础的开发人员都明白,用过Attribute的人也不在少数,毕竟很多框架都提供自定义的属性,类似于Newtonsoft.JSON中Json ...

  5. Istio的流量管理(实操一)(istio 系列三)

    Istio的流量管理(实操一)(istio 系列三) 使用官方的Bookinfo应用进行测试.涵盖官方文档Traffic Management章节中的请求路由,故障注入,流量迁移,TCP流量迁移,请求 ...

  6. Linux --如何新增一块硬盘并自动挂载

    1. 虚拟机添加硬盘 2.  分区 fdisk /dev/sdb 3. 格式化 mkfs -t ext4 /dev/sdb1 将刚刚创建的盘格式化成 ext4格式 4. 挂载 先创建一个目录,/hom ...

  7. python--制作微信好友照片墙

    知识来源:https://zhuanlan.zhihu.com/p/73975013 1.环境 os:MAC tool:python 3.7 ,pip3.7 2.前提: 使用pip3.7 instal ...

  8. MYsql 8 连接报错 MySQLNonTransientConnectionException: Could not create connection to database server.

    本地安装mysql 是8 项目中数据驱动 也要求是 8 <dependency> <groupId>mysql</groupId> <artifactId&g ...

  9. equals(), "== ",hashcode() 详细解释

    Object 通用方法容易混淆的定义 先搞清楚各自的定义 "==" 用来判断 相等 equals() 用来判断 等价 hashcode() 用来返回散列值 "==&quo ...

  10. Java—线程的生命周期及线程控制方法详解

    线程生命周期5种状态 介绍   线程的生命周期经过新建(New).就绪(Runnable).运行(Running).阻塞(Bolocked)和死亡(Dead) 状态转换图 新建(New)   程序使用 ...