Chapter 1: Problem Solving
Introduction
In order to write a program for a computer, the programmer must know what the program is going to do, how it will do it, and what it the input and output of the program will be. In order to do this, the programmer must have problem solving skills. For simple programs, the programmer will just need basic problem solving skills. These problem solving skills will improve as the programmer gains experience in programming.A programmer could come against a problem as simple as how to display a letter on the screen to something as complex as making a robot walk across a room or flying the space shuttle. Displaying a letter on the screen is very easy in most languages and can be solved by all programmers, as long as the programmer knows the basic commands of the language. Flying the space shuttle is a slightly different story. It takes a team of NASA programmers many months to solve the complex problems that are encountered by flying the space shuttle.
The beginner programmer must also realize that there is usually more than one way to solve a particular problem. For instance, there are at least five ways to write a letter on the screen in the language Qbasic; which way the programmer chooses to display a letter on the screen would depend upon the specifics of the problem or even the personal preferences of the programmer.
How to Solve Problems
There are many ways to solve problems. A problem can usually be solved if enough information is known about the problem. If a person is given a problem that requires a specific answer, the programmer must know how to get the required information from the problem in order to get an answer. It is similar to driving from one location to another. The person must know where to start and where to finish, and any places to visit on the trip.Let's take the problem of taking a trip from Florida to New York. A person who wishes to solve this problem must know first exactly where they are in Florida and where in New York they wish to visit. Next, they need to know what means of travel they will take (can they walk, drive, fly, take a boat, etc). They will also need to know where they wish to stop while traveling to New York. Some other things to consider are how long they wish to be traveling, how much money they have for the trip, and possibly how much luggage they wish to take. All or most of these questions must be answered before the trip should ever take place and then when certain questions are answered (such as means of travel), it could bring up more questions as which direction to travel or which roads to travel. As with most problems, there are many ways to travel from Florida to New York. The same is true with computer programming. Sometimes there are restrictions on the problem, such as taking the shortest route from Florida to New York, which could restrict the number of answers down to a few. This is also true with computer programming. As the traveler gains experience, they will know the best way to travel from Florida to New York and will also know the best places to stop on the way. Computer programmers also gain experience as they solve computer related problems.
There is no set way to solve a given computer problem. Each problem is different and therefore requires a different way to find a solution. Here are a few guidelines that a programmer should go through for each problem.
Read. Most of the time important information is enclosed in the description of the problem. The problem should be read until the programmer understands what is requested.
Understand. The programmer must be able to understand the problem completely before telling the computer how to solve the problem. The programmer must be able to put the solution in a very specific series of steps so the computer can produce the desired answer.
Ask. If not enough information is given in the description of the problem, ask questions to someone who may know how to solve the problem or to the person who produced the problem. Two heads are almost always better than one! Books and the Internet are also useful resources if another person is not available.
Think. Think of how a simpler problem could be applied to help solve this problem. Most of the time a harder problem is just a collection of simpler problems. For example, multi-digit multiplication contains simpler problems such as single-digit multiplication as well as addition. It is not always possible to come up with an easy solution to a problem.
Solve. If the programmer can produce a solution by hand, then a program can be more easily produced. If the programmer has no idea how to solve the problem, how will the programmer be able to tell the computer how to solve it?
Choose. Choose the language that best helps solve the problem or use the language the programmer already knows. If the programmer only knows Fortran, but the best language to use is Cobol, then the programmer should attempt (not all problems can be solved in every language) to produce the solution in Fortran, unless the programmer wishes to learn Cobol.
Code. Produce the program in the chosen language and make sure it is free from errors.
Test. Make sure the program produces the correct answers, if not, the problem should be thought through more carefully and redone. The reason to solve the problem was to get the correct answer, not incorrect answers.
No comments:
Post a Comment