開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C++ (プログラミング言語)
- g++(コンパイラ)
C++実践プログラミング (スティーブ オウアルライン (著)、Steve Oualline (原著)、Steve Oualline(原著)、望月 康司(翻訳)、クイープ(翻訳) 、オライリー・ジャパン)のⅢ部(高度な型とクラス)の12章(高度な型)、12.7(プログラミング実習)、実習 12-2.を解いてみる。
その他参考書籍
- C++プログラミング入門 (グレゴリー サティア (著)、ダウグ ブラウン (著)、Gregory Satir (原著)、Doug Brown (原著)、望月 康司 (翻訳)、谷口 功 (翻訳)、オライリージャパン)
実習 12-2.
コード(BBEdit, Emacs)
sample211_2.cpp
#include <iostream>
struct date_time {
int hour;
int minute;
int day;
};
int diff_time(struct date_time t1, struct date_time t2)
{
int hour = t2.hour - t1.hour;
int minute = t2.minute - t1.minute;
return 60 * hour + minute;
}
int main()
{
struct date_time t1 = { 5, 10, 0};
struct date_time t2 = { 6, 20, 0};
std::cout << diff_time(t2, t1) << '\n' <<
diff_time(t1, t2) << '\n';
return (0);
}
Makefile
#
# FSFのg++コンパイラ用のMakefile
#
CC=g++
CFLAGS=-g -Wall
all: sample211_2
sample211_2: sample211_2.cpp
${CC} ${CFLAGS} -o sample211_2 sample211_2.cpp
clean:
rm sample211_2
入出力結果(Terminal)
$ make && ./sample211_2 g++ -g -Wall -o sample211_2 sample211_2.cpp -70 70 $
0 コメント:
コメントを投稿