• No results found

OBJECTIVES In this chapter we provide an introduction to computing and engineering problem solving, including:

4. ALGORITHM DEVELOPMENT

Once you can work the problem for a simple set of data, you are then ready to develop an algorithm, or a step-by-step outline, of the problem solution. For simple problems such as this one, the algorithm can be listed as operations that are performed one after another.

This outline of steps decomposes the problem into simpler steps, as shown by the following outline of the steps required to compute and print the distance between two points.

Decomposition Outline

1. Give values to the two points.

2. Compute the lengths of the two sides of the right triangle generated by the two points.

3. Compute the distance between the two points, which is equal to the length of the hypotenuse of the triangle.

4. Print the distance between the two points.

This decomposition outline is then converted to C++ commands so that we can use the computer to perform the computations. From the following solution, you can see that the commands are very similar to the steps used in the hand example. The details of these commands are explained in Chapter 2.

/*---*/

/* Program chapter1_1 */

/* */

/* This program computes the */

/* distance between two points. */

Summary 29

#include<iostream>//Required for cout

#include<cmath>//Required for sqrt() using namespace std;

int main() {

// Declare and initialize objects.

double x1=1, y1=5, x2=4, y2=7, side1, side2, distance;

// Compute sides of a right triangle.

side1 = x2 - x1;

side2 = y2 - y1;

distance = sqrt(side1*side1 + side2*side2);

// Print distance.

cout << "The distance between the two points is"

<< distance << endl;

// Exit program.

return 0;

}

/*---*/

5. TESTING

The final step in our problem-solving process is testing the solution. We should first test the solution with the data from the hand example because we have already computed the solution. When the C++ statements in this solution are executed, the computer displays the following output:

The distance between the points is 3.60555

This output matches the value that we calculated by hand. If the C++ solution did not match the hand solution, then we should review both solutions to find the error. Once the solution works for the hand example, we should also test it with additional sets of data to be sure that the solution works for other valid sets of data.

The set of steps demonstrated in this example are used in developing the programs in the Problem Solving Applied sections in the chapters that follow.

SUMMARY

A brief history of the development of the digital computer was provided, followed by a group of outstanding recent engineering achievements to demonstrate the diversity of engineering applications, and the impact of computers in engineering. We also discussed some of the non-technical skills required to be a successful engineer. Because the solutions to most engineering problems will be by computer, we presented a summary of the components of a computer system, from computer hardware to computer software and the importance of learning the new terminology. We also discussed number systems and data representation and introduced

30 Chapter 1 Introduction to Computing and Engineering Problem Solving

a five-step problem-solving methodology that we will use to develop a computer solution to a problem. These five steps are as follows:

1. State the problem clearly.

2. Describe the input and output information for the problem.

3. Work the problem by hand (or with a calculator) for a simple set of data.

4. Develop an algorithm and convert it to a computer program.

5. Test the solution with a variety of data.

This process will be used throughout the text as we develop solutions to problems.

Key Terms

Summary 31

Problems Exam Practice!

True/False Problems

Indicate whether the following statements are true (T) or false (F).

1. A CPU consists of an ALU, memory, and a processor.

2. Linking and loading is the step that prepares the object program for execution.

3. An algorithm describes the problem solution step by step, while a computer program solves the problem in one step.

4. A computer program is the implementation of an algorithm.

Multiple-Choice Problems

Circle the letter for the best answer to complete each statement, or for the correct answer to each question.

5. Instructions and data are stored in (a) the arithmetic logic unit (ALU).

(b) the control unit (processor).

(c) the central processing unit (CPU).

(d) the memory.

(e) the keyboard.

6. An operating system is

(a) the software that is designed by users.

(b) a convenient and efficient interface between the user and the hardware.

(c) the set of utilities that allow us to perform common operations.

(d) a set of software tools.

7. Source code is

(a) the result of compiler operations.

(b) the process of getting information from the processor.

(c) the set of instructions in a computer language that solve a specific problem.

(d) the data stored in the computer memory.

(e) the values entered through the keyboard.

8. An algorithm refers to

(a) a step-by-step solution to solve a specific problem.

(b) a collection of instructions that the computer can understand.

(c) a code that allows us to type in text materials.

(d) stepwise refinement.

(e) a set of math equations to derive the problem solution.

9. Object code is

(a) the result of compiler operations on the source code.

(b) the process of obtaining information from the processor.

(c) a computer program.

(d) a process involving the listing of commands required to solve a specific problem.

(e) the result of the linking and loading process.

32 Chapter 1 Introduction to Computing and Engineering Problem Solving 10. Convert the following binary numbers to octal.

(a) 110110101 (b) 111101001101111 (c) 1010111001 (d) 1000000001 (e) 111111111

11. Convert the following binary numbers to hexadecimal.

(a) 100010101011 (b) 1110011111110101 (c) 1010111001 (d) 1000000000000001 (e) 111111111111

12. Convert the following decimal numbers to octal.

(a) 1292 (b) 607 (c) 9350 (d) 1000010 (e) 1111111

13. Convert the following numbers to base 10.

(a) 110101012

The following problems combine an assignment in which you will learn more about one of the topics in this chapter with an opportunity to improve your written communication skills.

(Perhaps your professor will even select some of the written reports for oral presentation in class.) Each report should include at least two references, so you will want to learn how to use library computers to locate reference information. Prepare your report using word-processor software. If you do not already know how to use a word processor, ask your professor for guidance or visit your university’s Web site for links to resources on campus.

14. Write a short report on one of these outstanding engineering achievements:

Analytical Engine

A good starting point for finding references is the World Wide Web and your local library.

Summary 33 15. Write a short report on one of these engineering challenges:

Predication of weather, climate, and global change Computerized speech understanding

Mapping of the human genome Improved vehicle performance

A good starting point for finding references is the NASA Web site: www.nasa.gov 16. Write a short report on an outstanding engineering achievement that is not included

in the list given in this chapter. Past issues of Scientific American and the Web would provide some good ideas of recent achievements.

2