Alert: You are not allowed to copy content or view source
Check Exam Dates here | See Marking Scheme here | Frequently Asked Questions (FAQs) | Buy Practice Papers for CREST Olympiads here | Last Date for CREST Reasoning Olympiads (CRO) Registration is 20th June 2019 | CREST Reasoning Olympiads (CRO) is scheduled for June/July. Apply now

Programming in QBasic

Programming in QBasic
  • To start with QBasic is - Quick Beginners All Purpose Symbolic Instruction Code.
  • QBasic has both integrated development environment as well as interpreter to run a variety of BASIC programming languages.
  • These languages are based on QuickBASIC.
  • We need QBasic interpreter to execute QBasic program.

First program

  • You have to initially launch the QBasic interpreter.
  • Where you might see a window requesting a list of "parameters."
  • Once the window opens up, hit the Enter key to continue.
  • You will now be able to see the QBasic interpreter, which has a blue background.
  • The blue background displays a dialogue box at the centre.
  • To make the screen smaller, press "Alt +Enter”.
  • To hide the dialogue box, press the Esc key.

  class

  • Type the following in the QBasic interpreter:
  • PRINT "Hello World!"
  • To run the program, press F5.
  • You will now see the output on a black screen.
  • You will find Hello World at the top, and you can press any key to continue at the bottom.
  • You can also press any key on the keyboard to return to the main screen.
  • It the program is run again, the interpreter adds another Hello World.

  class

Deleting the program

Follow the below steps to erase the current program:

  1. Go to the "File" menu and the click "New."
  2. You will be prompted asking if you want to save the program.
  3. If you want to delete the file, click on “No”.

  Strings

  • Strings are certain types of data or information.
  • Strings can contain a sequence of characters such as letters, numbers, and symbols which are enclosed in quotation marks.
  • For example, "Hello World!" is a string.

Few more examples – The following are also strings:

"0123456789"

"This is a string"

"abc123"

"1 + 1 = 2"

"[email protected]#$%^&*()"

 

When a dollar sign ($) is added to the end of a variable, then it is a string.

Example –

X$ = "Hello World!"

PRINT X$

Output:

Hello World!

 

Commands

  • As the word indicates, a "command" instructs the QBasic interpreter to perform some instructions.
  • We also have a command to print on the output screen.
  • Using PRINT command we can instruct the QBasic interpreter to print something to the screen.
  • In this case, the interpreter printed "Hello World!”
  • Example –

PRINT 512 (or?512)

 

Now press F5 to run the program.

The program outputs: 512

Expressions

  • Expression helps in performing the mathematical calculation.
  • Example:

2 + 2 (returns 4)

10 - 4 (returns 6)

3 * 34 (returns 102)

  • To refresh or clear the output screen, use the CLS command.
  • To insert spaces between the two words put a comma instead of a semi-colon.

Example –

PRINT "Hello",

PRINT "World"

Output:

Hello World

Variables

  • Variables are information (or just a bit of information) stored on computer's memory.
  • The location or the area where the variable is stored in RAM is called the "address."

  class

The IF and THEN commands

  • These commands are used to compare an expression.
  • Based on the expression they perform actions.

x = 5, IF x = 5 THEN PRINT "x equals 5"

Since X does equal 5 in this case, the program outputs:

x equals 5

Expression signs

You can also enter the following statements, instead of the equals sign:

x < 5 (x is less than 5)

x > 5 (x is greater than 5)

Run the following:

x = 16

IF (x > 5) THEN PRINT "x is greater than 5"

Output:

x is greater than 5

Labels and the GOTO and GOSUB commands

  • To move to a certain line in your program, you can use the GOTO and GOSUB command.
  • To specify which point to be executed in the program we have labels.

Example –

GOTO

Run the following example program:

PRINT "1"

GOTO TheLabel

PRINT "2"

TheLabel:

PRINT "3"

Output (notice how PRINT "2" is skipped):

1

3

 LOOPS

  • To make an action repeat multiple times, we use "Loops".
  • We have four types of loops:
    • ..GOTO
    • ..WEND
    • ..LOOP
    • ..NEXT

STOPPING LOOPS

  • When the program is on loop and to stop the loop before the execution use the EXIT command, followed by either FOR or DO.

FOR x = 1 TO 5

PRINT x

IF (x = 2) THEN EXIT FOR

NEXT x

Output:

1

2

Recap

Programming in QBASIC

  • To start with QBasic is - Quick Beginners All Purpose Symbolic Instruction Code.

First program

Deleting the program

Strings

Commands

Expressions

Variables

The IF and THEN commands

Labels and the GOTO and GOSUB commands

Loops

Stopping loops

Quiz for Programming in QBasic

Q.1

Who was the first Scientist to develop QBASIC?

a) Tom Kurtz
b) Albert Einstein
c) Thomas
d) Bill Gates

Q.2

A quantity that does not change its value during the execution of the program is called as _______?

a) Expressions
b) String
c) Variable
d) Constant

Q.3

Which of the following are not allowed in a numeric constant?

a)

Constants

b)

Strings

c)

Command

d)

Comment

Q.4

It consists of sequence of characters which must be enclosed by quotation mark. It is known as _______?

a) Numeric Variable
b) Numeric Constant
c) String Variable
d) String Constant

Q.5

A data type that cannot be used for mathematical operations is?

a) String
b) Long
c) Varchar
d) Integer

Q.6

A command or an instruction in Qbasic is called as?

a) Variable
b) Comment
c) Program
d) Statement

Q.7

Variables without a dollar sign can?

a) hold strings
b) hold numbers
c) hold constants
d) hold variables

Q.8

The arithmetic operator which is used for integer division is _______?

a)
b)
c) /
d) =

Q.9

Which of the following is not a reserved word or contain a space?

a) Numbers
b) Strings
c) Constants
d) Variable

Q.10

These are formed from the character of the Qbasic character set. They are known as?

a) Reserved Word
b) Variable
c) Constants
d) Numbers

Your Score: 0/10

Other Chapters of Class 7

  EXPLORE  

70%