编译器:C++ (g++)
输入样例
16 28 57
32 49 15
输出样例
49 18 12
#include <iostream>
#include <iomanip>
using namespace std;
/* 你提交的代码将被嵌在这里 */
int main()
{
ANGLE a, b, c;
a.Input();
b.Input();
c = a.Add(b);
c.Output();
cout << endl;
return 0;
}
Ans:
class ANGLE {
private:
int deg;
int min;
int sec;
public:
ANGLE(int d, int m, int s) :deg(d), min(m), sec(s) {};
ANGLE() :deg(0), min(0), sec(0) {};
void Input() {
cin >> deg >> min >> sec;
}
void Output() {
cout << deg << " " << min << " " << sec << endl;
}
ANGLE& Add(ANGLE a) {
sec += a.sec;
if (sec > 59) {
sec = sec % 60;
min++;
if (min > 59) {
min = min % 60;
deg++;
}
}
min += a.min;
if (min > 59) {
min = min % 60;
deg++;
}
deg += a.deg;
return *this;
}
/*ANGLE& operator=(const ANGLE& a) {
sec = a.sec;
min = a.min;
deg = a.min;
return *this;
}*/
};
本文介绍了如何在C++中创建一个名为ANGLE的类,用于处理角度的输入、输出以及加法操作,展示了类的构造函数、成员变量和自定义运算符等关键部分。
1417

被折叠的 条评论
为什么被折叠?



