• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

練習用です。いろんなものがごちゃまぜです。


Commit MetaInfo

Revision47 (tree)
Time2015-10-01 12:19:07
Authorbellyoshi

Log Message

(empty log message)

Change Summary

Incremental Difference

--- TeachYourSelf/stopwatch.cpp (revision 46)
+++ TeachYourSelf/stopwatch.cpp (revision 47)
@@ -4,41 +4,43 @@
44
55 class stopwatch {
66 clock_t startTime;
7- int timespan;
8- bool switch_on;
7+ clock_t endTime;
98 public:
109 stopwatch();
10+ stopwatch(clock_t starttime);
1111 void stop();
1212 void start();
13+ void show();
1314 ~stopwatch();
1415 };
1516
1617 stopwatch::stopwatch()
1718 {
18- timespan = 0;
19- switch_on = false;
19+ startTime = endTime = 0;
2020 }
21-
21+stopwatch::stopwatch(clock_t starttime)
22+{
23+ this->startTime = starttime;
24+ this->endTime = 0;
25+}
26+
2227 void stopwatch::start()
2328 {
24- startTime = clock();
25- switch_on = true;
29+ this->startTime = clock();
2630 }
2731
2832 void stopwatch::stop()
2933 {
30- if (!switch_on){
31- return;
32- }
33- switch_on = false;
34- clock_t endTime = clock();
35- timespan += (endTime - startTime) / CLOCKS_PER_SEC;
34+ this->endTime = clock();
3635 }
36+void stopwatch::show()
37+{
38+ int timespan = (endTime - startTime) / CLOCKS_PER_SEC;
39+ cout << "経過時間: " << timespan << "\n";
40+}
3741
3842 stopwatch::~stopwatch()
3943 {
40- stop();
41- cout << "経過時間: " << timespan << "\n";
4244 }
4345
4446 int main()
@@ -48,15 +50,16 @@
4850
4951 //遅延...
5052 sw.start();
51- cout << "on なにか入力: ";
53+ cout << "なにか入力: ";
5254 cin >> c;
5355 sw.stop();
54- cout << "off なにか入力。: ";
56+ sw.show();
57+
58+ stopwatch sw2(clock());
59+ cout << "なにか入力。: ";
5560 cin >> c;
56- sw.start();
57- cout << "on なにか入力。: ";
58- cin >> c;
59- sw.stop();
61+ sw2.stop();
62+ sw2.show();
6063
6164 return 0;
6265 }
\ No newline at end of file