0% found this document useful (0 votes)
80 views

Data Types, Assignment and Input/output Statements in BASIC Programing Language

This document will cover the following areas: 1. Command of BASIC I.E Auto, Delete, List, Renum and System 2. How entries are made in BASIC 3. Variables, types of constants and types of operators are used in BASIC

Uploaded by

Engr Syed Yahya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Data Types, Assignment and Input/output Statements in BASIC Programing Language

This document will cover the following areas: 1. Command of BASIC I.E Auto, Delete, List, Renum and System 2. How entries are made in BASIC 3. Variables, types of constants and types of operators are used in BASIC

Uploaded by

Engr Syed Yahya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Class 10

Unit 10 (Data types, Assignment and Input/output Statements)


Question Answers

Question No 10.05: Write a note on BASIC and describe some of its features?
BASIC is first high level language. It is used on micro-computers. Microsoft wrote
first interpreter of BASIC. It has many versions. Most popular versions are GW-
BASIC and QBASIC.
Features:
i) It is easy and student friendly language.
ii) It is general purpose language.
iii) It is suitable for scientific and commercial programming.
iv) It has simple syntax rules. Therefore it is easy to test and debug.
v) Communication with computers is simple with it.

Question No 10.06: What types of entries are made in BASIC? What is


difference between commands and statements?
There are three types of entries that we can make in BASIC. They are:
i) Commands
ii) Program Statements
iii) Data
Difference between commands & statements:
Commands Statements

Commands are generally executable in the Statements run in the compiler’s mode.
direct mode. Statements are the part of a computer
Commands usually perform some type of program
program maintenance such as editing,
clearing, running, or saving programs.

1
Question No 10.07: Describe briefly the following commands?
Auto, Delete, List, Renum and System
Auto:
It generates an automatic line number each time <ENTER> key is pressed.
Delete:
It deletes Program lines or line range.
List:
It is used to display the program or part of the program currently in memory.
Renum:
It is sued to re-number program lines without changing the order of program
lines.
System:
It is used to exit BASIC to return to DOS by entering the SYSTEM command.

Question No 10.08: How many types of variables names are used in BASIC?
Give examples of invalid variable names with explanations.
Variables are names used to represent certain quantities in BASIC. There are two
types of variables used in BASIC. They are:
i) Numeric variables
ii) String variables
Invalid Variable Name Reason
5NUM Cannot begin with a digit
TOT PAY Blank spaces are not allowed
NET-PAY Hyphen not allowed
B&W Special symbol (&) not allowed
TAX$ $ symbol invalid for numeric
variable name
LIST Cannot use reserve words

2
Question No 10.09: Describe various types of constants used in BASIC with
examples.
Something that does not change its value during execution of the program is
called constant. It has following types:
Numeric Constants:
Numeric constants are positive or negative numbers. For example 23, -4.76 and
+53.15 etc. Numeric constants cannot contain commas.
String Constants:
A string constant is any set of (maximum 2555) characters enclosed in
quotation marks. Blank spaces may also be included but not quotation marks. For
example “I LOVE PAKISTAN”, “23RD MARCH”, AND “43+17=?” etc.

Question No 10.10: Pick out numeric and strings from the following data items:
“LAHORE” ;27; “60W”; 1.008; “16”; 20km; “23RD MARCH”; IX;A-1.

Numeric:
27; 1.008; 16; IX.
Strings:
“LAHORE”; “60W”; 20km; “23RD MARCH”; A-1

Question No 10.11: Explain various types of operators used in BASIC with


examples.
Operators perform mathematical or logical operations on values. It has following
types:

3
1-Arithmetic Operators:
These operators perform arithmetic operations like addition,
subtraction, multiplication etc.

Operation Operator Arithmetic Example


Addition + 5+8
Subtraction - 5-3
Multiplication * 5x3
Division / 5÷3

2-Relational Operators:
These are used to relate or compare two quantities
Operator Relation Example
= Equality If A = 15Then STOP
< Less Than If M < 50 Then Print FAIL
> Greater Than If M > 80 Then Print A+

3-Logical Operators:
Logical Operators such as AND, OR, NOT, NAND, NOR perform in the same way as
in Boolean algebra. The result of these logical operations would be either true or
false. These operators decide the flow of a program.
4-Functional Operators:
There are some built-in functions such as ABS, INT, FIX, RND, SQR, LOG, SIN and
COS. These functions make the programming much simpler.
Question No 10.12: How does computer know whether an instruction you typed
is a program?
When we enter RUN command the computer knows that the instruction we have
typed is a program.
Question No 10.13: What commands clears the computer’s memory?
The NEW command clears the computer’s memory but on some computers it
does not clear the screen.

4
The CLS command clears all files and clears all common and user variables from
computer’s memory. It resets the stack and string spaces.
Question No 10.14: What will be the output? When you enter PRINT
“37 C =“37*9/5+32?
37 C = 98.6 F

Question No 10.15: Write a note on assignment statements with examples?


The assignment statement is used when the programmer wishes to give a variable
an initial value that will be used throughout the program, or when a variable is
assigned a new value as a result of computation or operation. For example
the following statements assign number “5” to the variable M, and name
“KASHIF NAEEM” to the variable NAME$.

Question No 10.16: What is the difference between STOP and END statement?
Explain it with examples.
STOP Statement:
STOP statement is used to stop the program during execution at any
instance, whenever and wherever required. For example:
10 Let A = 5
20 Let B = 11
30 Let C = (A + B) / 2
40 STOP
50 PRINT C
60 END
END Statement:
END statement tells the computer where a certain program ends. For example:

5
10 Let A = 5
20 Let B = 11
30 Let C = (A + B) / 2
40 PRINT C
50 END
Question No 10.17: Write a program that prints three numbers, their sum and
average using LET statement.
10 CLS
20 LET A=10
30 LET B=20
40 LET C=30
50 PRINT “THE THREE NUMBERS ARE”; A, B, C
60 LET AVERAGE = (A+B+C)/3
70 LET SUM = A+B+C
80 PRINT “AVERAGE =”; AVERAGE
90 PRINT “SUM =”; SUM
100 END
Question No 10.18: Write a program that prints three numbers, their sum and
average using INPUT statement.
10 CLS
20 INPUT A
30 INPUT B
40 INPUT C
50 PRINT “THE THREE NUMBERS ARE”; A, B, C
60 AVERAGE= (A+B+C)/3

6
70 SUM=A+B+C
80 PRINT “AVERAGE =”; AVERAGE
90 PRINT “SUM =”; SUM
100 END
Question No 10.19: Write a program for the square and cube of any number
using INPUT statement. Print the number, its square and cube in zones.
10 CLS
20 INPUT A
30 LET SQUARE=A*A
40 LET CUBE=A*A*A
50 PRINT “THE NUMBER, ITS SQUARE AND CUBE IS “; A, SQUARE, CUBE
60 END
Question No 10.20: Tell whether the following are valid BASIC
statements/program. If not, give a possible correction and its output if any.
a) 10 INPUT “ ENTER A NUMBER “: N
ENTER A NUMBER?
b) 10 INPUT “ NUMBERS = “ X, Y, Z
This is not a valid BASIC statement. The correct statement is
10 INPUT “NUMBERS = “; X, Y, Z
c) 10 INPUT, A $ + 2
This is not a valid BASIC statement. We cannot add a string with a number.
d) 10 READ A; B
20 PRINT 6, 9
30 PRINT A + B
This is not a valid BASIC statement. The correct statement is
10 READ A, B
20 DATA 6, 9
30 PRINT A + B
OUTPUT:

7
15

e) 10 READ A$, B$, C$


20 PRINT “SUBJECTS”
30 DATA ENGLISH, PHYSICS, MATHEMATICS
40 END
This is not a valid BASIC statement. The correct statement is
10 READ A$, B$, C$
20 PRINT “SUBJECTS “A$, B$, C$
30 DATA ENGLISH, PHYSICS, MATHEMATICS
40 END
OUTPUT:
SUBJECTS ENGLISH PHYSICS MATHEMATICS
f) 10 READ A, B, C
20 LET X = (A + B) * C
30 PRINT X
40 END
This is not a valid BASIC statement. The correct statement is
10 READ A, B, C
20 LET X = (A + B) * C
30 PRINT X
40 DATA 10, 2, 2
50 END
OUTPUT:
24
g) 10 INPUT A, B$
20 C = A + B$
30 PRINT A: PRINT B$: PRINT C
40 END
This is not a valid BASIC statement.

Question No 10.21: What will be the output of the following program?


10 READ A$

8
20 PRINT A$
30 RESTORE
40 READ B$
50 PRINT B$
60 RESTORE
70 READ C$
80 PRINT C$
90 DATA ASLAM, AKRAM, AFZAL
100 END
OUTPUT:
ASLAM
ASLAM
ASLAM
Question No 10.22: Write a BASIC program to calculate the sum, product and
average of 4 numbers using INPUT statement and READ-DATA statements.
USING INPUT STATEMENT:
10 CLS
20 INPUT A, B, C, D
30 LET SUM=A+B+C+D
40 LET PRODUCT=A*B*C*D
50 LET AVERAGE=SUM/4
60 PRINT “THE FOUR NUMBERS ARE “; A, B, C, D
70 PRINT “THE SUM OF FOUR NUMBERS IS “; SUM
80 PRINT “THE AVERAGE OF FOUR NUMBERS IS “; AVERAGE
90 PRINT “THE PRODUCT OF FOUR NUMBERS IS “; PRODUCT
9
100 END
USING READ-DATA STATEMENT:
10 CLS
20 READ A, B, C, D
30 DATA 10, 20, 30, 40
40 SUM = A+B+C+D
50 AVERAGE = SUM/4
60 PRODUCT = A*B*C*D
70 PRINT “THE FOUR NUMBERS ARE “; A, B, C, D
80 PRINT “THE SUM OF FOUR NUMBERS IS “; SUM
90 PRINT “THE AVERAGE OF FOUR NUMBERS IS “; AVERAGE
100 PRINT “THE PRODUCT OF FOUR NUMBERS IS “; PRODUCT
110 END

10

You might also like