2013年3月26日火曜日

開発環境

『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487312-194-7)の 第6章(オブジェクト指向プログラミング)6.8(練習問題)練習6-2.を解いてみる。

その他参考書籍

練習6-2.

コード

using System;

namespace Sample
{
    class Book
    {
        private string title;
        private string author;
        private string isbn;
        public Book(string title, string author, string isbn)
        {
            this.title = title;
            this.author = author;
            this.isbn = isbn;
        }
        public void Read()
        {
            Console.WriteLine("本({0})を読む。", title);
        }
        public void Shelve()
        {
            Console.WriteLine("本({0})を書棚にしまう。", title);
        }
    }
    class Tester
    {
        public void Run()
        {
            Book lcs = new Book("初めてのC#", "Jesse Liberty", "487311294X");
            lcs.Read();
            lcs.Shelve();
        }
        static void Main()
        {
            Tester t = new Tester();
            t.Run();
        }
    }
}

入出力結果(Console Window)

本(初めてのC#)を読む。
本(初めてのC#)を書棚にしまう。
続行するには何かキーを押してください . . .

pythonの場合。

コード(BBEdit)

sample.py

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

class Book:
    def __init__(self, title, author, isbn):
        self._title = title
        self._author = author
        self._isbn = isbn
    def read(self):
        print("本({0})を読む。".format(self._title))
    def shelve(self):
        print("本({0})を書棚にしまう。".format(self._title))

lcs = Book("初めてのC#", "Jesse Liberty", "487311294X")
lcs.read()
lcs.shelve()

入出力結果(Terminal)

$ ./sample.py
本(初めてのC#)を読む。
本(初めてのC#)を書棚にしまう。
$

0 コメント:

コメントを投稿