I am a computer science student and need to learn BASIC programming language. Please any help?
BASIC was an early programming language that is still among the simplest and most popular of programming languages. BASIC stands for "Beginner's All-purpose Symbolic Instruction Code." Originally designed as an interactive mainframe timesharing language by John Kemeney and Thomas Kurtz in 1963, it became widely used on personal computers everywhere. On IBM's first "family" computer, the PCJr, a BASIC cartridge was a popular add-on. Because of its simplicity, BASIC has frequently been used in teaching the introductory concepts of programming with a working language.
Hundreds of thousands of computer professionals have had their first introduction to computer programming by way of the BASIC language. It is not necessarily the best language for teaching beginners, but it does have a couple of things to recommend itself. Among them, the fact that it is available freely on Windows in the form of Microsoft QBASIC, which is still included on Windows98 Second Edition, although it is hidden away in \WIN98\TOOLS\OLDMSDOS. Just copy QBASIC.EXE to C:\WINDOWS and you are in business. (But you would be well advised to also take HELP.EXE, HELP.HLP and QBASIC.HLP). In the following, I am assuming that you are running QBASIC under MS Windows.
BASIC continues to be widely used because it can be learned quickly, its statements are easy to read by other programmers, and support is available on most operating systems. BASIC's documentation has been translated into many national languages. It often comes with sound and graphics support. A popular version of BASIC today is QBASIC.
BASIC is used in many business applications and is still considered a valid choice as a programming language for some purposes. Microsoft's Visual Basic adds object-oriented features and a graphical user interface to the standard BASIC.
It is traditional to illustrate the flavor of a programming language by showing a small program that displays the words "Hello World!". In BASIC, that could look like this:
10 PRINT 'Enter a number'
20 INPUT NUM
30 PRINT 'Your number * 10 is ';NUM*10;
The following example of BASIC gets a number from a user, multiplies the number by 10, and prints or displays the result:
100 REM This is a sample BASIC program
110 PRINT "HELLO WORLD!"
But before we get too far ahead, let me scale down your expectations a bit. BASIC was invented and in widespread use before computers had windows, in fact before they had display screens. The world in which BASIC came to life, was one in which only one program at a time was running on the computer, and it used a teletype terminal (a kind of electric typewriter) to talk to the user. In some cases, the terminal was connected to a large computer via a modem and a telephone line, but each user saw BASIC as a small computer that he alone used. QBASIC runs in an MS-DOS command window and tries to make windows look like that nostalgic vision. There are newer and fancier BASIC versions for windows (called Visual Basic) that will draw real windows with dialog boxes and buttons, but we are trying to keep things simple for now, so the restrictions suit us just fine.
The BASIC instructions in this program are:
100 REM This is a simple BASIC program
REM is short for remark, what other programming languages call a comment. It does not do anything, but allows you to put an explanation into the program, for the benefit of someone reading the program later. (Which could be yourself. It is remarkable, how cryptic your program can seem 6 months later, when you want to make a small change.)
110 PRINT "HELLO WORLD!"
PRINT writes something on the screen. The things to write are put between quote marks to distinguish them from the program.
SYSTEM is not standard BASIC, but is part of QBASIC. It means to leave the program and go back to the operating system (DOS or WINDOWS). In other versions of BASIC, the preferred word is STOP, EXIT or END. In QBASIC, STOP brings up the QBASIC program editor, even if you did not start the program from there. In QBASIC, END works somewhere in between SYSTEM and STOP. (In some other versions of BASIC, everything after END is thrown away.)
There are several ways to run QBASIC. The first and simplest would be to
and then from the MS-DOS command line type
QBASIC /RUN HELLO
If you typed the program correctly, you would see the message and a new C:\mybasic> prompt.
The next step would be to just type QBASIC. This starts QBASIC and gives you the choice between seeing a help file and starting to work in QBASIC. This time, take the latter option, by hitting the ESC key (upper left corner of your keyboard). This puts you on a blue window where you can type/edit programs. Now click on File in the upper left corner of the window, select Open and click on HELLO.BAS and click on . This brings up the program on your blue window. You can now change it. Click on the W in WORLD and type your first name, the word "and" and spaces on both sides of "and". Then click on Run and Start at the menu bar on top of the screen.
Here is a more complex program:
100 REM This program reads and writes
110 PRINT "What is your name";
120 INPUT name$
130 PRINT "Hi, ";name$;"!"
140 PRINT "Please type a number";
150 INPUT num1
160 PRINT "Please type another number";
170 INPUT num2
180 PRINT name$;", do you know how much ";num1;" plus ";num2" add up to?"
190 PRINT "Please type the sum here";
200 INPUT num3
210 IF (num3 = (num1 + num2)) then
220 PRINT "Very good, ";name$;", that is correct!!"
240 PRINT "I'm sorry, that is not correct."
250 PRINT num1, "plus", num2, "is", num3
260 END IF
This program introduces the concepts of
Let's look at each of these in turn.
In order to do useful things, programs need to work on information. A variable is a memory cell that has a name and can hold a value. In basic, we have three kinds of values:
A general number is just what it sounds like. These variables can have values such as 27, 274,327, -6 or 3.14159; their names are words.
A whole number cannot have a decimal point. If you try to stick a decimal fraction into it, it gets rounded off to the nearest whole number. Their names end with a percent sign.
A string is any sequence of symbols, although you will have to jump through hoops to get some punctuation marks into them. Their names end with a dollar sign.
In the example above, name$ is a string, while num1, num2 and num3 are general numbers.
In BASIC, the INPUT command puts out a question mark and then reads from the keyboard. If more than one variable is being read, the values are separated by commas. This works really well, but makes it hard to read commas. The input ends with typing the "ENTER" key.
The IF statement allows you to make decisions and choose between different things to do, depending on the values of variables. Between the words IF and THEN is a calculated value that must be true or false. If it is true, the first group of statements is executed (from THEN to ELSE). If it is false, the second group is executed (from ELSE to END IF). Sometimes, there is no need for an ELSE, and you can use the simpler form
IF (test) THEN
You can print more than one thing with a single PRINT statement. If you have several items to print, you can separate them with either commas or semicolons.
If you choose commas, BASIC will choose the way they are printed, line them up in columns, make sure there is some space between them and switch to a new line when the line is full.
If you choose semicolons, BASIC will print exactly what is in the variable, and it is up to you to make sure there is space between the items, or that the lines do not get too long. If the P