0% found this document useful (0 votes)
5 views29 pages

Q Basic

This document provides a comprehensive introduction to QBASIC programming, focusing on the PRINT statement, variables, and the INPUT statement. It includes lessons with clear objectives, real-life examples, syntax rules, common mistakes, and practice exercises for beginners. The document is structured to facilitate learning with step-by-step explanations and homework challenges to reinforce understanding.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views29 pages

Q Basic

This document provides a comprehensive introduction to QBASIC programming, focusing on the PRINT statement, variables, and the INPUT statement. It includes lessons with clear objectives, real-life examples, syntax rules, common mistakes, and practice exercises for beginners. The document is structured to facilitate learning with step-by-step explanations and homework challenges to reinforce understanding.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Abu Farhad Sardar

7478085288
📘 Lesson 1: QBASIC and the PRINT Statement (Very PRINT means show on the screen.
Easy)
Real-life example:
If you speak, people hear your words.
If the computer uses PRINT, we see words on the
1. Lesson Title
screen.
Lesson 1: QBASIC and the PRINT Statement

4. Syntax
2. Learning Objectives
This is the simple way to use PRINT:
After this lesson, you will be able to:
PRINT "message"
 Tell what a program is
Rules:
 Tell what QBASIC is
 The word must be PRINT
 Use PRINT to show text on the screen
 Text must be inside double quotes " "
 Run a simple QBASIC program
 Each line runs from top to bottom

3. Concept Explanation (Very Simple Language +


5. Fully Commented Example Program (With Very
Real-Life Examples)
Clear Meaning)
A computer is like a robot.
REM Lesson 1 program
A robot needs instructions.
A computer also needs instructions. REM This program shows messages on the screen

A program is a set of instructions.


We write the instructions.
PRINT "Hello World"
The computer follows them.
PRINT "My name is Riya"
Real-life examples
PRINT "I am learning QBASIC"
 If your teacher says: “Open your book.”
That is an instruction.

 If your mother says: “Bring water.” 6. Program Output


That is an instruction.
When you run the program, you will see:
 If you tell a friend: “Write your name.”
That is an instruction. Hello World

A computer is the same. My name is Riya


It will do only what we tell it to do. I am learning QBASIC
What is QBASIC?

QBASIC is a simple computer language. 7. Step-by-Step Explanation of the Code (Every Line
It is good for beginners. Clearly)
It is used in schools to learn programming.
Line 1:
What is PRINT?
REM Lesson 1 program
1
Abu Farhad Sardar
7478085288
 REM means “This is a note for humans.” PRINT "Hello"

 It helps us understand the program. Reason: Text must be inside " ".

 The computer does not run this line.

 The computer ignores it. Mistake 2: Spelling PRINT wrong

Line 2: ❌ Wrong:

REM This program shows messages on the screen PRNT "Hello"

 This is also a note. ✅ Correct:

 It tells what the program does. PRINT "Hello"

 Again, the computer ignores this line. Reason: The computer needs the correct word.

Line 3:

PRINT "Hello World" Mistake 3: Using single quotes for text

 PRINT tells the computer: “Show something.” ❌ Wrong:

 "Hello World" is the message. PRINT 'Hello'

 The message is inside quotes. ✅ Correct:

 The computer displays: Hello World PRINT "Hello"

Line 4: Reason: Text must use double quotes in QBASIC.

PRINT "My name is Riya"

 The computer reads this next. 9. Practice Exercises (Easy to Moderate)

 It shows the message: My name is Riya 1. Print your name

 You can change Riya to your name. 2. Print your school name

Line 5: 3. Print “I love computers”

PRINT "I am learning QBASIC" 4. Print any 3 lines about yourself (3 PRINT lines)

 This is the last line. 5. Print:

 The computer shows: I am learning QBASIC o “My class is ____”

 Then the program ends. o “My roll number is ____”

6. Print your full address in 2 lines

8. Common Mistakes (With Simple Reasons)

Mistake 1: No quotes 10. Homework Challenge

❌ Wrong: Homework

PRINT Hello Write a program to print this:

✅ Correct:  Your name

2
Abu Farhad Sardar
7478085288
 Your class  A box stores toys

 Your favorite game In the same way,


a variable stores data in a computer.
 Your favorite food
The data can be:
Each on a new line.
 Numbers (like 5, 10, 25)
Bonus (Optional)
 Text (like your name)
Add 2 comment lines using REM at the top to explain
your program. What is INPUT?

The INPUT statement is used to take data from the


user.

Real-life example:

 A teacher asks: “What is your name?”

 You answer with your name.

The computer does the same.


📘 Lesson 2: Variables and the INPUT Statement
It asks a question.
You type the answer.

1. Lesson Title

Lesson 2: Variables and the INPUT Statement 4. Syntax

Variable assignment

2. Learning Objectives A = 10

After this lesson, you will be able to: NAME$ = "RAM"

 Understand what a variable is INPUT statement

 Store numbers and text in variables INPUT A

 Take input from the user INPUT NAME$

 Use the INPUT statement in programs Rules:

 Variable names must start with a letter

3. Concept Explanation (Very Simple Language +  Use $ for text (string) variables
Real-Life Examples)
 Numbers do not use $
What is a Variable?

A variable is like a box.


5. Fully Commented Example Program 1
The box stores something.
Program 1: Input and print a number
Real-life examples:
REM Program to input a number and print it
 A water bottle stores water

 A school bag stores books

3
Abu Farhad Sardar
7478085288
INPUT A 'Takes a number from the user

PRINT A 'Shows the number on the screen 10. Step-by-Step Explanation of Program 2

 INPUT NAME$
The computer asks for text.
6. Program Output (Program 1)
The user types a name.
If the user enters: The name is stored in NAME$.

5  PRINT "Hello "; NAME$


The computer prints Hello.
The output will be: Then it prints the name.
5 Both appear on the same line.

7. Step-by-Step Explanation of Program 1 11. Common Mistakes

 REM Program to input a number and print it Mistake 1: Forgetting $ for text
This is a comment. ❌ Wrong:
It explains the program.
The computer ignores it. INPUT NAME

 INPUT A ✅ Correct:
The computer waits for the user.
INPUT NAME$
The user types a number.
The number is stored in A. Mistake 2: Using quotes in INPUT

 PRINT A ❌ Wrong:
The computer shows the value stored in A.
INPUT "A"

✅ Correct:
8. Fully Commented Example Program 2
INPUT A
Program 2: Input and print a name
Mistake 3: Mixing number and text variables
REM Program to input and print a name
❌ Wrong:

A$ = 10
INPUT NAME$ 'Takes name from the user
✅ Correct:
PRINT "Hello "; NAME$ 'Prints greeting with name
A = 10

9. Program Output (Program 2)


12. Practice Exercises (Easy to Moderate)
If the user enters:
1. Input a number and print it
Riya
2. Input your age and print it
The output will be:
3. Input your name and print it
Hello Riya
4. Input two numbers and print them

4
Abu Farhad Sardar
7478085288
5. Input your school name and print it  Try to fix it

Do not worry if you feel confused.


This is how programmers learn 😊
13. Homework Challenge

Homework
❌ Program 1 (Wrong)
Write a program that:
REM Program to input name
 Inputs your name
INPUT NAME
 Inputs your class
PRINT "Hello "; NAME
 Prints both on the screen
📌 What is the problem?
Bonus
Look carefully at the variable name.
Print a message like:

Welcome <name> to class <class>


❌ Program 2 (Wrong)

REM Program to input a number

INPUT "A"

PRINT A

📌 What is the problem?


Check how INPUT is used.

❌ Program 3 (Wrong)

REM Program to store age

AGE$ = 12

PRINT AGE$

📌 What is the problem?


Check the type of variable used.

✅ Answers (Do Not See Until You Try!)

🐞 Debug This Program


✔ Answer to Program 1
In this section, you will see wrong programs.
Each program has a common beginner mistake. Problem:
NAME is a text variable.
👉 Your task: But $ is missing.
 Read the program Correct Program:
 Find the mistake REM Program to input name

5
Abu Farhad Sardar
7478085288
INPUT NAME$ Below is Lesson 3, created using the same lesson
template, written in very simple English, with real-life
PRINT "Hello "; NAME$
school examples.
It is suitable for absolute beginners.

✔ Answer to Program 2

Problem: 📘 Lesson 3: IF and IF…ELSE Statements


INPUT should not have quotes.

Correct Program:
1. Lesson Title
REM Program to input a number
Lesson 3: IF and IF…ELSE Statements
INPUT A

PRINT A
2. Learning Objectives

After this lesson, you will be able to:


✔ Answer to Program 3
 Understand what a condition is
Problem:
 Use the IF statement
AGE$ is a text variable.
But 12 is a number.  Use the IF…ELSE statement

Correct Program (Option 1 – Number):  Write simple decision-making programs

REM Program to store age

AGE = 12 3. Concept Explanation (Very Simple Language +


Real-Life Examples)
PRINT AGE
Sometimes we make decisions.
Correct Program (Option 2 – Text):
Real-life examples:
REM Program to store age
 If it is raining, take an umbrella
AGE$ = "12"
 If the bell rings, go to class
PRINT AGE$
 If you score 40 marks or more, you pass

 Else, you fail



The computer also makes decisions.
It checks a condition.

A condition is a question with YES or NO answer.

IF statement

The IF statement means:


👉 “If this is true, then do something.”

IF…ELSE statement

6
Abu Farhad Sardar
7478085288
The IF…ELSE statement means: 5
👉 “If this is true, do this.
Output:
👉 Otherwise, do something else.”
Positive number

(If the number is not positive, nothing is printed.)


4. Syntax

IF statement
7. Step-by-Step Explanation of Program 1
IF condition THEN
 INPUT A
statement
The computer asks for a number.
END IF The number is stored in A.

IF…ELSE statement  IF A > 0 THEN


The computer checks the condition.
IF condition THEN
It asks: “Is A greater than 0?”
statement
 PRINT "Positive number"
ELSE This runs only if the condition is true.

statement  END IF
This ends the IF block.
END IF

Rules:
8. Fully Commented Example Program 2
 Conditions use symbols like >, <, =
Program 2: Check pass or fail
 END IF is used to close the IF block
REM Program to check pass or fail
 Statements run from top to bottom

INPUT MARKS 'Takes marks from the user


5. Fully Commented Example Program 1

Program 1: Check if a number is positive


IF MARKS >= 40 THEN 'Checks if marks are 40 or more
REM Program to check positive number
PRINT "PASS"

ELSE 'Runs when condition is false


INPUT A 'Takes a number from the user
PRINT "FAIL"

END IF 'Ends IF...ELSE


IF A > 0 THEN 'Checks if number is greater than 0

PRINT "Positive number"


9. Program Output (Program 2)
END IF 'Ends IF statement
If the user enters:

55
6. Program Output (Program 1)
Output:
If the user enters:
7
Abu Farhad Sardar
7478085288
PASS IF MARKS = 40 THEN

If the user enters: ✅ Better:

30 IF MARKS >= 40 THEN

Output:

FAIL Mistake 3: Writing ELSE without IF

❌ Wrong:

10. Step-by-Step Explanation of Program 2 ELSE

 INPUT MARKS PRINT "FAIL"


The computer asks for marks.

 IF MARKS >= 40 THEN


12. Practice Exercises (Easy to Moderate)
The computer checks if marks are enough to
pass. 1. Input a number and check if it is greater than
10
 PRINT "PASS"
This runs when the condition is true. 2. Input age and check if age is 18 or more
 ELSE 3. Input marks and print PASS or FAIL
This runs when the condition is false.
4. Input a number and check if it is zero
 PRINT "FAIL"
This shows fail message. 5. Input temperature and print HOT or COLD

 END IF
This ends the decision. 13. Homework Challenge

Homework
11. Common Mistakes Write a program that:
Mistake 1: Forgetting END IF  Inputs your age
❌ Wrong:  If age is 5 or more, print “School Student”
IF A > 0 THEN  Else, print “Too young for school”
PRINT "Positive" Bonus
✅ Correct: Change the program to check:
IF A > 0 THEN  Primary student
PRINT "Positive"  Secondary student
END IF

Mistake 2: Using = instead of >= or >

❌ Wrong:

8
Abu Farhad Sardar
7478085288

Below is Lesson 4, written using the same lesson


template, with very simple English, short sentences,
and daily-life examples.
It is suitable for absolute beginners.

📘 Lesson 4: FOR…NEXT Loop

1. Lesson Title

Lesson 4: FOR…NEXT Loop

2. Learning Objectives

After this lesson, you will be able to:

 Understand repetition

 Know why loops are used

9
Abu Farhad Sardar
7478085288
 Use the FOR…NEXT loop NEXT I 'Increases I and repeats the loop

 Write simple looping programs

6. Program Output (Program 1)

3. Concept Explanation (Very Simple Language + 1


Daily-Life Examples)
2
Sometimes we do the same work again and again.
3
Daily-life examples:
4
 Write your name 5 times in a notebook
5
 Clap your hands 10 times

 Count numbers from 1 to 10


7. Step-by-Step Explanation of Program 1
 Do 20 jumping jacks
 FOR I = 1 TO 5
Doing the same work many times is called repetition. The loop starts.
I becomes 1 first.
A loop is used for repetition in programming.
 PRINT I
The FOR…NEXT loop tells the computer:
The computer prints the value of I.
👉 “Do this work again and again for a fixed number of
times.”  NEXT I
The value of I increases by 1.
The loop repeats.
4. Syntax
 The loop stops when I becomes 6.
FOR variable = start TO end

statement
8. Fully Commented Example Program 2
NEXT variable
Program 2: Print a message 3 times
Rules:
REM Program to print a message 3 times
 The loop starts at the start value

 The loop stops at the end value


FOR COUNT = 1 TO 3 'Loop will run 3 times
 NEXT tells the loop to move to the next value
PRINT "Good Morning" 'Prints message

NEXT COUNT 'Moves to next count


5. Fully Commented Example Program 1

Program 1: Print numbers from 1 to 5


9. Program Output (Program 2)
REM Program to print numbers from 1 to 5
Good Morning

Good Morning
FOR I = 1 TO 5 'Loop starts with I = 1 and ends at 5
Good Morning
PRINT I 'Prints value of I

10
Abu Farhad Sardar
7478085288
10. Step-by-Step Explanation of Program 2 PRINT I

 FOR COUNT = 1 TO 3 NEXT I


The loop will run 3 times.

 PRINT "Good Morning"


12. Practice Exercises (Easy to Moderate)
The message is printed.
1. Print numbers from 1 to 10
 NEXT COUNT
The loop moves to the next number. 2. Print your name 5 times
 After 3 times, the loop stops. 3. Print “I like QBASIC” 4 times

4. Print numbers from 10 to 15


11. Common Mistakes 5. Print first 7 natural numbers
Mistake 1: Forgetting NEXT

❌ Wrong: 13. Homework Challenge


FOR I = 1 TO 5 Homework
PRINT I Write a program that:
✅ Correct:  Prints numbers from 1 to 20
FOR I = 1 TO 5  Prints “Even Number” after each number
PRINT I Bonus
NEXT I Change the program to print:

 Only odd numbers


Mistake 2: Using different variable names

❌ Wrong: ✅ End of Lesson 4


FOR I = 1 TO 5 Next lesson: WHILE…WEND Loop and repetition with
conditions
PRINT I

NEXT J

✅ Correct:

FOR I = 1 TO 5

PRINT I

NEXT I

Mistake 3: Writing start value bigger than end value

❌ Wrong:
Below is Lesson 5, written using the same lesson
FOR I = 5 TO 1
template, in very simple English, with clear daily-life
11
Abu Farhad Sardar
7478085288
examples, and a simple comparison with the FOR FOR Loop WHILE Loop
loop.
Used when number of Used when repeats are not
repeats is fixed fixed
📘 Lesson 5: WHILE…WEND Loop Example: Repeat while a
Example: Repeat 5 times
condition is true

1. Lesson Title Starts and ends with Starts and ends with a
numbers condition
Lesson 5: WHILE…WEND Loop

4. Syntax
2. Learning Objectives
WHILE condition
After this lesson, you will be able to:
statement
 Understand conditional repetition
WEND
 Use the WHILE…WEND loop
Rules:
 Know when to use WHILE instead of FOR
 Condition must be true to enter the loop
 Write simple WHILE loop programs
 Condition is checked before each repeat

 WEND ends the loop


3. Concept Explanation (Very Simple Language +
Daily-Life Examples)

Sometimes we repeat work until a condition becomes 5. Fully Commented Example Program 1
false.
Program 1: Print numbers from 1 to 5 using WHILE
Daily-life examples:
REM Program to print numbers from 1 to 5
 Keep drinking water while you are thirsty

 Keep studying while the exam is not over


I=1 'Start value
 Keep walking while the traffic light is red

In these cases:
WHILE I <= 5 'Loop runs while I is less than or
 We do not know how many times the work equal to 5
will repeat
PRINT I 'Prints the value of I
 We stop only when the condition changes
I=I+1 'Increases I by 1
This is called conditional repetition.
WEND 'Ends the WHILE loop
What is WHILE…WEND?

The WHILE…WEND loop means:


6. Program Output (Program 1)
👉 “Do this work while the condition is true.”
1

2
Simple comparison with FOR loop
12
Abu Farhad Sardar
7478085288
3 Good Evening

5 10. Step-by-Step Explanation of Program 2

 COUNT = 1
The loop starts from 1.
7. Step-by-Step Explanation of Program 1
 WHILE COUNT <= 3
 I=1
The condition is checked.
The loop counter starts at 1.
 PRINT "Good Evening"
 WHILE I <= 5
The message is printed.
The computer checks the condition.
If true, it enters the loop.  COUNT = COUNT + 1
The count increases.
 PRINT I
The number is printed.  When COUNT becomes 4, the loop stops.

 I=I+1
The value of I increases.
11. Common Mistakes
This helps stop the loop later.
Mistake 1: Forgetting to change the value inside loop
 WEND
The loop goes back to check the condition ❌ Wrong:
again.
I=1

WHILE I <= 5
8. Fully Commented Example Program 2
PRINT I
Program 2: Print a message until count reaches 3
WEND
REM Program to print a message 3 times
🔴 Problem: Loop never stops.

COUNT = 1 'Start count


Mistake 2: Forgetting WEND

❌ Wrong:
WHILE COUNT <= 3 'Loop runs while count is 3
or less WHILE I <= 5

PRINT "Good Evening" 'Prints message PRINT I

COUNT = COUNT + 1 'Moves to next count

WEND 'Ends the loop Mistake 3: Condition always false

❌ Wrong:

9. Program Output (Program 2) I = 10

Good Evening WHILE I < 5

Good Evening PRINT I

13
Abu Farhad Sardar
7478085288
WEND

12. Practice Exercises (Easy to Moderate)

1. Print numbers from 1 to 10 using WHILE

2. Print your name 4 times using WHILE

3. Print numbers from 5 to 1 using WHILE

4. Print even numbers from 2 to 10

5. Print “QBASIC” while count is less than 5

13. Homework Challenge

Homework

Write a program that:

 Starts from 1

 Prints numbers

 Stops when the number reaches 15

Bonus

Rewrite the same program using:

 FOR loop
Compare both programs.

14
Abu Farhad Sardar
7478085288
o 2 for Coffee

o 3 for Juice

 On a TV remote:

o Press 1 for News

o Press 2 for Sports

o Press 3 for Movies

You choose one option from many.

The computer also needs to handle many choices.

The SELECT CASE statement helps the computer:


👉 “Check one value
👉 Match it with many choices
👉 Do the correct work”

It is easier and cleaner than many IF…ELSE


statements.

📘 Lesson 6: SELECT CASE Statement

4. Syntax

1. Lesson Title SELECT CASE variable

Lesson 6: SELECT CASE Statement CASE value1

statement

2. Learning Objectives CASE value2

After this lesson, you will be able to: statement

 Understand what SELECT CASE does CASE ELSE

 Use SELECT CASE for multiple choices statement

 Create simple menu-based programs END SELECT

 Know when to use SELECT CASE instead of IF… Rules:


ELSE
 The computer checks the value of the variable

 It runs the matching CASE


3. Concept Explanation (Very Simple Language +
 CASE ELSE runs if no match is found
Daily-Life Examples)
 END SELECT closes the block
Sometimes we have many choices.

Real-life examples:
5. Fully Commented Example Program 1
 In a restaurant menu, you choose:
Program 1: Simple menu (Drink choice)
o 1 for Tea

15
Abu Farhad Sardar
7478085288
REM Program to show drink choice  PRINT "1. Tea"
Shows menu option 1.

 PRINT "2. Coffee"


PRINT "1. Tea"
Shows menu option 2.
PRINT "2. Coffee"
 PRINT "3. Juice"
PRINT "3. Juice" Shows menu option 3.

 INPUT CHOICE
User enters a number.
INPUT CHOICE 'Takes user choice
 SELECT CASE CHOICE
The computer checks the value.
SELECT CASE CHOICE 'Checks the value of  CASE 1
CHOICE Runs if choice is 1.
CASE 1  CASE 2
PRINT "You chose Tea" Runs if choice is 2.

CASE 2  CASE 3
Runs if choice is 3.
PRINT "You chose Coffee"
 CASE ELSE
CASE 3 Runs for any wrong number.
PRINT "You chose Juice"  END SELECT
CASE ELSE Ends the SELECT CASE block.

PRINT "Invalid choice"

END SELECT 8. Fully Commented Example Program 2

Program 2: Day of the week

6. Program Output (Program 1) REM Program to print day name

If the user enters:

2 PRINT "Enter a number (1 to 7)"

Output: INPUT D

You chose Coffee

If the user enters: SELECT CASE D

5 CASE 1

Output: PRINT "Monday"

Invalid choice CASE 2

PRINT "Tuesday"

7. Step-by-Step Explanation of Program 1 CASE 3

16
Abu Farhad Sardar
7478085288
PRINT "Wednesday"

CASE 4 Mistake 2: Using IF inside SELECT CASE wrongly

PRINT "Thursday" ❌ Wrong:

CASE 5 SELECT CASE A

PRINT "Friday" IF A = 1 THEN PRINT "One"

CASE 6 END SELECT

PRINT "Saturday"

CASE 7 Mistake 3: No CASE ELSE

PRINT "Sunday" ❌ Problem: Wrong input not handled

CASE ELSE ✔ Always add CASE ELSE for safety.

PRINT "Wrong number"

END SELECT 12. Practice Exercises (Easy to Moderate)

1. Menu for subjects:

9. Program Output (Program 2) o

If the user enters: 1. Maths

6 o

Output: 2. Science

Saturday o

3. English
10. Step-by-Step Explanation of Program 2 2. Menu for shapes:
 User enters a number o

 SELECT CASE checks the number 1. Circle


 Matching CASE prints the day o

 CASE ELSE handles wrong input 2. Square

11. Common Mistakes 3. Triangle


Mistake 1: Forgetting END SELECT 3. Input month number and print month name
❌ Wrong: 4. Menu for games (Cricket, Football, Chess)
SELECT CASE A 5. Menu for class section (A, B, C)
CASE 1

PRINT "One" 13. Homework Challenge


17
Abu Farhad Sardar
7478085288
Homework examples.
It is suitable for absolute beginners.
Create a menu-based program for:


📘 Lesson 7: Arrays (Single Dimensional)
1. Addition


1. Lesson Title
2. Subtraction
Lesson 7: Arrays (Single Dimensional)

3. Multiplication
2. Learning Objectives
Ask the user to:
After this lesson, you will be able to:
 Enter two numbers
 Understand what an array is
 Choose the operation
 Store many numbers using an array
Print the result.
 Use array index numbers
Bonus
 Write simple programs using arrays
Rewrite the same program using IF…ELSE.

3. Concept Explanation (Very Simple Language +


Daily-Life Examples)

Sometimes we need to store many values.

Real-life examples:

 A row of boxes to keep apples

 A rack of shoes with numbers

 A list of marks of students

Using many variables is hard:

A = 10

B = 20

C = 30

An array makes this easy.

An array is one name with many boxes.


Each box has a number.
This number is called the index.

Below is Lesson 7, written using the same lesson


template, in very simple English, with clear numeric
4. Syntax

18
Abu Farhad Sardar
7478085288
Declaring an array 10

DIM A(5) 20

Using an array 30

A(1) = 10 40

Rules: 50

 DIM is used to create an array

 Numbers inside ( ) are index numbers 7. Step-by-Step Explanation of Program 1

 Index starts from 1 (in our examples)  DIM A(5)


Creates an array named A.
It has 5 boxes.
5. Fully Commented Example Program 1
 FOR I = 1 TO 5
Program 1: Store and print 5 numbers Loop runs 5 times.

REM Program to store and print 5 numbers using array  INPUT A(I)
Takes a number.
Stores it in box number I.
DIM A(5) 'Creates an array with 5 boxes  Second FOR loop
Reads values one by one.
Prints each value.
FOR I = 1 TO 5 'Loop to take input

INPUT A(I) 'Stores number in array


8. Fully Commented Example Program 2
NEXT I
Program 2: Find sum of 5 numbers using array

REM Program to find sum of 5 numbers


FOR I = 1 TO 5 'Loop to print values

PRINT A(I) 'Prints value from array


DIM A(5) 'Array to store numbers
NEXT I
SUM = 0 'Variable to store total

6. Program Output (Program 1)


FOR I = 1 TO 5
If the user enters:
INPUT A(I) 'Input numbers
10
SUM = SUM + A(I) 'Add each number to SUM
20
NEXT I
30

40
PRINT "Total = "; SUM 'Prints the sum
50

Output:

19
Abu Farhad Sardar
7478085288
9. Program Output (Program 2)

If the user enters: 12. Practice Exercises (Easy to Moderate)

2 1. Store and print 3 numbers using array

4 2. Store 5 marks and print them

6 3. Find sum of 3 numbers using array

8 4. Find average of 5 numbers

10 5. Print numbers in reverse order

Output:

Total = 30 13. Homework Challenge

Homework

10. Step-by-Step Explanation of Program 2 Write a program that:

 DIM A(5)  Stores 10 numbers in an array


Creates array.
 Prints only even numbers
 SUM = 0
Bonus
Starts total from zero.
Modify the program to:
 Loop takes input
Adds each value to SUM.  Count how many even numbers are there
 PRINT shows the final total.

11. Common Mistakes

Mistake 1: Using array without DIM

❌ Wrong:

A(1) = 10

Mistake 2: Using index outside range

❌ Wrong:

DIM A(5)

PRINT A(6)

Mistake 3: Forgetting loop for array input

❌ Wrong:

INPUT A

20
Abu Farhad Sardar
7478085288

Below is Lesson 8, written using the same lesson


template, in very simple English, with complete
programs that combine many concepts learned
earlier.
It is suitable for absolute beginners.

📘 Lesson 8: Simple Programs Using Many Concepts

1. Lesson Title

Lesson 8: Simple Programs Using Many Concepts

2. Learning Objectives

After this lesson, you will be able to:

 Use INPUT and PRINT together

 Use IF, loops, and SELECT CASE

 Write complete small programs

 Think step by step like a programmer

21
Abu Farhad Sardar
7478085288
3. Concept Explanation (Very Simple Language +
Real-Life Examples)
SELECT CASE CHOICE
A real program uses many ideas together.
CASE 1
Real-life examples:
PRINT "Result = "; A + B
 A calculator uses numbers and choices
CASE 2
 A report card uses marks and averages
PRINT "Result = "; A - B
 A game uses input, checking, and repeating
CASE 3
In this lesson:
PRINT "Result = "; A * B
 You will build small but complete programs
CASE 4
 Each program uses many concepts together
IF B <> 0 THEN

PRINT "Result = "; A / B


4. Syntax
ELSE
There is no single syntax here.
PRINT "Cannot divide by zero"
We combine:
END IF
 INPUT
CASE ELSE
 PRINT
PRINT "Wrong choice"
 IF…ELSE
END SELECT
 FOR / WHILE

 SELECT CASE
6. Program Output (Program 1)

If user enters:
5. Fully Commented Example Program 1
1
Program 1: Simple Calculator (Menu Based)
5
REM Simple calculator program
3

Output:
PRINT "1. Addition"
Result = 8
PRINT "2. Subtraction"

PRINT "3. Multiplication"


7. Step-by-Step Explanation of Program 1
PRINT "4. Division"
 Menu is printed using PRINT

 User selects an option


INPUT CHOICE 'Takes operation choice
 Two numbers are entered
INPUT A 'First number
 SELECT CASE checks the choice
INPUT B 'Second number
22
Abu Farhad Sardar
7478085288
 Correct calculation is done  Marks are added

 Result is printed  Average is calculated

 Result is printed

8. Fully Commented Example Program 2

Program 2: Find Average of Marks 11. Fully Commented Example Program 3

REM Program to find average marks Program 3: Number Guessing Game

REM Number guessing game

SUM = 0

SECRET = 7 'Fixed secret number

FOR I = 1 TO 5

INPUT M 'Takes marks WHILE 1 = 1 'Loop runs again and again

SUM = SUM + M 'Adds marks INPUT GUESS 'User guesses number

NEXT I

IF GUESS = SECRET THEN

AVG = SUM / 5 'Calculates average PRINT "Correct Guess!"

END

PRINT "Average Marks = "; AVG ELSE

PRINT "Try Again"

9. Program Output (Program 2) END IF

If user enters: WEND

60

70 12. Program Output (Program 3)

80 If user enters:

90 5

100 Output:

Output: Try Again

Average Marks = 80 If user enters:

10. Step-by-Step Explanation of Program 2 Output:

 SUM starts from 0 Correct Guess!

 FOR loop runs 5 times

23
Abu Farhad Sardar
7478085288
13. Step-by-Step Explanation of Program 3

 SECRET number is stored 🎉 Congratulations!

 WHILE loop runs continuously You have completed the QBASIC Beginner Course.
You can now write simple programs on your own 👏
 User enters a guess

 IF checks the guess

 Program ends when correct

14. Common Mistakes

 Forgetting END in infinite loops

 Division by zero

 Wrong menu choice handling

 Forgetting to update variables

15. Practice Exercises (Easy to Moderate)

1. Create a calculator for only addition and


subtraction

2. Find average of 3 numbers

3. Guess a number between 1 and 5

4. Print result PASS or FAIL using average

5. Create a menu for subjects

16. Homework Challenge

Homework

Create a program that:

 Inputs marks of 5 subjects

 Finds total and average

 Prints PASS if average ≥ 40

 Else prints FAIL

Bonus

Add:

 Grade using SELECT CASE

24
Abu Farhad Sardar
7478085288
1. Write a program to print your name.

Below are clean, printable practice worksheets for all 2. Write a program to print your school name.
8 QBASIC lessons, rewritten clearly and structured so
3. Print three different messages on the screen.
they can be directly printed or converted to PDF for
students.

Each worksheet includes:

 ✏️Short Answer Questions 📘 Worksheet – Lesson 2


 🧠 Write-the-Output Questions Topic: Variables and INPUT Statement
 💻 Small Coding Tasks A. Short Answer Questions
Language is simple and school-friendly. 1. What is a variable?

2. What does INPUT statement do?


📄 QBASIC PRACTICE WORKSHEETS 3. Why is $ used in variable names?
(Lessons 1 to 8) 4. Write one numeric variable.

5. Write one string variable.


📘 Worksheet – Lesson 1

Topic: Introduction to QBASIC & PRINT Statement B. Write the Output


A. Short Answer Questions 1.
1. What is a computer program? INPUT A
2. What is QBASIC? PRINT A
3. What does the PRINT statement do? (User enters: 8)
4. Why are double quotes used in PRINT? 2.
5. Write one PRINT statement. INPUT NAME$

PRINT "Hello "; NAME$


B. Write the Output (User enters: Riya)
1.

PRINT "Hello" C. Small Coding Tasks


PRINT "QBASIC" 1. Input your age and print it.
2. 2. Input two numbers and print their sum.
PRINT "My Name" 3. Input your name and print a welcome
message.
PRINT "Is Amit"

C. Small Coding Tasks

25
Abu Farhad Sardar
7478085288
📘 Worksheet – Lesson 3

Topic: IF and IF…ELSE Statements 📘 Worksheet – Lesson 4

A. Short Answer Questions Topic: FOR…NEXT Loop

1. What is a condition? A. Short Answer Questions

2. What is the use of IF statement? 1. What is a loop?

3. When is ELSE used? 2. Why is FOR loop used?

4. Write one relational operator. 3. Write FOR loop syntax.

5. Why is END IF needed? 4. What does NEXT do?

5. Give one example of repetition in daily life.

B. Write the Output

1. B. Write the Output

INPUT A 1.

IF A > 5 THEN FOR I = 1 TO 4

PRINT "Big" PRINT I

ELSE NEXT I

PRINT "Small" 2.

END IF FOR I = 1 TO 3

(User enters: 3) PRINT "Hi"

2. NEXT I

INPUT M

IF M >= 40 THEN PRINT "PASS" C. Small Coding Tasks

ELSE PRINT "FAIL" 1. Print numbers from 1 to 10.

END IF 2. Print your name 5 times.

(User enters: 45) 3. Print even numbers from 2 to 10.

C. Small Coding Tasks

1. Check whether a number is positive or 📘 Worksheet – Lesson 5


negative.
Topic: WHILE…WEND Loop
2. Input marks and print PASS or FAIL.
A. Short Answer Questions
3. Input age and check if age is 18 or more.
1. What is WHILE loop?

2. When is WHILE loop used?

26
Abu Farhad Sardar
7478085288
3. Write WHILE loop syntax. 4. Write SELECT CASE syntax.

4. One difference between FOR and WHILE. 5. Give one menu example from daily life.

5. What happens if condition never becomes


false?
B. Write the Output

1.
B. Write the Output
INPUT A
1.
SELECT CASE A
I=1
CASE 1
WHILE I <= 3
PRINT "One"
PRINT I
CASE 2
I=I+1
PRINT "Two"
WEND
CASE ELSE
2.
PRINT "Other"
X=4
END SELECT
WHILE X > 1
(User enters: 2)
PRINT X
2.
X=X-1
(User enters: 7)
WEND

C. Small Coding Tasks


C. Small Coding Tasks
1. Menu for days of the week.
1. Print numbers from 1 to 5 using WHILE.
2. Menu for subjects (Maths, Science, English).
2. Print your name 3 times using WHILE.
3. Menu-based calculator (Add/Subtract).
3. Print numbers from 10 to 1 using WHILE.

📘 Worksheet – Lesson 7
📘 Worksheet – Lesson 6
Topic: Arrays (Single Dimensional)
Topic: SELECT CASE Statement
A. Short Answer Questions
A. Short Answer Questions
1. What is an array?
1. What is SELECT CASE used for?
2. Why is DIM used?
2. When is SELECT CASE better than IF?
3. What is an index?
3. What is CASE ELSE?
4. Write array declaration syntax.

27
Abu Farhad Sardar
7478085288
5. Give one real-life example of array. 1.

SUM = 0

B. Write the Output FOR I = 1 TO 3

1. INPUT A

DIM A(3) SUM = SUM + A

A(1)=5 NEXT I

A(2)=10 PRINT SUM

A(3)=15 (Inputs: 2, 3, 5)

PRINT A(2) 2.

2. N=6

DIM N(2) IF N > 5 THEN

N(1)=4 PRINT "YES"

N(2)=6 ELSE

PRINT N(1)+N(2) PRINT "NO"

END IF

C. Small Coding Tasks

1. Store and print 5 numbers using array. C. Small Coding Tasks

2. Find sum of 3 numbers using array. 1. Calculator using SELECT CASE.

3. Find average of 5 marks. 2. Find average of 5 numbers and print


PASS/FAIL.

3. Guess a number between 1 and 5.

📘 Worksheet – Lesson 8
✅ Teacher / Parent Note
Topic: Programs Using Multiple Concepts
 Section A → Viva & theory
A. Short Answer Questions
 Section B → Written exam
1. Why do we combine programming concepts?
 Section C → Lab practice
2. Name any three QBASIC statements.

3. What is a calculator program?


If you want next, I can:
4. What is average?
 📘 Add complete answer keys
5. What is a guessing game?
 📄 Convert this into a professional PDF

 🧠 Create MCQ papers


B. Write the Output

28
Abu Farhad Sardar
7478085288
 🏫 Make unit tests & final exam

 📚 Design holiday homework booklet

Just tell me 👍

29

You might also like