Answers to Chapter 2 Review Questions

   


Chapter 2

1:

What are the four core activities in the software development process? Describe each activity briefly.

A:

The four core activities of the software development process are

  • Software specification Specifying the requirements of the software

  • Software design Specifying how the software specification can be turned into a fully-functioning program

  • Writing the software Writing the text of the source code program, which in our case consists of C# language constructs

  • Software validation and debugging Checking that the program does what is specified in its software specification

2:

What is an algorithm and how can it be expressed?

A:

An algorithm is a set of precise instructions that the computer follows to accomplish a task. For example, algorithms can be expressed using pseudocode or a high-level language like C#.

3:

Why do computers need a very precise set of instructions to solve a problem?

A:

Computers are very fast but extremely dumb when trying to understand a computer program. They do not make assumptions and need to be told exactly what to do.

4:

In what order are instructions in pseudocode and C# executed?

A:

Execution begins with the topmost line and moves through the lines one by one as they appear in the pseudocode or the C# code. Execution ends at the last line.

5:

What are the three different errors programmers encounter? Describe each of them briefly.

A:
  • Syntax errors appear when the source code program does not follow the (grammatical) rules (the syntax) put forth in the C# language for how to write instructions.

  • Logic errors represent flaws in the logic of a program.

  • Runtime errors range from errors directly caused by the programmer to difficult-to-prevent problems, such as attempting to access corrupted or non-existing files.

6:

Why is computer testing a tricky undertaking?

A:

Most computer programs are so complex that it is impossible to test all the different scenarios the program will endure. Logic errors can still occur in programs without any syntax errors.

7:

Briefly describe process-oriented programming.

A:

Process-oriented programming focuses on actions rather than on the related data.

8:

Briefly describe object-oriented programming. What are the advantages of object-oriented programming compared to process-oriented programming?

A:

Object-oriented programming combines actions and their related data to form self-contained units called classes, with equal emphasis on actions and data. Objects are instantiated from classes. Objects collaborate to solve tasks by sending messages to each other. One main advantage of object-oriented programming is that it allows programmers to divide a program into smaller, simpler, self-contained units with a resulting reduction in complexity.

9:

What is an object? What does it consist of?

A:

An object is a fairly self-contained module containing data and actions that act on those data.

10:

What is the relationship between a class and its objects?

A:

A class is a blueprint for generating objects. A class can be viewed in the source code, whereas an object is created on the basis of a class during the execution of a program.

11:

How are the objects of a specific programming problem often identified?

A:

By describing the programming problem in a spoken language like English and then identifying the nouns used in this description.

12:

What is a software part meant for reuse called?

A:

A software component.

13:

What is the basic unit of reuse in .NET? Describe this unit.

A:

The assembly is the basic unit of reuse in .NET. It is a self-describing element that consists of MSIL, metadata, and resources.

14:

Which part of .NET offers software components for reuse?

A:

The .NET Frameworks class library.

15:

What are some of the design goals of C# and .NET?

A:

The designers wanted C# to be an evolutionary step forward from previous powerful languages (C and C++, in particular) by building on the strengths of these languages and to allow programmers an easy migration to C#. At the same time, they wanted C# to be simpler, safer, and more productive than its predecessors. C# is the first true component-oriented language, it provides full support for RAD, and it is a true object-oriented language where everything can be viewed as being an object.

16:

What are the main steps required for running a simple C# program?

A:

The C# source code is written with a text editor. The source code is compiled into MSIL using a C# language compiler. The .NET execution engine executes the MSIL to run the program.

17:

Can a C# program that has been accepted by the compiler still contain errors?

A:

Yes, the compiler checks for syntax errors, but it cannot know what you want your program to do, so it is unable to check for logical errors.

Answers to Chapter 2 Programming Exercises

1:

Write the pseudocode for an algorithm that determines the maximum number of two given numbers. Hint: Use the following logic: If number1 is greater than number2, number1 is the maximum number; otherwise, number2 is greater than or equal to number1.

A:

Exercise 1:

 Take a piece of paper and a pencil. Write number1 on the left side of the paper and number2 on the right side of the paper  graphics/ccc.gifand Greatest number below on the middle of the page. Write the number that number1 represents underneath number1. Write the number that number2 represents underneath number2. If the number associated with number1 is greater than the number associated with number2  graphics/ccc.gifwrite this former number underneath Greatest number otherwise write the number associated  graphics/ccc.gifwith number2 under Greatest number. 
2:

Write the pseudocode for an algorithm that determines the maximum number in a given list of numbers. The list can contain any amount of numbers. Hint: Keep a variable called maxSoFar (written on the paper, with zero as the initial value). Go through the list one by one and compare each number with maxSoFar. Any number found to be greater than maxSoFar becomes equal to maxSoFar. At the end of the list, maxSoFar represents the largest number in the list.

A:

Exercise 2:

 1. Take a piece of paper and a pencil. 2. Write maxSoFar with a zero underneath. 3. Repeat the following action (3.a) for each value in the list: 3.a. If the current value we are focusing at in the list is greater than the value  graphics/ccc.gifwritten under maxSoFar then put a line through this previous number and write the greater  graphics/ccc.gifvalue under the old crossed out number. 4. The value written furthest down that is not crossed out is the largest number in the  graphics/ccc.giflist of numbers. 
3:

Change the average-calculating pseudocode in the section "Algorithms and Pseudocode" so that it doesn't perform division by zero, even when no numbers are provided.

A:

Exercise 3: Change point 4 of the pseudocode to the following:

 4. If the ListSize is greater than 0 then         divide the Sum by the ListSize and write the number down     otherwise if the ListSize is 0 then simply write the 0 down. 
4:

Write, compile, and run a C# program that writes the following on the console:

 Our alien friend lives on planet Blipos far far away 
A:

Exercise 4:

 using System; public class StoryTeller {     public static void Main()     {         Console.WriteLine("Our alien friend");         Console.WriteLine("lives on planet Blipos");         Console.WriteLine("far far away");     } } 


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net