0% found this document useful (0 votes)
2 views21 pages

Computer Notes

The document provides comprehensive notes on QBasic, covering fundamental concepts such as computer programs, statements, syntax, and the BASIC programming language. It details QBasic features, including its IDE, data types, keywords, and various programming constructs like variables, conditional statements, and input/output operations. Additionally, it includes examples and exercises to reinforce learning and understanding of QBasic programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views21 pages

Computer Notes

The document provides comprehensive notes on QBasic, covering fundamental concepts such as computer programs, statements, syntax, and the BASIC programming language. It details QBasic features, including its IDE, data types, keywords, and various programming constructs like variables, conditional statements, and input/output operations. Additionally, it includes examples and exercises to reinforce learning and understanding of QBasic programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

QBasic Computer Notes

Aditya Bhattacharjee
September 2023

1
What is a computer program?
A computer program is a set of instructions or a sequence of coded commands that tells a computer
how to perform a specific task or solve a problem. It is a precise set of instructions written in a
programming language that can be executed by a computer to produce a desired output or result.

What is a statement?
In computer programming, a statement is a complete instruction that performs a specific action or
operation. It is a fundamental unit of code that represents a single executable command within a
program.

What is a syntax?
In computer programming, syntax refers to the set of rules and conventions that dictate the structure,
format, and placement of individual elements and statements within a programming language. It
defines how code should be written and organized to be considered valid and understandable by the
programming language compiler or interpreter.

What is BASIC?
BASIC (Beginner’s All-purpose Symbolic Instruction Code) is a high-level programming language
that was designed in the 1960s to make programming more accessible to beginners and non-experts.
It was developed at Dartmouth College by John G. Kemeny and Thomas E. Kurtz as an educational
language.

What is QBasic?
QBasic is a programming language developed by Microsoft in the early 1990s. It stands for ”Quick
Beginners All-purpose Symbolic Instruction Code.” QBasic is based on the BASIC programming
language and was designed to be easy to learn and use, especially for beginners and hobbyists.

2
Features of QBasic?
• Simple Syntax: QBasic has a straightforward and easy-to-understand syntax, making it
accessible to beginners. It uses plain English keywords and minimal punctuation, allowing
users to focus on learning programming concepts rather than complex language constructs.
• Integrated Development Environment (IDE): QBasic includes an integrated develop-
ment environment with a text editor, debugger, and compiler. This makes it convenient for
writing, testing, and running programs in a single environment.

• Structured Programming Support: QBasic supports structured programming concepts


such as loops, conditionals, and subroutines. These features enable the organization and
modularization of code, making it easier to write and maintain programs.
• Graphics and Sound Capabilities: QBasic provides built-in commands for creating simple
graphics and sound effects. This makes it suitable for developing simple games and interactive
applications.
• Event-Driven Programming: QBasic supports event-driven programming, allowing users
to respond to user input or system events such as mouse clicks or key presses. This enables
the creation of interactive and responsive applications.
• Compatibility with DOS: QBasic is designed to run on the DOS operating system, making
it compatible with older computer systems. It can be run directly from the command line or
as a standalone executable.
• Educational Resources: QBasic has a wealth of educational resources available, including
tutorials, sample programs, and documentation. This makes it an excellent choice for learning
programming concepts and practicing coding skills.

What are Keywords?


In computer programming, keywords are reserved words that have special meanings within the
programming language. These words are predefined and cannot be used as identifiers (such as
variable names or function names) because they serve specific purposes and have specific functionality
in the language.
Example: CLS, PRINT

3
Screens
QBasic IDE as two screens.
Program Area/Editor Screen: This is the main area where you write your QBasic code. It is a
text editor where you can enter your program line by line.
• The place where we type the Qbasic instructions/statements.
• Every statements is typed on a new line
• All the reserved keywords are automatically capitalised.

Figure 1: Editor Screen

Output Window: When you run a QBasic program, any output or error messages are displayed in
the output window. It shows the results of your program’s execution or any messages generated
during runtime.
• This is the screen where we see the output for the program.
• We can see the output screen after pressing the F5 function key on the keyboard.
• The output screen is divided into 5 zones which are not visible on the output screen.
• Pressing any key, takes us back to the EDITOR SCREEN

Figure 2: Output Screen

4
CLS Keyword
The CLS keyword in QBasic is used to clear the screen. It stands for ”Clear Screen.” When the CLS
command is executed in a QBasic program, it clears the entire contents of the screen, removing any
text or graphics that were previously displayed.

Data Types
QBasic supports numeric and string data types. Numeric data can be both negative and positive.
It can also be integer and decimal. String data contains alpha-numeric data enclosed with double
quotation mark.

Numeric Data
Postive: 52, 42, 746
Negative: -3, -341, -89
Integer: 3, 4, -20

Decimal: 12.2, 3.14, 2.17

String
• ”one”

• ”4”
• ”%”
• ”@[Link]”

• ”#202G”

Note: A Number enclosed with double quotation mark is considered as a string.

5
Print Keyword
The print statement also known as display statement is used to display data in the output console.
The print statement can display both numeric and alpha-numeric data.

SYNTAX

PRINT data/ expression


Examples Output
PRINT 100 100
PRINT 20*50*60 130
PRINT 60*2 120
PRINT ”NHPS” NHPS
PRINT ”My School name is NHPS” ”My School name is NHPS”

Print statement with semicolon


To display multiple values on a line, delimiters like semi-colon ; is used. Semi-colon ; will display
the values next to each other. For numeric data a single space is padded around the numeric data.
If a numeric data follows a numeric data, no additional space is padded.

Example

PRINT 15;" AUGUST ";2022


Output:
15 AUGUST 2022

6
Input Statement
1. In QBASIC, the INPUT statement is used to accept user input. It prompts the user for input
and stores the value entered by the user into a variable.
2. It is called as the interactive assignment statement.
3. It accepts keyboard inputs during the program execution.

4. It temporarily halts the programs and waits for the data entry.

Input delimiter
1. With ; a question mark appears next to the message prompt in the output screen. Enter
your name?
2. With , the cursor blinks right next to the message prompt. Enter your name
3. Input statement without ; or , Following error message appears:

4. Only Input without prompt:

(a) ‘Input N‘.


(b) A question mark appears with the cursor on the output screen.
(c) ?
5. Input with multiple variables

(a) All variable should be separated by comma.


(b) Example: Input ”Enter 3 numbers”; a, b, c
6. Without comma(,) in between the variables. Gives an error message

7
Syntax

INPUT <Optional -Prompt ><delimiter ><variable >


<Optional-Prompt>: A message or text displayed to the user, to request input or provide
instructions. The prompt is typically presented as a question or statement that prompts the user to
take action or provide information.
<delimiter>: Either can be semicolon ; or comma ,. Semicolon will separate out the prompt
and the user input with a question-mark ?. A comma adds no additional space between the prompt
and user input.
<variable>: Can either be a string or numeric variable. If string, should be preceded by a $
sign.

Example

INPUT "Enter your name :"; name$


PRINT "Hello , " + name$ + "!"
Output:
Enter your name :? Aditya
Hello , Aditya !

8
What is a variable?
Variable is a name of a memory location where data is stored.

How many types of variables are there?


There are two types of variables. Numeric variables to store numeric data and string variable to
store string data. A String variable is suffixed with a dollar sign.
Example: NUM is a numeric variable whereas NAME$ is a string variable.

What are the rules for naming variables?


• A variable should start with an alphabet.
• It contains a combination of alphabets, numbers and a period(.).
• No spaces are allowed in a variable name.

• QBASIC keyword cannot be as a variable name.


• A variable name cannot exceed 40 characters.

Difference between Numeric and String variable


Numeric String
Stores only numeric data Stores only String data
Default value is 0 Default value is empty string
Is not suffixed with $ Suffixed with Dollar
Example NUM = 3 Example NAME$ = ”ADITYA”

9
Let Statement
Let Statement is an assignment statement. It helps in storing / assigning a value to a variable.

Syntax of LET statement

LET variable = data / expression / variable

Example

LET X = 3 'Is valid . Assigning a constant to a variable


X = 3 'Is Valid as LET is an optional Keyword
LET X = 3 * 3 '‘ 'Is valid . Assigning an expression to a variable
Y = X '‘ 'Is valid . Assigning variable to another variable
NAME$ = " ADITYA " 'Valid . Stores a string into a string variable
LET 3 = X 'Invalid . Assigning a variable to a constant
LET 3 * 3 = X 'Invalid . Assigning a variable to an expression

10
Difference between LET and INPUT

LET INPUT
Values are given while writing the program. Values are given while executing the program.
Only one value can be assigned to one
variable in a single statement. Multiple values can be assigned to multiple
variables in one statement.
We can perform calculation using LET
statement. Calculations cannot be performed in Input
statement.

Relational Operators in QBasic:


These operators compare values and return True or False
The expression signs (relational operators) are:

Operator Meaning Example


< Less than 2<3
<= Less than or equal to 2<=3
> Greater than 5>2
>= Greater than or equal to 2>=2
= Equal to 2=2
<> Not Equal to 3<>2

Relational operators are used to compare two values. In programming, especially in languages
like QBasic, these operators play a crucial role in decision-making structures like the IF statement.
The result of a comparison using a relational operator is either TRUE or FALSE.

Condition Evaluation:
When a condition is evaluated using a relational operator, the result is a boolean value: either TRUE
or FALSE.
For example:

• 5 = 5 evaluates to TRUE
• 5 <> 5 evaluates to FALSE
• 3 < 4 evaluates to TRUE

• 10 > 20 evaluates to FALSE

11
Emphasis on Condition Evaluation:
In QBasic, when you use an IF statement, the condition inside the statement is evaluated using
relational operators. The actions inside the IF block are executed only if the condition evaluates to
TRUE.

Start

TRUE
age ≥ 18 Print ”Eligible to vote”

FALSE

Print ”Not eligible to vote”

End

In the flowchart above, the diamond shape represents a condition that’s being evaluated. If the
condition (in this case, age >= 18) is TRUE, the program takes one path (rightwards), and if it’s
FALSE, it takes another path (downwards).

12
Conditional Statement
1. Conditional Statement which checks for only one condition: IF-THEN- ELSE
2. Conditional Statement which checks multiple conditions: IF-THEN- ELSEIF...
3. If statements are used to check conditions in the program.

4. Also called decision making statement.


5. The If...Then...Else statement conditionally executes a statement or group of statements when
the condition evaluates to True and executes another set of statements if the condition evaluates
to False.

Understanding IF .. THEN .. ELSE in QBasic


Imagine you’re playing a game where you have to decide which door to open based on a clue. The
computer checks the clue and tells you which door to open.
In QBasic, we use the IF .. THEN .. ELSE command to help the computer make decisions just
like in our game.

Start

Yes
Is the clue correct? Open Door 1

No
Open Door 2

End

In the game, if the clue is correct, you open Door 1. Otherwise, you open Door 2. In QBasic, we
write this as:

IF clue is correct THEN


PRINT "Open Door 1"
ELSE
PRINT "Open Door 2"
END IF

Just like in our game, the computer checks the clue and decides which door to open!

13
Choosing an Outfit Based on the Weather
Imagine you’re getting ready for school and need to decide what to wear based on the weather
outside.

Start

Yes
Is it raining? Wear raincoat

No

Yes
Is it sunny? Wear favorite t-shirt

No

Yes
Is it snowing? Wear warm jacket

No

Wear regular shirt

End

In QBasic, we can represent this decision-making process as:

IF weather = "raining" THEN


PRINT "Wear raincoat"
ELSEIF weather = "sunny" THEN
PRINT "Wear favorite t-shirt"
ELSEIF weather = "snowing" THEN
PRINT "Wear warm jacket"
ELSE
PRINT "Wear regular shirt"
END IF

Just like in real life, the computer checks the weather and decides what outfit to suggest!

14
Subjective Questions
1. What are QBASIC expressions?
2. What are the types of expressions supported by QBASIC?

Objective Questions
Identify the numeric and String data.
• ”100”
• 100
• ”AB1D”
• ”x % y”
• ”Hello everyone”
• ”1947”

Rewrite the following statements after correcting the errors


1. LET A. – 100
2. LET NUM = ”100”
3. PRINT208
4. LET WORD$=”REBOOT”
5. PRINT=”Class5”
6. LET CLS=123

Write the Output


1. LET EXTRA = 5
LET VALUE = 2 + EXTRA
PRINT "The Value is :"; Value

LET X = 5
LET Y = 10
PRINT "The Product is :"; X * Y

3.
2. LET NUM = 50
PRINT "The variable contains "; NUM

LET area = 10 * 2
PRINT "The variable contains "; area

5.
4. PRINT " HAPPY ";" BIRTHDAY "
PRINT 10;20;100
PRINT "10";"20";"100"
PRINT 15;" AUGUST ";1947

15
6. PRINT1 ;2
PRINT "A" ; "B"
PRINT "A" ; " B"
PRINT 6 ; "th Cross "
PRINT "$" ; 10
PRINT "I am" ; 11 ; " years old"
PRINT " CLASS :" ; 5 ; "A"
PRINT 5 ; "x" ; 3 ; "=" ; 15
PRINT "Bangalore -" ; 560008
PRINT " REBOOT !" ; " " ; "BOOK" ; 5

16
School Programs
1. Write a program to display the name of our school houses and their corresponding colours
under appropriate headings.
2. Write a program to display the following pattern.
3. Write a program to display the sum, difference, product and quotient of 12 and 2 in the
following format:
4. Write a program to display the colours of a traffic signal with their meanings one below the
other under a heading.
5. Write a program to display the first 5 odd numbers one below the other and the first five even
numbers in different zones.
6. Write a program to store your roll number in a numeric variable and your name in a string
variable. Display the details one below the other using the variables.
7. Write a program to accept your name and age. Display in the following format.
8. Write a program to accept two numbers. Calculate and store the sum and product of the
numbers. Display all the details.
9. Write a program to accept a number. Display the multiplication table in the proper format
under a heading from 5th to 8th multiple.
10. Write a program to accept a number. Display if the number is a positive number, negative
number or zero.
11. Write a program to accept colour. Display the significance of the colour in a traffic light.
12. Write a program to accept two numbers and an arithmetic operator. Based on the operator,
perform the arithmetic calculations.
13. Write a program to accept the values of length and breadth of the rectangle. Depending on the
user’s choice, display either the area or the perimeter of the rectangle. Display an appropriate
message if the user enters the wrong choice.
14. Write a program to accept a colour. Display whether it is one of the primary colour otherwise
display an appropriate message.
15. Write a program to accept a number. Display whether it’s a positive number or not.
16. Write a program to accept the name of a house from NHPS. Display whether you belong to
that house or not.
17. Write a program to accept a number and display if the number is even or odd.
18. Write a program to accept two different numbers. Display the greater number of the two.
19. Write a program to accept a section. Display whether the user belongs to your section or not.
20. Write a program to accept two numbers. Display the sum of the numbers if they are equal
otherwise display the product.
21. Write a program to accept the age of a person and display if the person can vote or not. (Note:
Voting age is 18 and above)

17
Revision
Question 1
Fill in the blanks
1. The outcome of a condition always results to either or .

2. The Keyword CLS stands for .


3. Each line of code in a statement is called a .
4. The operator used to perform mathematical operations between numbers are called
operators.

5. QBASIC is divided into two screens namely screen and screen.


6. Multiple IF statement in a single block is called

Question 2
Name the following and write their syntax.
1. INPUT.
2. LET
3. PRINT

4. IF ... THEN ... ELSE.

Question 3
Name the following and write their syntax.
1. INPUT.

2. LET
3. PRINT
4. IF ... THEN ... ELSE.

Question 4
Answer the following questions
1. Write one similarity between LET and INPUT statement.
2. Write the symbols and name of any four relational operator.

3. Write any two rules of naming a variable.


4. Define keyword and syntax.
5. Name two types of variables and two types of constants.

18
Question 5
Write one QBasic statement for each of the following.
1. Increase the value of A by 10 and store it in A.
2. Assign the value of Y$ to X$.
3. Check whether the user is as old as you or younger. assume the user’s age is stored in a variable
’age’.

4. Display Q and Basic without leaving any space between them.


5. Write the expression to divide 10 and 3 and store only the integer part of the quotient in a
variable.

Question 6
Write the output of the following programs
1. Print ”Program to show concatenation”
LET firstword$ = " Computer "
LET secondword$ = " Science "
PRINT firstword$ + secondword$

2. Print ”Program to display message”


PRINT " Welcome ";`to our world
PRINT "dear friend "

Question 7
Fill in the blanks to complete the program

1. CLS
INPUT " Enter the name of the item "; N$
INPUT " Enter the number of items ";P
INPUT " Enter the cost of the item ";
LET M=P*Q
PRINT "Name of the item "; _____________
PRINT " Total cost of "; _____________ ; " number of items =";

2. PRINT " Enter two numbers "


INPUT __________
__________ =A+B
__________ =A*B
PRINT "The sum of two numbers ";S
PRINT "The product of two numbers ";P

19
Question 8
Write the following programs
1. The employees of a firm are classified into 4 grades (1,2,3,4) 61 and salary is computed using
the following format.
12000 x (5-A)+550 x B+200.
Where A denotes the grade and B denotes the number of years of experience. Write a program
to accept the name of the employee, grade and years of experience using appropriate message.
Display the salary of the employee in the following format.
Example :The salary of Jack is

2. In an examination, 80% of students passed in English and 70% passed in Maths. Write a
program to find the number of students who failed in English and the number of students who
failed in Maths taking the total number of students in the class as input.

Question 9
Write any four of the following programs:
1. Prompt the user to enter an abbreviation from a given list.
Write a program to display the message based on the abbreviation.
Display the message “Unknown”, if any other abbreviation is entered.
The abbreviation list is shown below:

TC Take Care
FYI For Your Information
HAND Have A Nice Day

2. A garment shop has announced end of season discounts on the purchase of items, based on the
total cost of the items bought.

Total Cost Discount in percentage


Less than Rs.2000/- 5%
Rs.2000/- to Rs.5000/- 10%
Rs.5001/- to Rs.10000/- 15%
Above Rs.10000 25%

Write a program to accept the total cost and display the payable amount after availing the
discount.
3. Air quality index (AQI) tells you the quality of air. Write a program to accept the AQI for
today. Display the message according to the following conditions.

AQI Message
Less than or equal to 50 Air Quality is good
Between 51 to 100 Air Quality is Satisfactory
Between 101 to 200 Polluted
Above 200 Alarming

20
4. Write a program to accept user’s height in meters and weight in kg. Display the name of the
user, BMI and the appropriate message after calculating the BMI based on the given formula.
BMI is body Mass Index
BMI=Weight in Kg / (Height in meter)

BMI Message
Less than 18.5 Under weight
18.5 to 24.9 Ideal weight
25 to 29.9 Over weight
Greater than 29.9 1t is high time to take corrective measures

5. (Write a program to accept the measurement of an angle. Display whether the angle is acute,
obtuse or right angle.

Angle Message
Greater than 0 and less than 90 Acute
Equal to 90 Right angle
Greater than 90 and less than 180 Obtuse Angle

21

You might also like