设计一个多功能的MyTime类 代码参考
#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类 代码参考的更多相关文章
- 设计MyTime类 代码参考
#include <iostream> #include <cstdio> using namespace std; class MyTime { private: int h ...
- 设计一个 Java 程序,自定义异常类,从命令行(键盘)输入一个字符串,如果该字符串值为“XYZ”。。。
设计一个 Java 程序,自定义异常类,从命令行(键盘)输入一个字符串,如果该字符串值为“XYZ”,则抛出一个异常信息“This is a XYZ”,如果从命令行输入 ABC,则没有抛出异常.(只有 ...
- 一个简单的php分页类代码(转载)
入门级php分页类 原文地址:http://www.xfcodes.com/php/fenye/3608.htm 时间:2015-12-16 20:52:00来源:网络 php分页类. 复制代码代码如 ...
- 一个基类Person的多个派生类 代码参考
#include <iostream> #include <cstring> using namespace std; class Person { protected: ch ...
- 设计带构造函数的Dog类 代码参考
#include <iostream> #include <string> using namespace std; class Dog { private: string n ...
- 设计Dog类 代码参考
#include <iostream> #include <string> using namespace std; class Dog { private: string n ...
- 设计Person类 代码参考
#include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...
- 设计并测试Trapezium类 代码参考
#include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...
- 设计Weekday类 代码参考
#include <iostream> using namespace std; class Weekday { private: int num; public: void SetDay ...
随机推荐
- bat 命令
1.强制杀死进程 /F force 强制性/IM image + 进程名 TASKKILL /F /IM python.exe
- django开发最完美手机购物商城APP带前后端源码
后端和数据接口,全采用django开发 从0到大神的进阶之路 一句话,放弃单文件引用vue.js练手的学习方式 马上从vue-cli4练手,要不然,学几年,你也不懂组件式开发,不懂VUEX,不懂路由, ...
- Azkaban无法连接网页
出的问题如下图 首先我查看日志看到有一个 [ERROR] 2020/03/13 11:12:34.417 +0800 ERROR [PluginCheckerAndActionsLoader] [Az ...
- 【FreeRTOS学习03】小白都能懂的Task Management 任务管理基本概念介绍
在FreeRTOS中,线程的术语又可以被称之为任务,或许这样更加合适,本文将介绍任务的创建/删除,任务参数的使用,以及任务优先级: 1 软实时和硬实时 硬实时系统的任务运行正确性与响应时限是紧密相关的 ...
- 探索Linux内核:Kconfig / kbuild的秘密
探索Linux内核:Kconfig / kbuild的秘密 文章目录 探索Linux内核:Kconfig / kbuild的秘密 深入了解Linux配置/构建系统的工作原理 Kconfig kbuil ...
- 第一行Kotlin系列(二)Intent隐式显式跳转及向下传值
1.Intent显式跳转页面 val button5 = findViewById<Button>(R.id.mButton5) button5.setOnClickListener { ...
- 设计模式GOF23之单例模式
单例模式的五种方式 主要:懒汉式,饿汉式 其他:双重检测锁(Double Checking模式),静态内部类,枚举模式 选取时机 延时加载,占用内部资源大:静态内部类好于懒汉 不延时加载,占用内部资源 ...
- Mybatis学习笔记汇总(包括源码和jar包)
博客整理 Mybatis学习笔记(一)--对原生jdbc中问题的总结 Mybatis学习笔记(二)--Mybatis框架 Mybatis学习笔记(三)--入门程序 MyBatis学习笔记(四)--入门 ...
- PK,FK, UK,DF, CK
PK 主键 constraint primary key FK 主外键关系 constraint foreign references UK 唯一约束 constraint unique key DF ...
- java学习笔记之原型模式及深浅拷贝
一.原型模式的基本介绍 在聊原型模式之前,我们来思考一个小问题,传统的方式我们是如何克隆对象呢? 那我们以多利羊(Sheep)为例,来说明上述这个问题,具体代码见下面: 多利羊(Sheep) publ ...