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

Q Basic

This document provides a comprehensive introduction to QBASIC programming, covering the PRINT statement, variables, and basic control structures like IF statements and loops. It includes clear explanations, real-life examples, syntax rules, common mistakes, and practice exercises for beginners. The lessons are structured to facilitate understanding for absolute beginners, with step-by-step explanations and homework challenges.
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)
6 views29 pages

Q Basic

This document provides a comprehensive introduction to QBASIC programming, covering the PRINT statement, variables, and basic control structures like IF statements and loops. It includes clear explanations, real-life examples, syntax rules, common mistakes, and practice exercises for beginners. The lessons are structured to facilitate understanding for absolute beginners, with step-by-step explanations and homework challenges.
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

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.”
Hello World
That is an instruction.
My name is Riya
A computer is the same.
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:
2
Abu Farhad Sardar
7478085288
• Your name • A school bag stores books

• 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
3
Abu Farhad Sardar
7478085288
Hello Riya

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.
The user types a number. INPUT NAME$
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

PRINT "Hello "; NAME$ 'Prints greeting with name Correct:

A = 10

9. Program Output (Program 2)


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

Riya 1. Input a number and print it

The output will be: 2. Input your age and print it

3. Input your name and print it


4
Abu Farhad Sardar
7478085288
4. Input two numbers and print them • Find the mistake

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

Write a program that: Program 1 (Wrong)

• Inputs your name REM Program to input name

• Inputs your class INPUT NAME

• Prints both on the screen PRINT "Hello "; NAME

Bonus What is the problem?


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

In this section, you will see wrong programs. ✔ Answer to Program 1


Each program has a common beginner mistake.
Problem:
Your task: NAME is a text variable.
But $ is missing.
• Read the program

5
Abu Farhad Sardar
7478085288
Correct Program:

REM Program to input name Below is Lesson 3, created using the same lesson
template, written in very simple English, with real-life
INPUT NAME$
school examples.
PRINT "Hello "; NAME$ It is suitable for absolute beginners.

✔ Answer to Program 2 Lesson 3: IF and IF…ELSE Statements

Problem:
INPUT should not have quotes.
1. Lesson Title
Correct Program:
Lesson 3: IF and IF…ELSE Statements
REM Program to input a number

INPUT A
2. Learning Objectives
PRINT A
After this lesson, you will be able to:

• Understand what a condition is


✔ Answer to Program 3 • Use the IF statement
Problem: • Use the IF…ELSE statement
AGE$ is a text variable.
But 12 is a number. • Write simple decision-making programs

Correct Program (Option 1 – Number):

REM Program to store age 3. Concept Explanation (Very Simple Language +


Real-Life Examples)
AGE = 12
Sometimes we make decisions.
PRINT AGE
Real-life examples:
Correct Program (Option 2 – Text):
• If it is raining, take an umbrella
REM Program to store age
• If the bell rings, go to class
AGE$ = "12"
• If you score 40 marks or more, you pass
PRINT AGE$
• 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: If the user enters:
“If this is true, do this.
5
Otherwise, do something else.”
Output:

Positive number
4. Syntax
(If the number is not positive, nothing is printed.)
IF statement

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

IF condition THEN • IF A > 0 THEN


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

END IF • END IF
This ends the IF block.
Rules:

• Conditions use symbols like >, <, =


8. Fully Commented Example Program 2
• END IF is used to close the IF block
Program 2: Check pass or fail
• Statements run from top to bottom
REM Program to check pass or fail

5. Fully Commented Example Program 1


INPUT MARKS 'Takes marks from the user
Program 1: Check if a number is positive

REM Program to check positive number


IF MARKS >= 40 THEN 'Checks if marks are 40 or more

PRINT "PASS"
INPUT A 'Takes a number from the user
ELSE 'Runs when condition is false

PRINT "FAIL"
IF A > 0 THEN 'Checks if number is greater than 0
END IF 'Ends IF...ELSE
PRINT "Positive number"

END IF 'Ends IF statement


9. Program Output (Program 2)

If the user enters:


6. Program Output (Program 1)
55

7
Abu Farhad Sardar
7478085288
Output: Wrong:
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


The computer checks if marks are enough to 12. Practice Exercises (Easy to Moderate)
pass.
1. Input a number and check if it is greater than
• PRINT "PASS" 10
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 >

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
9
Abu Farhad Sardar
7478085288
• Know why loops are used PRINT I 'Prints value of I

• 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
10
Abu Farhad Sardar
7478085288
FOR I = 5 TO 1

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:
11
Abu Farhad Sardar
7478085288
Below is Lesson 5, written using the same lesson
template, in very simple English, with clear daily-life
Simple comparison with FOR loop
examples, and a simple comparison with the FOR
loop. FOR Loop WHILE Loop

Used when number of Used when repeats are not


Lesson 5: WHILE…WEND Loop repeats is fixed fixed

Example: Repeat while a


Example: Repeat 5 times
condition is true
1. Lesson Title

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

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

• Condition is checked before each repeat


3. Concept Explanation (Very Simple Language +
Daily-Life Examples) • WEND ends the loop

Sometimes we repeat work until a condition becomes


false. 5. Fully Commented Example Program 1
Daily-life examples: Program 1: Print numbers from 1 to 5 using WHILE
• Keep drinking water while you are thirsty REM Program to print numbers from 1 to 5
• Keep studying while the exam is not over

• Keep walking while the traffic light is red I=1 'Start value
In these cases:

• We do not know how many times the work WHILE I <= 5 'Loop runs while I is less than or
will repeat equal to 5
• We stop only when the condition changes PRINT I 'Prints the value of I
This is called conditional repetition. I=I+1 'Increases I by 1
What is WHILE…WEND? WEND 'Ends the WHILE loop
The WHILE…WEND loop means:
“Do this work while the condition is true.”
6. Program Output (Program 1)
12
Abu Farhad Sardar
7478085288
1 Good Evening

2 Good Evening

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

13
Abu Farhad Sardar
7478085288
WHILE I < 5

PRINT I

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
• Know when to use SELECT CASE instead of
IF…ELSE

3. Concept Explanation (Very Simple Language +


Daily-Life Examples)

Sometimes we have many choices.

Real-life examples:

• In a restaurant menu, you choose:

o 1 for Tea

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


Lesson 6: SELECT CASE Statement statements.

1. Lesson Title 4. Syntax

Lesson 6: SELECT CASE Statement SELECT CASE variable

CASE value1

2. Learning Objectives statement

After this lesson, you will be able to: CASE value2

• Understand what SELECT CASE does statement

• Use SELECT CASE for multiple choices CASE ELSE

• Create simple menu-based programs statement

END SELECT
15
Abu Farhad Sardar
7478085288
Rules: Output:

• The computer checks the value of the variable You chose Coffee

• It runs the matching CASE If the user enters:

• CASE ELSE runs if no match is found 5

• END SELECT closes the block Output:

Invalid choice

5. Fully Commented Example Program 1

Program 1: Simple menu (Drink choice) 7. Step-by-Step Explanation of Program 1

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)"

16
Abu Farhad Sardar
7478085288
INPUT D • CASE ELSE handles wrong input

SELECT CASE D 11. Common Mistakes

CASE 1 Mistake 1: Forgetting END SELECT

PRINT "Monday" Wrong:


CASE 2 SELECT CASE A
PRINT "Tuesday" CASE 1
CASE 3 PRINT "One"
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
17
Abu Farhad Sardar
7478085288
o

2. Square

3. Triangle

3. Input month number and print month name

4. Menu for games (Cricket, Football, Chess)

5. Menu for class section (A, B, C)

13. Homework Challenge


Below is Lesson 7, written using the same lesson
Homework template, in very simple English, with clear numeric
examples.
Create a menu-based program for:
It is suitable for absolute beginners.

1. Addition
Lesson 7: Arrays (Single Dimensional)

2. Subtraction
1. Lesson Title

Lesson 7: Arrays (Single Dimensional)
3. Multiplication

Ask the user to:


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

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


18
Abu Farhad Sardar
7478085288
Using many variables is hard: NEXT I

A = 10

B = 20 6. Program Output (Program 1)

C = 30 If the user enters:

An array makes this easy. 10

An array is one name with many boxes. 20


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

50
4. Syntax
Output:
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.
5. Fully Commented Example Program 1 It has 5 boxes.

Program 1: Store and print 5 numbers • FOR I = 1 TO 5


Loop runs 5 times.
REM Program to store and print 5 numbers using array
• INPUT A(I)
Takes a number.
DIM A(5) 'Creates an array with 5 boxes Stores it in box number I.

• Second FOR loop


Reads values one by one.
FOR I = 1 TO 5 'Loop to take input Prints each value.
INPUT A(I) 'Stores number in array

NEXT I 8. Fully Commented Example Program 2

Program 2: Find sum of 5 numbers using array


FOR I = 1 TO 5 'Loop to print values REM Program to find sum of 5 numbers
PRINT A(I) 'Prints value from array

19
Abu Farhad Sardar
7478085288
DIM A(5) 'Array to store numbers A(1) = 10

SUM = 0 'Variable to store total

Mistake 2: Using index outside range

FOR I = 1 TO 5 Wrong:
INPUT A(I) 'Input numbers DIM A(5)
SUM = SUM + A(I) 'Add each number to SUM PRINT A(6)
NEXT I

Mistake 3: Forgetting loop for array input


PRINT "Total = "; SUM 'Prints the sum Wrong:

INPUT A
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
Starts total from zero. Bonus

• Loop takes input Modify the program to:


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:
20
Abu Farhad Sardar
7478085288

Below is Lesson 8, written using the same lesson


template, in very simple English, with complete
21
Abu Farhad Sardar
7478085288
programs that combine many concepts learned • IF…ELSE
earlier.
• FOR / WHILE
It is suitable for absolute beginners.
• SELECT CASE

Lesson 8: Simple Programs Using Many Concepts


5. Fully Commented Example Program 1

Program 1: Simple Calculator (Menu Based)


1. Lesson Title
REM Simple calculator program
Lesson 8: Simple Programs Using Many Concepts

PRINT "1. Addition"


2. Learning Objectives
PRINT "2. Subtraction"
After this lesson, you will be able to:
PRINT "3. Multiplication"
• Use INPUT and PRINT together
PRINT "4. Division"
• Use IF, loops, and SELECT CASE

• Write complete small programs


INPUT CHOICE 'Takes operation choice
• Think step by step like a programmer
INPUT A 'First number

INPUT B 'Second number


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

A real program uses many ideas together. SELECT CASE CHOICE

Real-life examples: CASE 1

• A calculator uses numbers and choices PRINT "Result = "; A + B

• A report card uses marks and averages CASE 2

• A game uses input, checking, and repeating PRINT "Result = "; A - B

In this lesson: CASE 3

• You will build small but complete programs PRINT "Result = "; A * B

• Each program uses many concepts together CASE 4

IF B <> 0 THEN

4. Syntax PRINT "Result = "; A / B

There is no single syntax here. ELSE


We combine:
PRINT "Cannot divide by zero"
• INPUT
END IF
• PRINT
CASE ELSE
22
Abu Farhad Sardar
7478085288
PRINT "Wrong choice"

END SELECT PRINT "Average Marks = "; AVG

6. Program Output (Program 1) 9. Program Output (Program 2)

If user enters: If user enters:

1 60

5 70

3 80

Output: 90

Result = 8 100

Output:

7. Step-by-Step Explanation of Program 1 Average Marks = 80

• Menu is printed using PRINT

• User selects an option 10. Step-by-Step Explanation of Program 2

• Two numbers are entered • SUM starts from 0

• SELECT CASE checks the choice • FOR loop runs 5 times

• 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!"


23
Abu Farhad Sardar
7478085288
END 1. Create a calculator for only addition and
subtraction
ELSE
2. Find average of 3 numbers
PRINT "Try Again"
3. Guess a number between 1 and 5
END IF
4. Print result PASS or FAIL using average
WEND
5. Create a menu for subjects

12. Program Output (Program 3)


16. Homework Challenge
If user enters:
Homework
5
Create a program that:
Output:
• Inputs marks of 5 subjects
Try Again
• Finds total and average
If user enters:
• Prints PASS if average ≥ 40
7
• Else prints FAIL
Output:
Bonus
Correct Guess!
Add:

• Grade using SELECT CASE


13. Step-by-Step Explanation of Program 3

• SECRET number is stored


Congratulations!
• WHILE loop runs continuously
You have completed the QBASIC Beginner Course.
• User enters a guess
You can now write simple programs on your own
• 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)

24
Abu Farhad Sardar
7478085288
Topic: Introduction to QBASIC & PRINT Statement

A. Short Answer Questions

1. What is a computer program?

2. What is QBASIC?

3. What does the PRINT statement do?

4. Why are double quotes used in PRINT?

5. Write one PRINT statement.

B. Write the Output

1.

PRINT "Hello"

PRINT "QBASIC"

2.

PRINT "My Name"

PRINT "Is Amit"

C. Small Coding Tasks

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
25
Abu Farhad Sardar
7478085288
B. Write the Output ELSE

1. PRINT "Small"

INPUT A END IF

PRINT A (User enters: 3)

(User enters: 8) 2.

2. INPUT M

INPUT NAME$ IF M >= 40 THEN PRINT "PASS"

PRINT "Hello "; NAME$ ELSE PRINT "FAIL"

(User enters: Riya) END IF

(User enters: 45)

C. Small Coding Tasks

1. Input your age and print it. C. Small Coding Tasks

2. Input two numbers and print their sum. 1. Check whether a number is positive or
negative.
3. Input your name and print a welcome
message. 2. Input marks and print PASS or FAIL.

3. Input age and check if age is 18 or more.

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

26
Abu Farhad Sardar
7478085288
NEXT I WHILE X > 1

2. PRINT X

FOR I = 1 TO 3 X=X-1

PRINT "Hi" WEND

NEXT I

C. Small Coding Tasks

C. Small Coding Tasks 1. Print numbers from 1 to 5 using WHILE.

1. Print numbers from 1 to 10. 2. Print your name 3 times using WHILE.

2. Print your name 5 times. 3. Print numbers from 10 to 1 using WHILE.

3. Print even numbers from 2 to 10.

Worksheet – Lesson 6

Worksheet – Lesson 5 Topic: SELECT CASE Statement

Topic: WHILE…WEND Loop A. Short Answer Questions

A. Short Answer Questions 1. What is SELECT CASE used for?

1. What is WHILE loop? 2. When is SELECT CASE better than IF?

2. When is WHILE loop used? 3. What is CASE ELSE?

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
27
Abu Farhad Sardar
7478085288
(User enters: 2)

2. C. Small Coding Tasks

(User enters: 7) 1. Store and print 5 numbers using array.

2. Find sum of 3 numbers using array.

C. Small Coding Tasks 3. Find average of 5 marks.

1. Menu for days of the week.

2. Menu for subjects (Maths, Science, English).

3. Menu-based calculator (Add/Subtract). Worksheet – Lesson 8

Topic: Programs Using Multiple Concepts

A. Short Answer Questions

Worksheet – Lesson 7 1. Why do we combine programming concepts?

Topic: Arrays (Single Dimensional) 2. Name any three QBASIC statements.

A. Short Answer Questions 3. What is a calculator program?

1. What is an array? 4. What is average?

2. Why is DIM used? 5. What is a guessing game?

3. What is an index?

4. Write array declaration syntax. B. Write the Output

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"


28
Abu Farhad Sardar
7478085288
END IF

C. Small Coding Tasks

1. Calculator using SELECT CASE.

2. Find average of 5 numbers and print


PASS/FAIL.

3. Guess a number between 1 and 5.

Teacher / Parent Note

• Section A → Viva & theory

• Section B → Written exam

• Section C → Lab practice

If you want next, I can:

• Add complete answer keys

• Convert this into a professional PDF

• Create MCQ papers

• Make unit tests & final exam

• Design holiday homework booklet

Just tell me

29

You might also like