chapter 2 data types

Upload: muhammad-dawood

Post on 12-Oct-2015

31 views

Category:

Documents


0 download

DESCRIPTION

this is the chapter 2 for computer science

TRANSCRIPT

  • 5/21/2018 Chapter 2 Data Types

    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.

  • 5/21/2018 Chapter 2 Data Types

    2/33

    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 anglex.

    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.

  • 5/21/2018 Chapter 2 Data Types

    3/33

    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 inmemory.

    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 specifieddrive.

    RUN This command is used to execute the program currently inmemory.

    EDIT This command is used to edit a specified program line currently inmemory

    DELETE This command is used to delete a specified program line in currentmemory.

    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 tooperating system.

    LLIST This command is used to list all or part of the program currently inthe memory to the printer.

    AUTO Command

    Purpose:

    To generate and increment line numbers automatically each time you press theRETURN key.

    Syntax:AUTO[line number][,[increment]]AUTO.[,[increment]]

  • 5/21/2018 Chapter 2 Data Types

    4/33

    File Commands

    The following are the commands and statements most frequently used with programfiles. The GW-BASIC User's Referencecontains more information on each of them.

    SAVEfilename[,a][,p]

    Writes to diskette the program currently residing in memory.

    LOADfilename[,r]

    Loads the program from a diskette into memory. LOAD deletes the current contents ofmemory and closes all files before loading the program.

    RUNfilename[,r]

    Loads the program from a diskette into memory and runs it immediately. RUN deletesthe current contents of memory and closes all files before loading the program.

    MERGEfilename

    Loads the program from a diskette into memory, but does not delete the currentprogram already in memory.

    KILLfilename

    Deletes the file from a diskette. This command can also be used with data files.

    NAMEold filenameASnew filename

    Changes the name of a diskette file. Only the nameof the file is changed. The file is notmodified, and it remains in the same space and position on the disk. This command canalso be used with data files.

    KILL Command

    Purpose:

    To delete a file from a disk.

    Syntax:KILLfilename

  • 5/21/2018 Chapter 2 Data Types

    5/33

    Comments:

    filenamecan 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:LOADfilename[,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 residingin memory before it loads the designated program.

    If the roption is used with LOAD, the program runs after it is loaded, and all open datafiles are kept open.

    LOAD with the r option lets you chain several programs (or segments of the sameprogram). Information can be passed between the programs using the disk data files.

    MKDIR Command

    Purpose:

    To create a subdirectory.

    Syntax:MKDIRpathname

    Comments:

    pathname is a string expression, not exceeding 63 characters, identifying thesubdirectory to be created.

    Examples:MKDIR "C:SALES\JOHN"

  • 5/21/2018 Chapter 2 Data Types

    6/33

    EDIT Command

    Purpose:

    To display a specified line, and to position the cursor under the first digit of the linenumber, so that the line may be edited.

    Syntax:EDITline numberEDIT.

    Comments:

    line numberis the number of a line existing in the program.

    A period (.) refers to the current line. The following command enters EDIT at the currentline:

    EDIT .

    RENUM Command

    Purpose:

    To renumber program lines.

    Syntax:RENUM[new number],[old number][,incrementR]]

    Comments:

    new numberis 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 defaultis 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:RMDIRpathname

  • 5/21/2018 Chapter 2 Data Types

    7/33

    Comments:

    pathname is a string expression, not exceeding 63 characters, identifying thesubdirectory to be removed from its parent.

    The subdirectory to be deleted must be empty of all files except "." and ".." or a "Pathfile/access error" is given.

    Examples:

    Referring to the sample directory structure illustrated in CHDIR, the following commanddeletes the subdirectory report:

    RMDIR "SALES\JOHN\REPORT"

    RMDIR Command

    Purpose:

    To delete a subdirectory.

    Syntax:RMDIRpathname

    Comments:

    pathname is a string expression, not exceeding 63 characters, identifying thesubdirectory to be removed from its parent.

    The subdirectory to be deleted must be empty of all files except "." and ".." or a "Pathfile/access error" is given.

    Examples:

    Referring to the sample directory structure illustrated in CHDIR, the following commanddeletes the subdirectory report:

    RMDIR "SALES\JOHN\REPORT"

  • 5/21/2018 Chapter 2 Data Types

    8/33

    RMDIR Command

    Purpose:

    To delete a subdirectory.

    Syntax:RMDIRpathname

    Comments:

    pathname is a string expression, not exceeding 63 characters, identifying thesubdirectory to be removed from its parent.

    The subdirectory to be deleted must be empty of all files except "." and ".." or a "Pathfile/access error" is given.

    Examples:

    Referring to the sample directory structure illustrated in CHDIR, the following commanddeletes 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 intomemory 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 tocommand level.

    RUN filename closes all open files and deletes the current memory contents beforeloading the specified file from disk into memory and executing it.

  • 5/21/2018 Chapter 2 Data Types

    9/33

    The r option keeps all data files open.

    If you are using the speaker on the computer, please note that executing the RUNcommand will turn off any sound that is currently running and will reset to MusicForeground. Also, the PEN and STRIG Statements are reset to OFF.

    Examples:RUN "NEWFIL", R

    Runs NEWFIL.BASwithout closing data files.

    SAVE Command

    Purpose:

    To save a program file on diskette.

    Syntax:SAVEfilename,[,a]SAVEfilename,[,p]

    Comments:

    filename is a quoted string that follows the normal MS-DOS naming conventions. Iffilenamealready exists, the file will be written over. If the extension is omitted, .baswillbe used.

    The a option saves the file in ASCII format. Otherwise, GW-BASIC saves the file in acompressed binary format. ASCII format takes more space on the diskette, but somediskette access commands (for example, the MERGE command and some MS-DOScommands, such as TYPE) may require an ASCII format file.

    The p option protects the file by saving it in an encoded binary format. When aprotected file is later run or loaded, any attempt to list or edit it fails. When the p optionis used, make an additional copy under another name or diskette to facilitate futureprogram maintenance.

    Examples:

    The following command saves the file com2.bas in the ASCII format:

    SAVE "COM2", A

    The following command saves the fileprog.basin binary format, and protects access:

    SAVE "PROG", P

  • 5/21/2018 Chapter 2 Data Types

    10/33

    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 enteredGW-BASIC through a batch file from MS-DOS, the SYSTEM command returns you tothe 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 linesfrom 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.

  • 5/21/2018 Chapter 2 Data Types

    11/33

    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 rangeoptions for LLIST are the same as for LIST.

    Examples:

    See the examples in theLISTstatement.

    LPRINT and LPRINT

    Purpose:

    To print data at the line printer.

    Syntax:LPRINT[list of expressions][;]

    http://www.antonis.de/qbebooks/gwbasman/LIST.htmlhttp://www.antonis.de/qbebooks/gwbasman/LIST.htmlhttp://www.antonis.de/qbebooks/gwbasman/LIST.htmlhttp://www.antonis.de/qbebooks/gwbasman/LIST.html
  • 5/21/2018 Chapter 2 Data Types

    12/33

    LPRINT USINGstring exp; list of expressions[;]

    Comments:

    list of expressions consists of the string or numeric expression separated bysemicolons.

    string expressions is a string literal or variable consisting of special formattingcharacters. The formatting characters determine the field and the format of printedstrings 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 placeduring 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 useGOTO 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.

  • 5/21/2018 Chapter 2 Data Types

    13/33

    Unlike the STOP statement, END does not cause a "Break in linexxxx" message to beprinted.

    An END statement at the end of a program is optional. GW-BASIC always returns tocommand 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 exceeds1000.

    REM StatementPurpose:

    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 programis listed.

    Once a REM or its abbreviation, an apostrophe ('), is encountered, the program ignoreseverything else until the next line number or program end is encountered.

    REM statements may be branched into from a GOTO or GOSUB statement, andexecution 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.

  • 5/21/2018 Chapter 2 Data Types

    14/33

    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

  • 5/21/2018 Chapter 2 Data Types

    15/33

    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 StatementPurpose:

    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 avariable name.

    The LET statement is seldom used. It is included here to ensure compatibility with previousversions of BASIC that require it.

    When using LET, remember that the type of the variable and the type of the expression mustmatch. If they don't, a "Type mismatch" error occurs.

  • 5/21/2018 Chapter 2 Data Types

    16/33

    Input and Output Statement

    Read and DATA statement

    DATA StatementPurpose:

    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), separatedby commas. No expressions are allowed in the list.

    String constants in DATA statements must be surrounded by double quotation marks only if theycontain commas, colons, or significant leading or trailing spaces. Otherwise, quotation marks arenot 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 anynumber of DATA statements may be used in a program.

    READ StatementPurpose:

    To read values from a DATA statement and assign them to variables.

    Syntax:READlist 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.

  • 5/21/2018 Chapter 2 Data Types

    17/33

    READ statement variables may be numeric or string, and the values read must agree with thevariable 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 inorder. Several READ statements may access the same DATA statement.

    RESTORE StatementPurpose:

    To allow DATA statements to be reread from a specified line.

    Syntax:RESTORE[line number]

    Comments:

    If line numberis specified, the next READ statement accesses the first item in the specifiedDATA statement.

    If line numberis omitted, the next READ statement accesses the first item in the first DATAstatement.

    Input Statement

    INPUT StatementPurpose:

    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 stringis 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 bya semicolon or comma and the name of the variable to which it will be assigned. If more thanone variableis given, data items must be separated by commas.

  • 5/21/2018 Chapter 2 Data Types

    18/33

    PRINT StatementPurpose:

    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 thelist 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. Datab. Programc. Programmingd. Information

    What is a named space in the computers memory whose value can be changed duringthe execution of a program?

    a. Variableb. Constantc. Programd. Data

    In BASIC programming language which character is used as a last character with stringvariable?

    a. ?b. &c. %d. $

    Which shortcut key is used to apply RUN command in GWBASIC?a. F1

  • 5/21/2018 Chapter 2 Data Types

    19/33

    b. F2c. F3d. F4

    5. Which of the following error cannot be detected by a computer?

    a. Syntax errorb. Run time errorc. Logical errord. 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*Ca. 10b. 11

    c. 13d. 16

    9. Which of the following statements is used to accept data from the user duringprogram execution?a. PRINTb. LOADc. READ-DATAd. INPUT

    10. The set of rules that define the combination of symbols used by programming

    languages is called _____________.a. Syntaxb. Datac. Programd. Logic

    11. ____________ languages are the means of communication between usersand the computer.

  • 5/21/2018 Chapter 2 Data Types

    20/33

    a. Operatingb. Programmingc. Printingd.Writing

    All are the following are logical operator except?A NOTB ORC ANDD Neither

    All are the following are logical operator except?A NOTB ORC ANDD Neither

    The result of 10 Mod 3 isA 3B 30C OneD 2

    Which of the following key is used to save a file in GW Basic ?A F2B F1C F3

    D F4

    Question 1All are the following are logical operator except?A NOTB ORC ANDD Neither

    Question 2

    The result of 10 Mod 3 isA 3B 30C OneD 2

    Question 3Which of the following key is used to save a file in GW Basic ?

  • 5/21/2018 Chapter 2 Data Types

    21/33

    A F2B F1C F3D F4

    Question 4A Variable name must start with a(an) ?A AlphabetsB Special characterC DigitD Underscore

    Question 1All are the following are logical operator except?A NOT

    B ORC ANDD Neither

    Question 2The result of 10 Mod 3 is

    A 3B 30C OneD 2

    Question 3Which of the following key is used to save a file in GW Basic ?A F2B F1C F3D F4

    Question 4A Variable name must start with a(an) ?A AlphabetsB Special character

    C DigitD Underscore

    Question 5Which short key is used to save the Document ?

    A Ctrl+SB Ctrl+VC Ctrl+T

  • 5/21/2018 Chapter 2 Data Types

    22/33

    D Ctrl+B

    Question 1All are the following are logical operator except?A NOT

    B ORC ANDD Neither

    Question 2The result of 10 Mod 3 is

    A 3B 30C OneD 2

    Question 3Which of the following key is used to save a file in GW Basic ?A F2B F1C F3D F4

    Question 4A Variable name must start with a(an) ?A AlphabetsB Special character

    C DigitD Underscore

    Question 5Which short key is used to save the Document ?

    A Ctrl+SB Ctrl+VC Ctrl+TD Ctrl+B

    Question 6

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

    Types of array are ?

  • 5/21/2018 Chapter 2 Data Types

    23/33

    A 8B 4C 6D 2

    Which of the following statement command continues the program whose executionwas terminated temporarily?A CONTINUEB CONTC RESTARTD START

    If two or more statement are written on a line, they must by separated by a :A ColonB Semicolon

    C CommaD Hyphen

    GW-BASIC can operate in :A Three modesB One modeC Several modesD Two modes

    When a floating-point value is converted to an integer, the fractional parts :A May be Truncated or Rounded offB TruncatedC Conversion is impossibleD Rounded off

    Which of the following statement temporarily stops the execution of a program?A STOPB ENDC BREAK

    D PAUSE

    A variable name must start with a(n):A UnderscoreB DigitC Alphabet or UnderscoreD Alphabet

  • 5/21/2018 Chapter 2 Data Types

    24/33

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

    C 32D 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 variablesA $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

    programAns. (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 todo

  • 5/21/2018 Chapter 2 Data Types

    25/33

    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 CodeAns. (a)7. 1s and 0s are called:

    (a) Numbers (b) Arithmetics(c) binary number system (d) number systemAns. (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 MachineCode 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) SourceCode

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

    Ans. (c)

  • 5/21/2018 Chapter 2 Data Types

    26/33

    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) anew 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 fileAns. (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) sourcecodeAns. (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)

  • 5/21/2018 Chapter 2 Data Types

    27/33

    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) 355characters.

    Ans. (c)28. In GW-BASIC Variables are the names of:

    (a) characters (b) values (c) constants

    (d) Memory CellsAns. (d)29. Memory Cells which are used to store program's input data and its computationalresults

    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) 80characters

    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 symbolAns. (a)33. The words which cannot be used as Variables are:

    (a) Roman words (b) Urdu words

    (c) English words (d) Key /Reserved words ofBASICAns. (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:

  • 5/21/2018 Chapter 2 Data Types

    28/33

    (a) decimalpoint (b) type of variable (c) number (d) Blankspace

    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 BytesAns. (b)39. The memory required for # double precision variable is:

    (a) 2 Bytes (b) 4 Bytes (c) 6 Bytes (d) 8 BytesAns. (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 StringVariables

    (c) Quotation variables and interogative variables (d) Simeple variables andcomplex variables

    Ans. (b)

    SHORT QUESTIONS

  • 5/21/2018 Chapter 2 Data Types

    29/33

    DEFINE Different Commands

    AUTO CommandPurpose:

    To generate and increment line numbers automatically each time you press the RETURN key.

    Syntax:AUTO[line number][,[increment]]

    AUTO.[,[increment]]

    CONT CommandPurpose:

    To continue program execution after a break.

    Syntax:CONT

    DATA StatementPurpose:

    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), separatedby commas. No expressions are allowed in the list.

    EDIT CommandPurpose:

    To display a specified line, and to position the cursor under the first digit of the line number, sothat the line may be edited.

  • 5/21/2018 Chapter 2 Data Types

    30/33

    Syntax:EDITline number

    EDIT.

    Comments:

    line numberis the number of a line existing in the program.

    Q#1. What are modes of BASIC?

    Ans: GW BASIC operates in two Modes1. Direct Mode2. 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.

  • 5/21/2018 Chapter 2 Data Types

    31/33

    Ans: Reserved words are also called Keywords. They have predefined meanings inBASIC. They can only be used for the purpose for which they are developed. They cantbe 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 isname of the memory location. It is used to store input data or results of computations.

    Rules for variable DeclarationVariable 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 inencoded 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 inputstatement.

    Example:Examples of Input statement are

    READ/DATA Statement INPUT Statement

  • 5/21/2018 Chapter 2 Data Types

    32/33

    Output Statement:

    A statement which is used to display output of the program is calledOutput 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 specificvariable.

    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 StatementsThis 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 areassigned 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 questionmark (?) 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 StatementsThis statement reads values from the DATA statement and assigns them to correspondingvariables. Its Syntax is:

    READ comma-separated list of variablesThe 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 valuesfor these variables from the list of constants specified in DATA statement. The first variable inREAD 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 listof constants in DATA statement, and so on. The variable type (numeric or string) given inREAD statement must agree with the corresponding constant in the DATAstatement

    What is DATA StatementsThis Statement is used to store the numeric and string constants that are accessed by a READstatement specified somewhere in the program.Its Syntax is:

  • 5/21/2018 Chapter 2 Data Types

    33/33

    DATA comma-separated list of constantsIn 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.