Previous Chapter

 http://itechplatform.blogspot.com.ng/

Telling the Computer What to Do

A computer program, also called software, is a way to tell a computer what to do. Everything that the computer does, from booting up to shutting down, is done by a program. Windows XP is a program. Ms. Pac-Man is a program. The dir command used in MS-DOS to display file names is also a program. Even the Klez email worm is a program.
Computer programs are made up of a list of commands the computer handles in a specific order when the program is run. Each of these commands is called a statement.
If you're a science fiction fan, you're probably familiar with the concept of household robots. If not, you might be familiar with the concept of henpecked spouses. In either case, someone gives very specific instructions telling the robot or spouse what to do, something like the following:
  • Dear Theobald,
  • Please take care of these errands for me while I'm out lobbying members of Congress:
  • Item 1: Vacuum the living room.
  • Item 2: Go to the store.
  • Item 3: Pick up butter, lozenges, and as many bottles of Heinz E-Z Squirt green ketchup as you can carry.
  • Item 4: Return home.
  • Love,
  • Snookie Lumps
If you tell a loved one or artificially intelligent robot what to do, there's a certain amount of leeway in how your requests are fulfilled. If lozenges aren't available, cough medicine might be brought to you instead. Also, the trip to the store can be accomplished through a variety of routes. Computers don't do leeway. They follow instructions literally. The programs that you write will be followed precisely, one statement at a time.
The following is one of the simplest examples of a computer program, written in BASIC. Take a look at it, but don't worry yet about what each line is supposed to mean.
1 PRINT "Shall we play a game?" 
2 INPUT A$ 
Translated into English, this program is equivalent to giving a computer the following to-do list:
  • Dear personal computer,
  • Item 1: Display the question, "Shall we play a game?"
  • Item 2: Give the user a chance to answer the question.
  • Love,
  • Snookie Lumps
Each of the lines in the computer program is a statement. A computer handles each statement in a program in a specific order, in the same way that a cook follows a recipe, or Theobald the robot followed the orders of Snookie Lumps when he vacuumed and shopped at the market. In BASIC, the line numbers are used to put the statements in the correct order. Other languages, such as Java, do not use line numbers, favoring different ways to tell the computer how to run a program.
Figure 1.1 shows the sample BASIC program running on the Liberty BASIC interpreter, a shareware program that can be used to develop Windows and OS/2 programs. Liberty BASIC, which was developed by Carl Gundel, is among many BASIC interpreters that can be found on the Internet for Microsoft Windows, Apple Macintosh, Unix, and Linux systems. You can find out more about it at http://www.libertybasic.com.
01fig01.gif Figure 1.1 An example of a BASIC program running in Liberty BASIC.
Because of the way programs operate, it's hard to blame the computer when something goes wrong while your program runs. After all, the computer was just doing exactly what you told it to do. Unless your hardware is on the fritz, a pesky virus is attacking your system, or your operating system is having a bad day, the blame for program errors lies with the programmer. That's the bad news. The good news is that you can't do any permanent harm to your computer with the programming errors you make. No one was harmed during the making of this book, and no computers will be injured as you learn how to program with Java.

Reference: Sams Ebook
Source:informit
Axact

Author

My name is Dave, Am a cool IT Geek, computer analyst and a tutor. I do alot of computer stuffs like programming, web development, blogging, data administrator, computer security and lots more. Feel free to contact me if want more informations and tutorials.

Post A Comment:

0 comments: