プリンキピア

第7章高水準プログラミング言語

Exercises 16–17練習問題 16–17
16. Implement a code block in C++ that is only “activated” when we are debugging the application using a preprocessor definition.
16. プリプロセッサーの定義を使い、アプリケーションをデバッグするときだけ「有効になる」コードブロックを、C++で実装しなさい。
17. Run the program you wrote above in GDB. Explore setting breakpoints and setting watches on variables as they change. You can either download and install GDB on your computer or use the free online website (https://openstax.org/r/76GDB) that runs GDB for you.
英語のヒント
17. 上で書いたプログラムをGDBで実行しなさい。ブレークポイントを設定し、変化する変数を監視する設定を試しなさい。GDBをダウンロードして自分のコンピューターにインストールしてもよいし、GDBを実行できる「無料のオンラインWebサイト」(https://openstax.org/r/76GDB)を使ってもよい。

Problem Set A問題集A

Exercises 1–5練習問題 1–5
1. Research how high-level languages have portability restrictions and how some languages handle portability. For example, compare C# and Java on Linux platforms.
1. 高水準言語には、どのような移植性の制限があり、一部の言語が移植性にどう対応しているかを調べなさい。たとえば、Linuxプラットフォーム上でのC#とJavaを比較しなさい。
2. What is the tradeoff between C# being fully compiled and Java running on the JVM?
英語のヒント
2. C#が完全にコンパイルされることと、JavaがJVM上で動くことの間には、どのようなトレードオフがあるか。
3. Research for loops. Write a for loop that matches the functionality of the following while loop:
3. forループを調べなさい。次のwhileループと同じ働きをするforループを書きなさい。
int main () {
    int iter = 0;
    while(iter < 10)
    {
        iter++;
        printf("%d", iter);
    }
}
4. In C/C++, data types can be returned from a function or used as an output parameter by passing the object by reference using a pointer. Write a piece of code that demonstrates two functions with the same performance, but one that returns a data type and one that uses an output parameter.
英語のヒント
4. C/C++では、データ型の値を関数から返すことも、ポインターを使ってオブジェクトを参照渡しし、出力引数として使うこともできる。同じ処理結果を得る二つの関数を示すコードを書き、一方はデータ型の値を返し、もう一方は出力引数を使うようにしなさい。
5. Research what a style guide and coding standard are. Review a sample coding standard for at least three different languages. Are the style guides and coding standards the same for each language? How could the style guides and coding standards lead to well-structured code?
5. スタイルガイドとコーディング規約とは何かを調べなさい。少なくとも三つの異なる言語について、コーディング規約の例を確認しなさい。スタイルガイドやコーディング規約は、言語ごとに同じだろうか。それらが、適切に構造化されたコードにつながるのは、どのようにしてか。
Exercises 6–8練習問題 6–8
6. Describe how inheritance can simplify the design of a software application. Can inheritance add to the complexity of the software?
6. 継承が、ソフトウェアアプリケーションの設計をどのように単純にできるか、説明しなさい。継承によって、ソフトウェアの複雑さが増すこともあるか。
7. You are designing a real-time software application, so timing of computations is critical. How could you develop a solution that takes less time to execute? What safety considerations do you need to design around?
7. リアルタイムのソフトウェアアプリケーションを設計しているので、計算のタイミングが非常に重要である。実行時間を短くできる解決策を、どう開発するか。安全性について、何を考慮して設計する必要があるか。
8. Research preprocessor definition uses. How can an organization have a common baseline of code but deliver only certain modules of code in a delivery.
英語のヒント
8. プリプロセッサーの定義の用途を調べなさい。組織が共通の基盤となるコードを持ちながら、一回の納品では特定のコードモジュールだけを提供するには、どうすればよいか。

Problem Set B問題集B

Exercises 1–5練習問題 1–5
1. Research how much support and how many APIs are available for cutting-edge technologies for the most popular languages of C#, C++/C, Java, and Python.
英語のヒント
1. よく使われるC#、C++/C、Java、Pythonについて、最先端技術を支える機能とAPIが、どの程度利用できるかを調べなさい。
2. You’re the lead software engineer for a team that has two projects on going with the same set of user capability requirements. Since the requirements are the same, you want to find a common solution and develop at least a common module. The client for Project 1 has agreed to a REST API as the standard to interface to the application, while the client for Project 2 will integrate the software as a static library. Project 2 requires that the software needs to run on both Windows and Linux, and C must be the language of choice. Project 1 only needs to run on Windows and has no language constraints. Research C and the level of support for REST API development. Would C be a good choice for the top layer for Project 1? Would Java be a better solution?
英語のヒント
2. あなたは、同じ利用者機能要件を持つ二つのプロジェクトを進めるチームの、主任ソフトウェアエンジニアである。要件が同じなので、共通の解決策を見つけ、少なくとも共通モジュールを開発したいと考えている。プロジェクト1の顧客は、アプリケーションと接続する標準としてREST APIを使うことに同意している。一方、プロジェクト2の顧客は、ソフトウェアを静的ライブラリーとして組み込む。プロジェクト2では、WindowsとLinuxの両方で動く必要があり、使用言語はCでなければならない。プロジェクト1は、Windowsで動けばよく、言語の制約はない。Cと、REST API開発の支援の程度を調べなさい。プロジェクト1の最上位の層にCを選ぶのは、よい判断だろうか。Javaのほうが、よい解決策になるだろうか。
3. We have demonstrated that one of C and C++’s features is that you can return a data type and can also use an output parameter to get the output of a function by sending in a pointer to the variable or data structure. Research and explain the pros and cons of using an output parameter by sending in a pointer to the data type.
3. CとC++には、データ型の値を返すだけでなく、変数やデータ構造へのポインターを渡し、出力引数を使って関数の結果を得られるという特徴があることを示した。データ型へのポインターを渡して出力引数を使うことの利点と欠点を、調べて説明しなさい。
4. Research the concept of garbage collection in programming languages. How do Java and C++ differ in garbage collection?
4. プログラミング言語における、ガベージコレクションの考え方を調べなさい。JavaとC++では、ガベージコレクションにどのような違いがあるか。
5. Research how arrays are different between C/C++ and Java in terms of memory allocation. How can this impact safety and reliability of the code?
5. C/C++とJavaでは、メモリ割り当ての点で配列がどう違うかを調べなさい。その違いは、コードの安全性と信頼性へ、どのような影響を与えうるか。
Exercises 6–8練習問題 6–8
6. If functional languages such as C cannot build objects using classes, how can a developer create complex data types? Research how structures are used in functional languages to create data types.
6. Cのような関数型言語が、クラスを使ってオブジェクトを作れないなら、開発者はどのように複合データ型を作れるだろうか。関数型言語で、構造体を使ってデータ型を作る方法を調べなさい。
7. Write three Java classes using polymorphism where there is one super class and two classes that inherit from the super class.
7. ポリモーフィズムを使うJavaのクラスを三つ書きなさい。一つをスーパークラスとし、残る二つがそのスーパークラスを継承するようにしなさい。
8. Research how compilers optimize code at build time and how this is a configurable setting.
英語のヒント
8. コンパイラーがビルド時にコードを最適化する方法と、その設定を変更する方法を調べなさい。