#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. Pandas切片操作:很容易忽视的SettingWithCopyWarning

    Pandas是一个强大的分析结构化数据的工具集,主要用于数据挖掘和数据分析,同时也提供数据清洗功能. 很多初学者在数据的选取,修改和切片时经常面临一些困惑.这是因为Pandas提供了太多方法可以做同样 ...

  2. 一键运行CIS安全扫描,集群安全无忧!

    CIS安全扫描是Rancher 2.4推出的其中一个重磅功能,旨在帮助用户快速.有效地加强集群的安全性.本文将详细介绍CIS安全扫描这一功能,包含详细的操作demo. 本文来自Rancher Labs ...

  3. 这是一篇每个人都能读懂的最小生成树文章(Kruskal)

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是算法和数据结构专题的第19篇文章,我们一起来看看最小生成树. 我们先不讲算法的原理,也不讲一些七七八八的概念,因为对于初学者来说,看到 ...

  4. AntDesignPro的权限控制和动态路由

    最近看了AntDesignPro关于权限控制的官方文档以及自己框架里权限控制的实现,总结一下. 先贴一下官网上关于权限控制的图有利于理解 步骤如下: 判断是否有 AccessToken 如果没有则跳转 ...

  5. Linux共享库简单总结

    库 静态库 编译的二进制会重新包含一份静态库的副本 共享库 编译 gcc -shared -o file.c -fPIC 链接 ld ld-linux.so.2 可执行程序–>动态依赖表 流程: ...

  6. JDBC06 其他操作及批处理Batch

    灵活指定SQL语句中的变量 -PreparedStatement 对存储过程进行调用 -CallableStatement 运用事务处理 -Transaction 批处理 -Batch -对于大量的批 ...

  7. java中"no enclosing instance of type * is accessible"的解决方法

    这种情况一般发生在“在静态方法里面使用内部类” 测试代码: public class Test { public static void main(String[] args) { A a = new ...

  8. Pytorch使用分布式训练,单机多卡

    pytorch的并行分为模型并行.数据并行 左侧模型并行:是网络太大,一张卡存不了,那么拆分,然后进行模型并行训练. 右侧数据并行:多个显卡同时采用数据训练网络的副本. 一.模型并行 二.数据并行 数 ...

  9. python selenium unittest Fixture(setUp/tearDown)笔记

    Fixture用途: 1.做测试前后的初始化设置,如测试数据准备,链接数据库,打开浏览器等这些操作都可以使用fixture来实现 2.测试用例的前置条件可以使用fixture实现 Fixture使用: ...

  10. 萌新学习SpringMVC

    前言 只有光头才能变强. 文本已收录至我的GitHub精选文章,欢迎Star:https://github.com/ZhongFuCheng3y/3y 这篇SpringMVC被催了很久了,这阵子由于做 ...