Professional Documents
Culture Documents
10
Data Types, Assignment and Input / Output Statements
Q.10.01 Complete the following statements.
i) BASIC stands for________________________________________________
ii) Basic is well suited for computers having ________________ memory.
iii) In BASIC, key F1 is equivalent to the command ________________
iv) ________________ are the part of program which run in compiler’s mode.
v) To run a program press ________________ key.
vi) ________________ Statements allows you to enter value of variable while the
program is running.
Ans:
i) Beginner’s All-purpose Symbolic Instruction Code ii) limited
iii) LIST iv) Statement v) F2 vi) Input
1
(A) AND (B) OR (C) FIX (D) NOT
v) Which of the following types of the characters can be used as numeric variable
name?
(A) special (B) blank spaces (C) hyphen (D) none
vi) Equality operator is a:
(A) Logical operator (B) Functional operator
(C) Relational operator (C) Arithmetical operator
Ans:
i) (D) ii) (C) iii) (D) iv) (C) v) (D) vi) (C)
Q.10.04 Match the items given in Column I with those given in Column II
Column I Column II
i) Functional operator a) F1
ii) Save b) AND
iii) Command c) F2
iv) Load d) RND
v) Logical Operator e) F4
vi) List f) Less Than
g) Print
h) F3
Ans:
i) (d) ii) (e) iii) (g) iv) (h) v) (b) vi) (a)
Q.10.05 Write a short note on BASIC and describe some of its important features.
Ans: BASIC stands for Beginner’s All-purpose Symbolic Instruction Code. It is an easy high-
level computer programming language. It was developed in 1964. BASIC quickly became
one of the most popular programming languages.
Basic is first high level programming language to be used on microcomputers. First
interpreter of BASIC language was written in 1975 by Microsoft.
2
Q.10.06 What types of entries are made in BASIC? What is difference between commands
and statements?
Ans: There are three types of entries in BASIC. These are Commands, Statements and data.
Commands and Statements can be entered at any time. Data can be entered with the
data and assignment statement or when asked by the computer
Commands:
Commands are generally executed in direct mode. Commands usually perform some
type of program maintenance such as editing, clearing, running or saving.
Statements:
Statements are the part of the computer program and run in compiler’s mode or in
indirect mode. Statements are executed during running the program.
DELETE
Purpose: It deletes Program lines or line range.
Syntax: Following is the syntax of Delete Command.
Delete 50 It deletes the specified the line number.
LIST
Purpose: It displays the program or part of the program currently in the memory.
Syntax: Following is the syntax of List Command.
List It lists all program and lines currently in memory.
RENUM
Purpose: To renumber program lines without changing the order of the program.
Syntax: Following is the syntax of Renum Command.
Renum 100, 35, 10 First number specifies the new number in the new sequence for
the first line. Second number specifies old number of the line in
3
the current program. Third number specifies increment to be
used in the new sequence.
SYSTEM
Purpose: It is used to exit BASIC by entering the system command. Save program before
Pressing Enter Key.
Syntax: Following is the syntax of System Command.
System Press ENTER key
Q.10.08 How many types of variables names are used in BASIC? Give examples of invalid
variable names with explanation.
Ans: Ans: There are two types of variables:
(i) Numeric variable
(ii) String variable
4
Numeric constants are positive or negative numbers. A numeric constant in BASIC
cannot contain comma. Examples of numeric constants are 23, -46, 5.6, -7.4
(ii) String Constants:
A sting constant is any set of (maximum 255) character enclosed in quotation marks. For
Example “I LOVE PAKISTAN”, “47+17=?”
Q.10.10 Pick out numeric and strings from the following data items:
“Lahore” ; 27 ; “60W” ; 1.008 ; “16” ; 20km ; “23RD MARCH” ; IX ; A-1
Ans: Numeric Data: 27 , 1.008 , 20km , IX, A-1
String Data: “Lahore” , “60W” , “16” , “23RD MARCH”
Q.10.11 Explain various types of operators used in BASIC with examples.
Ans: There are four types of operators are used in GW Basic.
(i) Arithmetic Operator
(ii) Relational Operator
(iii) Logical Operator
(iv) Functional Operator
Operation Operator
Addition +
Subtraction -
Multiplication *
Division /
Power ^
Negation -
(ii) Relational Operators:
Relational operators are used to relate or compare two quantities. The result of comparison
may be either YES or NO or may be TRUE or FALSE. When these operators appear in a computer
program, their results decide the flow of the computer program.
Following are Relational Operators in GW Basic.
Operator Relation
= Equality
<> Inequality
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
5
(iii) Logical Operators:
Logical Operators such as AND, OR, NOT, NAND, NOR and XOR perform in the same way as in
Boolean algebra. The result of these logical operations would be either true or false. In a
computer program, such results are very important because they decide the flow of the
program.
Q.10.12 How does computer know whether an instruction you typed is a program.
Ans: When we type instructions in indirect mode then computer know these instructions are
program. Program must have line numbers.
Q.10.14 What will be the output? When you enter PRINT “37 C =” 37*9/5+32
Ans: Output will be
37 C = 98.6
value that will be used throughout the program, or when a variable is assigned a new value as a
result of computation or operation.
The assignment statement has the following format:
Line # (Let) variable name = variable or expression
The word let is optional in BASIC assignment. The term expression is defined as a combination of
two or more variables. It can be one or more constants and operators
Q.10.16 What is difference between STOP and END statement? Explain it with example.
Ans: STOP:
STOP command pause the current running statement. With the help of CONT command
we can run program again.
END:
6
END statement usually typed at the end of the program. It indicates program is finished.
Q.10.17 Write a program that prints three numbers, their sum and average using LET
statement.
Ans: 10 LET A = 10
20 LET B = 15
30 LET C = 20
40 LET SUM = A+B+C
50 LET AVG = SUM/3
60 PRINT “NUMBERS =” ; A;B;C
70 PRINT “SUM =” ; SUM
80 PRINT “AVERAGE =” ; AVG
90 END
Q.10.18 Write a program that prints three numbers, their sum and average using INPUT
statement.
Ans: 10 INPUT “ENTER ANY NUMBER”;A
20 INPUT “ENTER ANY NUMBER”;B
30 INPUT “ENTER ANY NUMBER”;C
40 LET SUM = A+B+C
50 LET AVG = SUM/3
60 PRINT “NUMBERS =” ; A;B;C
70 PRINT “SUM =” ; SUM
80 PRINT “AVERAGE =” ; AVG
90 END
Q.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.
Ans:
10 INPUT “ENTER ANY NUMBER”;A
20 LET SQUARE = A ^ 2
30 LET CUBE = A ^ 3
40 PRINT “SQUARE OF NO.” ;A; “=” ; SQUARE
50 PRINT “CUBE OF NO.” ;A; “=” ; CUBE
60 END
OUTPUT
ENTER ANY NUMBER ? 16
SQUARE OF NO. 16 = 256
CUBE OF NO. 16 = 4096
Q.10.20 Tell whether the following are valid BASIC statement/program. If not, find a possible
correction and its output if any.
7
a) 10 INPUT “ENTER A NUMBER”;N
Ans: This program is valid.
c) 10 INPUT A$ + 2
Ans: This program is not valid.
Correction:
10 INPUT A$
d) 10 READ A; B
20 PRINT 6,9
30 PRINT A+B
Ans: This program in not valid,
Correction:
10 READ A, B
20 PRINT A,B
30 DATA 6,9
Correction:
10 READ A$, B$, C$
20 PRINT “SUBJECTS” ; A$, B$, C$
30 DATA ENGLISH, PHYSICS, MATHEMATICS
40 END
f) 10 READ A,B,C
20 LET X=(A+B)*C
30 PRINT X
40 END
Ans: This program in not valid,
Correction:
10 READ A,B,C
20 LET X=(A+B)*C
30 PRINT X
40 DATA 10,20,30
8
g) 10 INPUT A,B$
20 C=A+B$
30 PRINT A : PRINT B$ : PRINT C
40 END
Ans: This program in not valid,
Correction:
10 INPUT A,B
20 C=A+B
30 PRINT A : PRINT B : PRINT C
40 END
Q.10.21What will be the output of the following program?
10 READ A$
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
Q.10.22 Write a BASIC program to calculate the sum, product and average of 4 numbers using
INPUT statement and READ – DATA statement.
Ans: Program using INPUT statement:
10 CLS
20 INPUT “ENTER ANY NUMBER”;A
30 INPUT “ENTER ANY NUMBER”;B
40 INPUT “ENTER ANY NUMBER”;C
50 INPUT “ENTER ANY NUMBER”;D
60 SUM =A+B+C+D
70 PROD = A*B*C*D
80 AVG = SUM/4
90 PRINT SUM
100 PRINT PROD
110 PRINT AVG
120 END
9
30 SUM =A+B+C+D
40 PROD = A*B*C*D
50 AVG = SUM/4
60 PRINT SUM
70 PRINT PROD
80 PRINT AVG
90 DATA 45,26,34,53
100 END
10