開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C++ (プログラミング言語)
- g++(コンパイラ)
C++実践プログラミング (スティーブ オウアルライン (著)、Steve Oualline (原著)、Steve Oualline(原著)、望月 康司(翻訳)、クイープ(翻訳) 、オライリー・ジャパン)のⅢ部(高度な型とクラス)の13章(シンプルなクラス)、13.9(プログラミング実習)、実習 13-2.を解いてみる。
その他参考書籍
- C++プログラミング入門 (グレゴリー サティア (著)、ダウグ ブラウン (著)、Gregory Satir (原著)、Doug Brown (原著)、望月 康司 (翻訳)、谷口 功 (翻訳)、オライリージャパン)
実習 13-2.
コード(BBEdit, Emacs)
sample233_2.cpp
#include <iostream>
class check {
private:
int total_amount;
public:
explicit check();
// check(const check& old_check)
// ~check()
// operator = (const check& old_check)
void add_item(int amount);
int total();
};
inline check::check()
{
total_amount = 0;
}
inline void check::add_item(int amount)
{
total_amount += amount;
}
inline int check::total()
{
return total_amount;
}
int main()
{
class check a_check;
int i;
for (i = 0; i < 10; ++i) {
a_check.add_item(i + 1);
}
std::cout << a_check.total() << '\n';
return (0);
}
Makefile
#
# FSFのg++コンパイラ用のMakefile
#
CC=g++
CFLAGS=-g -Wall
all: sample233_2
sample233_2: sample233_2.cpp
${CC} ${CFLAGS} -o sample233_2 sample233_2.cpp
clean:
rm sample233_2
入出力結果(Terminal)
$ make && ./sample233_2 g++ -g -Wall -o sample233_2 sample233_2.cpp 55 $
0 コメント:
コメントを投稿