일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 데이터 과학
- data science
- 인공지능
- 빅데이타
- R
- WebGL
- c++
- 통계
- 몽고디비
- Artificial Intelligence
- openCV
- probability
- 빅 데이터
- 딥러닝
- Statistics
- 김양재 목사
- Big Data
- 김양재
- 주일설교
- 김양재 목사님
- 우리들교회
- node.js
- No SQL
- MongoDB
- Machine Learning
- 빅데이터
- nodeJS
- 빅 데이타
- 확률
- Deep learning
Archives
- Today
- Total
Scientific Computing & Data Science
[C/C++] Example / clockType 본문
//
// main.cpp
//
// Created by gchoi on 2014. 5. 16..
// Copyright (c) 2014년 gchoi. All rights reserved.
//
#include <iostream>
#include <assert.h>
#include <math.h>
using namespace std;
class clockType {
private:
int hr;
int min;
int sec;
public:
clockType();
clockType(int hr, int min, int sec);
void setTime(int hr, int min, int sec);
void getTime(int& hr, int& min, int& sec);
void printTime() const;
void incrementSeconds();
void incrementMinutes();
void incrementHours();
bool equalTime(const clockType& otherClock) const;
};
clockType::clockType() {
hr = 0;
min = 0;
sec = 0;
}
clockType::clockType(int hour, int minute, int second) {
int mod, rem;
mod = second / 60;
rem = second % 60;
min = minute + mod;
sec = rem;
mod = min / 60;
rem = min % 60;
min = rem;
hr = hour + mod;
hr = hr % 24;
}
void clockType::setTime(int hour, int minute, int second) {
int mod, rem;
mod = second / 60;
rem = second % 60;
min = minute + mod;
sec = rem;
mod = min / 60;
rem = min % 60;
min = rem;
hr = hour + mod;
hr = hr % 24;
}
void clockType::getTime(int &hour, int &minute, int &second) {
hr = hour;
min = minute;
sec = second;
}
void clockType::printTime() const {
cout << hr << ":" << min << ":" << sec << endl;
}
void clockType::incrementSeconds() {
sec++;
int mod, rem;
mod = sec / 60;
rem = sec % 60;
min += mod;
sec = rem;
mod = min / 60;
rem = min % 60;
min = rem;
hr += mod;
hr = hr % 24;
}
void clockType::incrementMinutes() {
min++;
int mod, rem;
mod = min / 60;
rem = min % 60;
min = rem;
hr += mod;
hr = hr % 24;
cout << "oops" << endl;
}
void clockType::incrementHours() {
hr++;
hr = hr % 25;
}
bool clockType::equalTime(const clockType& otherClock) const {
int cnt = 0;
if(hr != otherClock.hr) cnt++;
if(min != otherClock.min) cnt++;
if(sec != otherClock.sec) cnt++;
if(cnt > 0) return false;
else return true;
}
///////////////////////////////////////////////////////////////
// MAIN
///////////////////////////////////////////////////////////////
int main(int argc, const char * argv[])
{
clockType* ct = new clockType(72, 59, 59);
clockType* ct2 = new clockType(72, 42, 59);
cout << ct2->equalTime(*ct) << endl;
return 0;
}
'Programming > C&C++' 카테고리의 다른 글
[C/C++] Example / Assignment Operator (0) | 2014.06.12 |
---|---|
[C/C++] Example / Double Pointer (0) | 2014.06.12 |
[C/C++] Example / String Append (0) | 2014.06.12 |
[C/C++] Example / Vector Class (0) | 2014.06.12 |
[C/C++] Example / 최대공약수(GCM) 알고리즘 (0) | 2014.06.12 |
Comments