|
|
|
|
|
|
|
4. If the number of hours worked is greater than 40, multiply 40 by the pay rate to calculate regular wages, and then multiply the difference between the number of hours worked and 40 by one and a half times the pay rate to calculate overtime wages. |
|
|
|
|
|
|
|
|
5. Add the regular wages to the overtime wages (if any) to determine total wages for the week. |
|
|
|
|
|
|
|
|
The steps the computer follows are often the same steps you would use to do the calculations by hand. |
|
|
|
|
|
|
|
|
After developing a general solution, the programmer tests the algorithm, walking through each step mentally or manually. If the algorithm doesn't work, the programmer repeats the problem-solving process, analyzing the problem again and coming up with another algorithm. Often the second algorithm is just a variation of the first. When the programmer is satisfied with the algorithm, he or she translates it into a programming language. We use the C++ programming language in this book. |
|
|
|
 |
|
 |
|
|
Programming Language A set of rules, symbols, and special words used to construct a program. |
|
|
|
|
|
|
|
|
A programming language is a simplified form of English (with math symbols) that adheres to a strict set of grammatical rules. English is far too complicated a language for today's computers to follow. Programming languages, because they limit vocabulary, are much simpler. |
|
|
|
|
|
|
|
|
Although a programming language is simple in form, it is not always easy to use. Try giving someone directions to the nearest airport using a vocabulary of no more than 45 words, and you'll begin to see the problem. Programming forces you to write very simple, exact instructions. |
|
|
|
|
|
|
|
|
Translating an algorithm into a programming language is called coding the algorithm. The product of that translationthe programis tested by running (executing) it on the computer. If the program fails to produce the desired results, the programmer must debug itthat is, determine what is wrong and then modify the program, or even the algorithm, to fix it. The combination of coding and testing an algorithm is called implementation. |
|
|
|
|
|
|
|
|
There is no single way to implement an algorithm. For example, an algorithm can be translated into more than one programming language. Each translation produces a different implementation. Even when they translate an algorithm into the same programming language, different people are likely to come up with different implementations (see Figure 1-2). Why? Because every programming language allows the programmer some flexibility in how an algorithm is translated. Given this flexibility, people adopt their own styles in writing programs, just as they do in writing short stories or es- |
|
|
|
|
|