当前位置:网站首页>Pta:6-30 time addition
Pta:6-30 time addition
2022-06-23 04:38:00 【Sy_ Faker】
Design a time class , When used to save 、 branch 、 Seconds and other private data members , By overloading operators “+” Realization 2 The sum of times . requirement : (1) The time range of hours is limited to greater than or equal to 0;(2) The time range of minutes is 0-59 branch ;(3) The time range of seconds is 0-59 second .
#include <iostream>
using namespace std;
class Time {
private:
int hours,minutes, seconds;
public:
Time(int h=0, int m=0, int s=0);
Time operator + (Time &);
void DispTime();
};
/* Please fill in the answer here */
int main() {
Time tm1(8,75,50),tm2(0,6,16), tm3;
tm3=tm1+tm2;
tm3.DispTime();
return 0;
}
Output :
Here is the corresponding output . for example :
9h:22m:6s
Code up :
Time::Time(int h,int m,int s)
{
hours=h;
minutes=m;
seconds=s;
}
void Time::DispTime()
{
cout<<hours<<"h:"<<minutes<<"m:"<<seconds<<"s"<<endl;
}
Time Time::operator +(Time & k)
{
Time temp;
temp.minutes=this->minutes+k.minutes;
temp.seconds=this->seconds+k.seconds;
temp.hours=this->hours+k.hours;
if(temp.seconds>59)
{
temp.seconds-=60;
temp.minutes++;
}
if(temp.minutes>59)
{
temp.minutes-=60;
temp.hours++;
}
return temp;
}
边栏推荐
- 距离度量 —— 余弦距离(Cosine Distance)
- [pycharm] ide Eval resetter
- OpenJudge NOI 1.13 49:计算对数
- [binary tree] flip equivalent binary tree
- Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
- Twitter cooperates with Shopify to introduce merchant products into twitter shopping
- Sequence table lookup
- Pta:7-85 data spacing (overload + function template)
- Halcon知识:binocular_disparity 知识
- 【二叉樹進階】AVLTree - 平衡二叉搜索樹
猜你喜欢

How to use shell script to monitor file changes

flutter系列之:flutter中的Wrap

Pytorch---使用Pytorch的预训练模型实现四种天气分类问题

The spring recruitment in 2022 begins, and a collection of interview questions will help you

Background ribbon animation plug-in ribbon js

C语言刷题随记 —— 自由落体的球

【Pytorch】用自动微分求sin(x)的导数

Black horse PostgreSQL, why is it black in the end

How MySQL deletes a row of data in a table

Getting started with tensorflow
随机推荐
[advanced binary tree] AVLTree - balanced binary search tree
摆烂LuoGu刷题记
Review the SQL row column conversion, and the performance has been improved
[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime
PTA:7-61 师生信息管理
If you want to understand PostgreSQL, you must first brush the architecture
Prince language on insect date class
How to make the page number start from the specified page in word
Please use the NLTK Downloader to obtain the resource
【Pytorch】用自动微分求sin(x)的导数
Halcon glue line detection - template matching, pose transformation, glue width, glue continuity detection
PTA:7-65 饮料的价格
给你的AppImage创建桌面快捷方式
[pycharm] ide Eval resetter
Leetcode 1208. Make strings as equal as possible
Online JSON to CSharp (c) class tool
抖音x-bogus和_signature参数分析
基于FPGA的VGA协议实现
京东云分布式数据库StarDB荣获中国信通院 “稳定性实践先锋”
虫子 STM32 高级定时器 (哈哈我说实话硬件定时器不能体现实力,实际上想把内核定时器发上来的,一想算了,慢慢来吧)