Вы находитесь на странице: 1из 33

Chapter 2 Data types, I/O statements

Introduction

Modes of Operation

Once GW-BASIC is initialized (loaded), it displays the Ok prompt. Ok means
GW-BASIC is at command level; that is, it is ready to accept commands. At this point,
GW-BASIC may be used in either of two modes: direct mode or indirect mode.

Direct Mode

In the direct mode, GW-BASIC statements and commands are executed as they are
entered. Results of arithmetic and logical operations can be displayed immediately
and/or stored for later use, but the instructions themselves are lost after execution. This
mode is useful for debugging and for using GW-BASIC as a calculator for quick
computations that do not require a complete program.

Indirect Mode

The indirect mode is used to enter programs. Program lines are always preceded by
line numbers, and are stored in memory. The program stored in memory is executed by
entering the RUN command.

Commands

Commands and statements are both executable instructions. The difference between
commands and statements is that commands are generally executed in the direct
mode, or command level of the interpreter.

Statements

A statement, such as ON ERROR...GOTO, is a group of GW-BASIC keywords
generally used in GW-BASIC program lines as part of a program. When the pro- gram is
run, statements are executed when, and as, they appear

Numeric Functions
The GW-BASIC Interpreter can perform certain mathematical (arithmetical or algebraic)
calculations. For example, it calculates the sine (SIN), cosine (COS), or tangent (TAN)
of angle x.
Unless otherwise indicated, only integer and single-precision results are returned by
numeric functions.

String Functions
String functions operate on strings. For example, TIME$ and DATE$ return the time and
date known by the system. If the current time and date are entered during system start
up, the correct time and date are given (the internal clock in the computer keeps track).

Variables
Certain groups of alphanumeric characters are assigned values and are
called variables. When variables are built into the GW-BASIC program they provide
information as they are executed.







GW-BASIC COMMANDS

Command Usage
AUTO This command is used to automatically generate line numbers
CLS This command is used to clear the screen
NEW This command is used to clear the Memory.
SAVE This command is used to save the program on disk.
LIST This command is used to list all or part of the program currently in
memory.
LOAD This command is used to load a program file from disk into main
memory.
FILES This command is used to display the list of files from specified
drive.
RUN This command is used to execute the program currently in
memory.
EDIT This command is used to edit a specified program line currently in
memory
DELETE This command is used to delete a specified program line in current
memory.
RENUM This command is used to renumber the program lines in RAM.
KILL This command is used to delete a program from disk.
SYSTEM This command is used to exit from GW-BASIC and return to
operating system.
LLIST This command is used to list all or part of the program currently in
the memory to the printer.



AUTO Command
Purpose:
To generate and increment line numbers automatically each time you press the
RETURN key.
Syntax:
AUTO [line number][,[increment]]
AUTO .[,[increment]]


File Commands
The following are the commands and statements most frequently used with program
files. The GW-BASIC User's Reference contains more information on each of them.
SAVE filename[,a][,p]
Writes to diskette the program currently residing in memory.
LOAD filename[,r]
Loads the program from a diskette into memory. LOAD deletes the current contents of
memory and closes all files before loading the program.
RUN filename[,r]
Loads the program from a diskette into memory and runs it immediately. RUN deletes
the current contents of memory and closes all files before loading the program.
MERGE filename
Loads the program from a diskette into memory, but does not delete the current
program already in memory.
KILL filename
Deletes the file from a diskette. This command can also be used with data files.
NAME old filename AS new filename
Changes the name of a diskette file. Only the name of the file is changed. The file is not
modified, and it remains in the same space and position on the disk. This command can
also be used with data files.

KILL Command
Purpose:
To delete a file from a disk.
Syntax:
KILL filename
Comments:
filename can be a program file, sequential file, or random-access data file.
KILL is used for all types of disk files, including program, random data, and sequential
data files.
LOAD Command
Purpose:
To load a file from diskette into memory.
Syntax:
LOAD filename[,r]
Comments:
filename is the filename used when the file was saved. If the extension was omitted,
.BAS will be used.
LOAD closes all open files and deletes all variables and program lines currently residing
in memory before it loads the designated program.
If the r option is used with LOAD, the program runs after it is loaded, and all open data
files are kept open.
LOAD with the r option lets you chain several programs (or segments of the same
program). Information can be passed between the programs using the disk data files.
MKDIR Command
Purpose:
To create a subdirectory.
Syntax:
MKDIR pathname
Comments:
pathname is a string expression, not exceeding 63 characters, identifying the
subdirectory to be created.
Examples:
MKDIR "C:SALES\JOHN"

EDIT Command
Purpose:
To display a specified line, and to position the cursor under the first digit of the line
number, so that the line may be edited.
Syntax:
EDIT line number
EDIT .
Comments:
line number is the number of a line existing in the program.
A period (.) refers to the current line. The following command enters EDIT at the current
line:
EDIT .

RENUM Command
Purpose:
To renumber program lines.
Syntax:
RENUM[new number],[old number][,incrementR]]
Comments:
new number is the first line number to be used in the new sequence. The default is 10.
old number is the line in the current program where renumbering is to begin. The default
is the first line of the program.
increment is the increment to be used in the new sequence. The default is 10.
RMDIR Command
Purpose:
To delete a subdirectory.
Syntax:
RMDIR pathname
Comments:
pathname is a string expression, not exceeding 63 characters, identifying the
subdirectory to be removed from its parent.
The subdirectory to be deleted must be empty of all files except "." and ".." or a "Path
file/access error" is given.
Examples:
Referring to the sample directory structure illustrated in CHDIR, the following command
deletes the subdirectory report:
RMDIR "SALES\JOHN\REPORT"


RMDIR Command
Purpose:
To delete a subdirectory.
Syntax:
RMDIR pathname
Comments:
pathname is a string expression, not exceeding 63 characters, identifying the
subdirectory to be removed from its parent.
The subdirectory to be deleted must be empty of all files except "." and ".." or a "Path
file/access error" is given.
Examples:
Referring to the sample directory structure illustrated in CHDIR, the following command
deletes the subdirectory report:
RMDIR "SALES\JOHN\REPORT"


RMDIR Command
Purpose:
To delete a subdirectory.
Syntax:
RMDIR pathname
Comments:
pathname is a string expression, not exceeding 63 characters, identifying the
subdirectory to be removed from its parent.
The subdirectory to be deleted must be empty of all files except "." and ".." or a "Path
file/access error" is given.
Examples:
Referring to the sample directory structure illustrated in CHDIR, the following command
deletes the subdirectory report:
RMDIR "SALES\JOHN\REPORT"

RUN Command
Purpose:
To execute the program currently in memory, or to load a file from the diskette into
memory and run it.
Syntax:
RUN [line number][,r]
RUN filename[,r]
Comments:
RUN or RUN line number runs the program currently in memory.
If line number is specified, execution begins on that line. Otherwise, execution begins at
the lower line number.
If there is no program in memory when RUN is executed, GW-BASIC returns to
command level.
RUN filename closes all open files and deletes the current memory contents before
loading the specified file from disk into memory and executing it.
The r option keeps all data files open.
If you are using the speaker on the computer, please note that executing the RUN
command will turn off any sound that is currently running and will reset to Music
Foreground. Also, the PEN and STRIG Statements are reset to OFF.
Examples:
RUN "NEWFIL", R
Runs NEWFIL.BAS without closing data files.

SAVE Command
Purpose:
To save a program file on diskette.
Syntax:
SAVE filename,[,a]
SAVE filename,[,p]
Comments:
filename is a quoted string that follows the normal MS-DOS naming conventions. If
filename already exists, the file will be written over. If the extension is omitted, .bas will
be used.
The a option saves the file in ASCII format. Otherwise, GW-BASIC saves the file in a
compressed binary format. ASCII format takes more space on the diskette, but some
diskette access commands (for example, the MERGE command and some MS-DOS
commands, such as TYPE) may require an ASCII format file.
The p option protects the file by saving it in an encoded binary format. When a
protected file is later run or loaded, any attempt to list or edit it fails. When the p option
is used, make an additional copy under another name or diskette to facilitate future
program maintenance.
Examples:
The following command saves the file com2.bas in the ASCII format:
SAVE "COM2", A
The following command saves the file prog.bas in binary format, and protects access:
SAVE "PROG", P

SYSTEM Command
Purpose:
To return to MS-DOS.
Syntax:
SYSTEM
Comments:
Save your program before pressing RETURN, or the program will be lost.
The SYSTEM command closes all the files before it returns to MS-DOS. If you entered
GW-BASIC through a batch file from MS-DOS, the SYSTEM command returns you to
the batch file, which continues executing at the point it left off.
Examples:
SYSTEM
A>

LIST Command
Purpose:
To list all or part of a program to the screen, line printer, or file.
Syntax:
LIST [line number][-line number][,filename]
LIST [line number-][,filename]
Comments:
line number is a valid line number within the range of 0 to 65529.
If filename is omitted, the specified lines are listed to the screen.
Use the hyphen to specify a line range. If the line range is omitted, the entire program is
listed. line number- lists that line and all higher numbered lines. -line number lists lines
from the beginning of the program through the specified line.
The period (.) can replace either line number to indicate the current line.
Any listing may be interrupted by pressing CTRL-BREAK.
Examples:
LIST
Lists all lines in the program.
LIST -20
Lists lines 1 through 20.
LIST 10-20
Lists lines 10 through 20.
LIST 20-
Lists lines 20 through the end of the program.

LLIST Command
Purpose:
To list all or part of the program currently in memory to the line printer.
Syntax:
LLIST [line number][-line number]
LLIST [line number-]
Comments:
GW-BASIC always returns to command level after a LLIST is executed. The line range
options for LLIST are the same as for LIST.
Examples:
See the examples in the LIST statement.

LPRINT and LPRINT
Purpose:
To print data at the line printer.
Syntax:
LPRINT [list of expressions][;]
LPRINT USING string exp; list of expressions[;]
Comments:
list of expressions consists of the string or numeric expression separated by
semicolons.
string expressions is a string literal or variable consisting of special formatting
characters. The formatting characters determine the field and the format of printed
strings or numbers.

CONT Command
Purpose:
To continue program execution after a break.
Syntax:
CONT
Comments:
Resumes program execution after CTRL-BREAK, STOP, or END halts a program.
Execution continues at the point where the break happened. If the break took place
during an INPUT statement, execution continues after reprinting the prompt.
CONT is useful in debugging, in that it lets you set break points with the STOP
statement, modify variables using direct statements, continue program execution, or use
GOTO to resume execution at a particular line number. If a program line is modified,
CONT will be invalid.

Basic Statements

END Statement
Purpose:
To terminate program execution, close all files, and return to command level.
Syntax:
END
Comments:
END statements may be placed anywhere in the program to terminate execution.
Unlike the STOP statement, END does not cause a "Break in line xxxx" message to be
printed.
An END statement at the end of a program is optional. GW-BASIC always returns to
command level after an END is executed.
END closes all files.
Examples:
520 IF K>1000 THEN END ELSE GOTO 20
Ends the program and returns to command level whenever the value of K exceeds
1000.

REM Statement
Purpose:
To allow explanatory remarks to be inserted in a program.
Syntax:
REM[comment]
'[comment]
Comments:
REM statements are not executed, but are output exactly as entered when the program
is listed.
Once a REM or its abbreviation, an apostrophe ('), is encountered, the program ignores
everything else until the next line number or program end is encountered.
REM statements may be branched into from a GOTO or GOSUB statement, and
execution continues with the first executable statement after the REM statement.
However, the program runs faster if the branch is made to the first statement.
Remarks may be added to the end of a line by preceding the remark with an apostrophe
(') instead of REM.
STOP Statement
Purpose:
To terminate program execution and return to command level.
Syntax:
STOP
Comments:
STOP statements may be used anywhere in a program to terminate execution. When a
STOP is encountered, the following message is printed:
Break in line nnnnn

Character Set of BASIC and Operators
The following are the characters valid for GW-BASIC
Character Meaning
= Equal sign or assignment symbol
+ Plus sign or string concatenation
- minus sign
* Asterisk or multiplication symbol
/ Slash or division symbol
^ Carter, exponentiation symbol, or CTRL key
( Left parenthesis
) Right parenthesis
% Percentage or integer declaration
# Number sign or double precision declaration
Exclamation point or single precision declaration
[ Left bracket
] Right bracket
, Comma
Double quotation marks or string delimiter
. Period ,dot or decimal point
Single quotation mark, apostrophe, or remark indicator
; Semi colon or carriage return suppressor
: Colon or line statement delimiter
& Ampersand or descriptor for hexadecimal and octal
number
? Question mark
< Less than symbol
> Greater than symbol
\ Backslash or integer division symbol
@ At sign
__ Underscore
BACK SPACE Deletes last character typed
ESC Erases the current line from the screen
TAB Moves print position to next tab stop. Tab stops are
every eight columns.
ENTER Terminates input to a line and moves cursor to
beginning of the next line ,or executes statement in
direct mode.

Assignment Statement

LET Statement
Purpose:
To assign the value of an expression to a variable.
Syntax:
[LET] variable=expression
Comments:
The word LET is optional; that is, the equal sign is sufficient when assigning an expression to a
variable name.
The LET statement is seldom used. It is included here to ensure compatibility with previous
versions of BASIC that require it.
When using LET, remember that the type of the variable and the type of the expression must
match. If they don't, a "Type mismatch" error occurs.

Input and Output Statement

Read and DATA statement
DATA Statement
Purpose:
To store the numeric and string constants that are accessed by the program READ statement(s).
Syntax:
DATA constants
Comments:
constants are numeric constants in any format (fixed point, floating-point, or integer), separated
by commas. No expressions are allowed in the list.
String constants in DATA statements must be surrounded by double quotation marks only if they
contain commas, colons, or significant leading or trailing spaces. Otherwise, quotation marks are
not needed.
DATA statements are not executable and may be placed anywhere in the program. A DATA
statement can contain as many constants that will fit on a line (separated by commas), and any
number of DATA statements may be used in a program.

READ Statement
Purpose:
To read values from a DATA statement and assign them to variables.
Syntax:
READ list of variables
Comments:
A READ statement must always be used with a DATA statement.
READ statements assign variables to DATA statement values on a one-to-one basis.
READ statement variables may be numeric or string, and the values read must agree with the
variable types specified. If they do not agree, a "Syntax error" results.
A single READ statement may access one or more DATA statements. They are accessed in
order. Several READ statements may access the same DATA statement.

RESTORE Statement
Purpose:
To allow DATA statements to be reread from a specified line.
Syntax:
RESTORE[line number]
Comments:
If line number is specified, the next READ statement accesses the first item in the specified
DATA statement.
If line number is omitted, the next READ statement accesses the first item in the first DATA
statement.

Input Statement
INPUT Statement
Purpose:
To prepare the program for input from the terminal during program execution.
Syntax:
INPUT[;][prompt string;] list of variables
INPUT[;][prompt string,] list of variables
Comments:
prompt string is a request for data to be supplied during program execution.
list of variables contains the variable(s) that stores the data in the prompt string.
Each data item in the prompt string must be surrounded by double quotation marks, followed by
a semicolon or comma and the name of the variable to which it will be assigned. If more than
one variable is given, data items must be separated by commas.
PRINT Statement
Purpose:
To output a display to the screen.
Syntax:
PRINT [list of expressions][;]
?[list of expressions][;]
Comments:
If list of expressions is omitted, a blank line is displayed.
If list of expressions is included, the values of the expressions are displayed. Expressions in the
list may be numeric and/or string expressions, separated by commas, spaces, or semicolons.
String constants in the list must be enclosed in double quotation marks.




MCQS

A sequence of instructions given to the computer to perform a specific task is called
_____________.
a. Data
b. Program
c. Programming
d. Information

What is a named space in the computers memory whose value can be changed during
the execution of a program?
a. Variable
b. Constant
c. Program
d. Data

In BASIC programming language which character is used as a last character with string
variable?
a. ?
b. &
c. %
d. $

Which shortcut key is used to apply RUN command in GWBASIC?
a. F1
b. F2
c. F3
d. F4

5. Which of the following error cannot be detected by a computer?
a. Syntax error
b. Run time error
c. Logical error
d. Execution error

6. Which of the following is a logical operator?
a. +
b.
c. >
d. /

7. Which of the following operator has the highest priority?
a. +
b. ^
c.
d. *


8. If A=5, B=3 and C=2, what will be the answer of the following expression?
Exp=A+B*C
a. 10
b. 11
c. 13
d. 16

9. Which of the following statements is used to accept data from the user during
program execution?
a. PRINT
b. LOAD
c. READ-DATA
d. INPUT

10. The set of rules that define the combination of symbols used by programming
languages is called _____________.
a. Syntax
b. Data
c. Program
d. Logic

11. ____________ languages are the means of communication between users
and the computer.
a. Operating
b. Programming
c. Printing
d.Writing

All are the following are logical operator except?
A NOT
B OR
C AND
D Neither

All are the following are logical operator except?
A NOT
B OR
C AND
D Neither

The result of 10 Mod 3 is
A 3
B 30
C One
D 2

Which of the following key is used to save a file in GW Basic ?
A F2
B F1
C F3
D F4


Question 1
All are the following are logical operator except?
A NOT
B OR
C AND
D Neither

Question 2
The result of 10 Mod 3 is
A 3
B 30
C One
D 2

Question 3
Which of the following key is used to save a file in GW Basic ?
A F2
B F1
C F3
D F4

Question 4
A Variable name must start with a(an) ?
A Alphabets
B Special character
C Digit
D Underscore


Question 1
All are the following are logical operator except?
A NOT
B OR
C AND
D Neither

Question 2
The result of 10 Mod 3 is
A 3
B 30
C One
D 2

Question 3
Which of the following key is used to save a file in GW Basic ?
A F2
B F1
C F3
D F4

Question 4
A Variable name must start with a(an) ?
A Alphabets
B Special character
C Digit
D Underscore

Question 5
Which short key is used to save the Document ?
A Ctrl+S
B Ctrl+V
C Ctrl+T
D Ctrl+B

Question 1
All are the following are logical operator except?
A NOT
B OR
C AND
D Neither

Question 2
The result of 10 Mod 3 is
A 3
B 30
C One
D 2

Question 3
Which of the following key is used to save a file in GW Basic ?
A F2
B F1
C F3
D F4

Question 4
A Variable name must start with a(an) ?
A Alphabets
B Special character
C Digit
D Underscore

Question 5
Which short key is used to save the Document ?
A Ctrl+S
B Ctrl+V
C Ctrl+T
D Ctrl+B

Question 6
How many types of error can occur in GW Basic Program ?
A 1
B 4
C 3
D 2


Types of array are ?
A 8
B 4
C 6
D 2

Which of the following statement command continues the program whose execution
was terminated temporarily?
A CONTINUE
B CONT
C RESTART
D START


If two or more statement are written on a line, they must by separated by a :
A Colon
B Semicolon
C Comma
D Hyphen


GW-BASIC can operate in :
A Three modes
B One mode
C Several modes
D Two modes


When a floating-point value is converted to an integer, the fractional parts :
A May be Truncated or Rounded off
B Truncated
C Conversion is impossible
D Rounded off


Which of the following statement temporarily stops the execution of a program?
A STOP
B END
C BREAK
D PAUSE


A variable name must start with a(n):
A Underscore
B Digit
C Alphabet or Underscore
D Alphabet


The maximum length of a variable name in GW-BASIC is :
A 31
B 40
C 32
D 45


Which of the following operator has the highest precedence?
A +
B =
C *
D ^


Which of the following is a type conversion character for integer variables
A $
B #
C %
D !



MORE MCQS


1. When we say that we have a program, it means that we know about a:
(a) complete set of numbers to be performed in a particular order to solve some
problem
(b) complete set of problems to be performed in a particular order to solve some
problem
(c) complete set of activities to be performed in a particular order to solve some
problem
(d) complete set of formulas to be performed in a particular order to solve some
program
Ans. (c)
2. A computer program is a precise sequence of steps to solve:
(a) a particular problem (b) a method
(c) a computer (d) something strange
Ans. (a)
3. At its most basic level, programming a computer simply means to tell a computer:
(a) to shut down (b) play a video (c) start working (d) what to
do
Ans. (d)
4. The basic language of computer is:
(a) C++ (b) JAVA
(c) VISUAL BASIC (d) Machine Code or Machine
Language
Ans. (d)
5. A computer has a memory comprising of switches which are:
(a) "on" or "off" (b) always On (c) always Off
(d) always On and Off
Ans. (a)
6. The only language that a computer understands is:
(a) JAVA (b) COBOL
(c) BASIC (d) MAchine Language or
Machine Code
Ans. (a)
7. 1s and 0s are called:
(a) Numbers (b) Arithmetics
(c) binary number system (d) number system
Ans. (c)
8. Binary number system is also called:
(a) Numbers (b) Arithmetics
(c) binary number system (d) machine code or machine
language.
Ans. (d)
9. A programming Language based on Machine Language is called a:
(a) Binary language (b) High level language
(c) Low Level Language (d) computer language
Ans. (c)
10. It is very difficult to write a computer program in Machine Language or Machine
Code so
Computer programmers use
(a) Binary language (b) Programming Languages
(c) Low Level Language (d) computer language
Ans. (b)
11. Programming Languages are:
(a) Binary language (b) computer language
(c) Low Level Language (d) High Level Language
Ans. (d)
12. The program written in a High Level language are saved in a file which is called:
(a) Program file (b) save file (c) Object code (d) Source
Code
Ans. (d)
13. After writing a program into Source Code the programmer converts it into:
(a) Program file (b) save file (c) Machine code (d) Source
Code
Ans. (c)
14. The program in Source Code is converted into Machine code so that:
(a) it can be run on a computer (b) it can be saved
(c) it can be seen (d) it can be valuable
Ans. (a)
15. The job of converting Source Code into Machine Code is carried out by two types
of
programs which are called:
(a) Computer and monitor (b) Floppy and hard disk
(c) Compiler and Interpreter (d) Machine and Language
Ans. (c)
16. A compiler converts all the source code into:
(a) Computer (b) hard disk (c) machine code (d) a
new language
Ans. (c)
17. A compiler converts all the source code into a machine code creating an:
(a) source code (b) executable file. (c) inside copy (d)
interesting file
Ans. (b)
18. An Interpreter converts a source code into:
(a) new code (b) executable file (c) machine code (d)
object code
Ans. (c)
19. An Interpreter simply executes each bit of machine code as it is:
(a) converted (b) downloaded (c) printed (d)
objected
Ans. (a)
20. An Interpreter does not create an:
(a) inside memory (b) executable file (c) display (d) source
code
Ans. (b)
21. List showing popular Interpreted languages is:
(a) C, C++, Visual Basic (b) LISP, BASIC, PERL
(c) COBOL, FORTRON, C++ (d) JAVA, C,COBOL
Ans. (b)
22. A Constant is a quantity whose value cannot be:
(a) Read (b) Printed (c) changed (d)
memorized
Ans. (c)
23. A Variable is a quantity whose value can be:
(a) Read (b) Printed (c) changed (d)
memorized
Ans. (c)
24. A Constant can be:
(a) Long or short (b) New or old
(c) changed or unchanged (d) numeric or string
Ans. (d)
25. A Numeric Constant consists of:
(a) Long or short values (b) New or old values
(c) changed or unchanged values
(d) integers, single-precision or double- precision numbers.
Ans. (d)
26. A String Constant is a sequence of:
(a) Long or short values (b) New or old values
(c) changed or unchanged values
(d) alphanumeric characters enclosed in double quotation marks.
Ans. (d)
27. The maximum length of a String Constant is:
(a) 55 characters (b) 155 characters (c) 255 characters (d) 355
characters.
Ans. (c)
28. In GW-BASIC Variables are the names of:
(a) characters (b) values (c) constants
(d) Memory Cells
Ans. (d)
29. Memory Cells which are used to store program's input data and its computational
results
during
(a) multiplication (b) subtraction
(c) division (d) the execution of program
Ans. (d)
30. A Variable name cannot be more than:
(a) 20 characters (b) 40 characters (c) 60 characters (d) 80
characters
Ans. (b)
31. The name of Variable may contain:
(a) alphabets (b) numbers
(c) decimal points (d) alphabets, numbers and
decimal points.
Ans. (d)
32. The first character in name of Variable must be:
(a) an alphabets (b) a numbers (c) a decimal points (d) a symbol
Ans. (a)
33. The words which cannot be used as Variables are:
(a) Roman words (b) Urdu words
(c) English words (d) Key /Reserved words of
BASIC
Ans. (d)
34. What is not allowed in names of Variables:
(a) Numbers (b) Alphabets (c) decimal points (d)
Blank space
Ans. (d)
35. Last character of variable name should indicate the:
(a) decimalpoint (b) type of variable (c) number (d) Blank
space
Ans. (b)
36. The memory required for $ string variable is:
(a) 2 Bytes (b) 4 Bytes (c) String length (d) 8 Bytes
Ans. (c)
37. The memory required for % Integer variable is:
(a) 2 Bytes (b) 4 Bytes (c) 6 Bytes (d) 8 Bytes
Ans. (a)
38. The memory required for ! single precision variable is:
(a) 2 Bytes (b) 4 Bytes (c) 6 Bytes (d) 8 Bytes
Ans. (b)
39. The memory required for # double precision variable is:
(a) 2 Bytes (b) 4 Bytes (c) 6 Bytes (d) 8 Bytes
Ans. (d)
40. The character used for double precision variable is:
(a) ! (b) $ (c) % (d) #
Ans. (d)
41. The character used for single precision variable is:
(a) ! (b) $ (c) % (d) #
Ans. (a)
42. The character used for Integer variable is:
(a) ! (b) $ (c) % (d) #
Ans. (c)
43. The character used for string variable is:
(a) ! (b) $ (c) % (d) #
Ans. (b)
44. The types of variables are:
(a) one (b) two (c) three (d)
four
Ans. (b)
45. The names of the types of variables are:
(a) decimal variable and point veriable (b) Numeric Variables and String
Variables
(c) Quotation variables and interogative variables (d) Simeple variables and
complex variables
Ans. (b)




SHORT QUESTIONS


DEFINE Different Commands

AUTO Command
Purpose:
To generate and increment line numbers automatically each time you press the RETURN key.
Syntax:
AUTO [line number][,[increment]]
AUTO .[,[increment]]


CONT Command
Purpose:
To continue program execution after a break.
Syntax:
CONT

DATA Statement
Purpose:
To store the numeric and string constants that are accessed by the program READ statement(s).
Syntax:
DATA constants
Comments:
constants are numeric constants in any format (fixed point, floating-point, or integer), separated
by commas. No expressions are allowed in the list.
EDIT Command
Purpose:
To display a specified line, and to position the cursor under the first digit of the line number, so
that the line may be edited.
Syntax:
EDIT line number
EDIT .
Comments:
line number is the number of a line existing in the program.
Q#1. What are modes of BASIC?
Ans: GW BASIC operates in two Modes
1. Direct Mode
2. Indirect Mode
Direct Mode:
Commands do not preceded by Line numbers.
Commands are executed as they are typed.
Commands are lost after execution.
It is used for debugging and quick computations.
InDirect Mode:
Commands are preceded by Line numbers.
Commands are not executed as they are typed.
Commands are not lost after execution.
It is used for typing a program in BASIC.


Q#2. Write steps to SAVE a file in BASIC.
Ans: After writing program, It must be stored on hard disk for later retrieval.
Following are steps to save file in BASIC.

Press F4 key OR type SAVE command.
Type the full path with valid file name and extension.
Press Enter key. File will be saved on specified location.




Q#3. Write steps to LOAD a file in BASIC.
Ans: Before executing a program, It must be loaded from hard disk to the RAM.
Following are steps to Load file in BASIC.

Press F3 key OR type LOAD command.
Type the full path with valid file name and extension.
Press Enter key. File will be loaded in memory.

Q#4. What are reserved words in BASIC? Give Examples.
Ans: Reserved words are also called Keywords. They have predefined meanings in
BASIC. They can only be used for the purpose for which they are developed. They cant
be used for other purposes like as name of variables.
Examples:
IF, ELSE, FOR, NEXT, DIM, THEN, WHILE, WEND
GOTO, GO SUB, LET

Q#5. What is a variable? Write 5 rules for naming variables.
Ans: It is a quantity whose value may change during the execution of the program. It is
name of the memory location. It is used to store input data or results of computations.
Rules for variable Declaration
Variable name cant be more than 40 characters long.
First character of name must be alphabet.
Reserved words cant be used as variable name.
Blank spaces are not allowed in name.
Name can contain alphabets, digits, and special characters.

Q#6. What is SAVE command? Give syntax with example.
Ans: This Command is used to store file on disk for later use.
Syntax:
SAVE path with filename, [a]
SAVE path with filename, [p]

Explanation:
By default file is saved in compressed binary format.

If [a] is used then file is stored in ASCII format. If [p] is used then file is stored in
encoded binary format (protected).
Example:
SAVE C:\Sum.BAS => Compressed binary format
SAVE C:\Factorial.BAS, a => ASCII format
SAVE C:\ Matrix.BAS, p => Encoded binary format


Q#7. What are I/O statements in BASIC? Give examples.
Ans: I/O statements mean input and output statements.
Input Statement:
A statement which is used to give input to the program is called input
statement.
Example:
Examples of Input statement are
READ/DATA Statement
INPUT Statement

Output Statement:
A statement which is used to display output of the program is called
Output statement.
Example:
Examples of Output statement are
PRINT Statement
PRINT USING Statement

Q#8. What are type declaration characters in BASIC?
Ans: In BASIC, type declaration characters are used to represent data type of a specific
variable.
Character Data Type Example Size in memory
$ String Name$ String length
% Integer Marks% 2 Byte
! Single precision Avg! 4 Byte
# Double precision Area# 8 Byte

What is an INPUT Statements
This statement is used to input data from the user during the program execution. Its Syntax is:
INPUT [;] [prompt string;] comma-separated list of variables.
In this Syntax the prompt string is the message that is displayed on the screen to
assist the user to input correct data. During program execution the values entered by the user are
assigned to the corresponding variables according to the same sequence in which they are listed.
When a semicolon is used to separate the prompt string from the list of variables a question
mark (?) appears at the end of the prompt string. This question mark can be avoided by using a
comma instead of a semicolon.


What do you meant by READ Statements
This statement reads values from the DATA statement and assigns them to corresponding
variables. Its Syntax is:
READ comma-separated list of variables
The READ statement is a part of the DATA statement and is always used in
conjunction. The READ statement specifies a list of variables and reads the corresponding values
for these variables from the list of constants specified in DATA statement. The first variable in
READ statement is assigned by the first value from the list of constants in DATA statement.
Similarly the second variable in READ statement is assigned by the second value from the list
of constants in DATA statement, and so on. The variable type (numeric or string) given in
READ statement must agree with the corresponding constant in the DATAstatement


What is DATA Statements
This Statement is used to store the numeric and string constants that are accessed by a READ
statement specified somewhere in the program.Its Syntax is:
DATA comma-separated list of constants
In this statement Constants may be string or numeric. The string constants, if they
contain commas, colons or spaces, then they must be enclosed in double quotation marks.

Вам также может понравиться