introduction to qbasic

Introduction to Qbasic
Introduction to Qbasic
Introduction to Qbasic
Introduction to Qbasic
Introduction to Qbasic
Download Introduction to Qbasic

Post on 10-Oct-2014

52 views

Category:

Documents

8 download

Embed Size (px)

TRANSCRIPT

PREFACEThese notes are an introduction to computer programming using the language QBasic. The twenty-four chapters will give you an idea of what programming is all about. If you faithfully work your way through all the chapters, you will learn how all the gritty details that programming involves add up to the wonderful things called "programs." You will be able to write some simple programs yourself. These notes are about programming, but they do not try to make you a programmer. Their goal is to increase your understanding of computers in the modern world. If you are thinking about becoming a programmer, studying these notes is a good first step. However, these notes are aimed at students who are not computer science majors. Details have been kept to a minimum.Chapter Topics: How

to use these notes. Why study QBasic?

Active LearningStudying a technical subject such as programming can get awfully dull. To make it interesting, use what you have learned as soon as you learn it. One way to do this is to pause and think for a while after every few paragraphs. The questions encourage you to do just that. When you encounter a question, stop and think about it, even if it is an easy question. Most questions are about the material that has just been presented. Some of them have you complete part of a small program, or work out a small problem. By reading and answering the questions you will achieve two things: You

will be engaged in active learning. o Active learning keeps your brain engaged. The material will be more interesting, and you will learn it better. You will be monitoring you own progress. o As you compare your answers to the suggested answers you will see how well you are doing.

Thousands and Thousands of Languages.Many thousands of computer languages have been invented. There are several hundred languages still actively being used. This sounds like a terrible situation, but it is not, because of:Two Facts about Computer Languages:

1. All computer programming languages are fundamentally the same. o All programmers have the same fundamental understanding of programming, regardless of what particular programming language they use. 2. Any program can be written with any programming language. o However, some languages are more effective for some types of programs. It is hard to explain why these two things are true without going into details. A (rather crude) analogy is that computer programming is like music:Two Facts about Music:

1. All music is fundamentally the same: it consists of musical tones and rhythm. o All musicians have the same fundamental understanding of music, no matter what instrument they play. 2. Any song can be played on any instrument. o However, a lullaby is not effective when played upon drums. All programming languages contain the same fundamental features. You will see all of these features in this course. (There are surprisingly few fundamental features.) The difference between languages is mostly a matter of emphasis and convenience.

Basic BASICThe language BASIC was designed in the early 1960s for teaching the basic principles of programming to non-science majors. It has been popular ever

since. There are many versions of BASIC. These notes use QBasic, a version that once came free with Microsoft operating systems. With QBasic you can easily write small programs and get the idea of what programming is about. Other versions of BASIC are intended for professional programmers who expect to write programs that are many thousands of lines long. Our programs will not get that long.

QBasic on your ComputerIf your computer is running any variety of a Microsoft operating system, it can run QBasic. If your computer is running DOS or Windows 3.1 it already has QBasic. Microsoft Windows 95, Windows 98, and Windows NT operating systems may have QBasic if it was chosen when the operating system was installed. Microsoft Windows ME, Windows 2000, and Windows XP do not come with QBasic (but it can be installed on these systems. See below). To check if your computer has QBasic:

1. Find the Command Prompt on your computer.

If you are running DOS, this is the prompt that asks you for commands. o If you are running Windows 3.1, find the "DOS prompt icon." This is usually in the Main window. The icon is a little picture of the letters MSDOS. Double-click on the icon. o If you are running a more recent operating system, click on the "Start" button. Click on "Run" In the "Open" box, enter CMD Click "OK" (or hit "Enter") 2. When you get a window with the prompt, enter the command: qbasic then press the ENTER key.o

3. QBasic should start up. The pictures in CHAPTER 1 show what you should see. If you can not find QBasic after doing the above, you might still have it on your system. Browse through your disk, use "search" from the start menu (look for qbasic.exe), or maybe look at the documentation. To get a copy of QBasic from the web, go to: http://www.devedia.com/dosghost/dos/dos_vers.asp#olddos Details about downloading and installing QBasic are given in Appendix A. Additional information about QBasic (including suggestions for downloading) can be found at http://www.qbasic.com. (These links worked as of September 25, 2004.) If you can't find QBasic, you can still read these notes. They won't be as interesting, but because of the active learning you will still be writing some small programs. If you are an Internet ace, you could try the microsoft web pages for a downloadable copy of QBasic.

CHAPTER 1 Small ProgramsIn this chapter you will learn to write small programs in the computer programming language called QBasic. These small programs won't do very much. But in following chapters you will write programs that do much more.Chapter Goals QBasic

statements. The PRINT statement. The END statement. Arithmetic operators. Strings. Sequential execution. Syntax errors. Bugs. The small programs in this chapter perform calculations similar to the arithmetic done with a electronic calculator. QBasic does much more than

that. But in this chapter, pretend that QBasic is a calculator that uses a keyboard for input. Instead of punching buttons on a calculator, you will write a program.