QBASIC Statements
QBASIC Statements
QBASIC statements is group of BASIC keywords generally used in program lines as the part of a program. The statements or instruction should be given according to the rules of the language in which the program is written. The QBASIC statement is first stored in the memory of the computer and executed only when the command RUN is given.
Data Type Definition Statement
A DEF statements declares that any variable name beginning with a certain range of letters is the specific data type. A DEF types of statements must be executed before you use any variable that it declares. if no DEF statements are encountered, single precision is the default for variable. DEF types of statements affect only variables names in the module in which it appears.
DEF types of letters [-letter] [,letter] [-letter] ......................
Types of DEF letter:
INT for integer,
LNG for long integer,
SNG for single precision,
DBL for double precision,
STR for string of 0-255 character.
SOLVED_PROBLEM
# Write a program in QBASIC to Calculate the 5% tax on basic salary.
Solution:
REM "This program calculates the tax of an employee"
DFSTR n
DEFINT c, s
INPUT "Enter the employee's name", N
INPUT "Enter his basic salary", S
T = S*(5/100)
PRINT "The tax is RS."; T
End
REM Statement
Rem statement is used to include explanatory remarks to be inserted in a program, which are very useful to explain what a group of statement achieve and what a variable stan for. An apostrophe (') may be used instead of REM. REM is a non-executable statement and it does not affect the program result in any way. The REM statement help the programmers and others in reading and understanding the programs. This statement can be used anywhere and any number of times in a program. The general format of REM statements is:
REM<remark> or '<remark>
Where, remark may be any expression or statement to define the process.
CLS statement
CLS statement is used to clear the output screen. it makes the screen completely blank. This command is generally given before the start of any program so that there is a fresh screen and any left over from the previous program is cleared completely. The general format of CLS statement is:
CLS
LET statements
LET statements is an assignment statement. It is used to assign the value of an expression to a variable. LET is an optional keyword i.e., the equal to sign is sufficient when assigning an expression to a variable name. the type of the expression (string or numeric) must be the same as the type of variable. otherwise, a "Type mismatch" error will occur. the general format of LET statement is:
LET<variable>=<expression>
Where, variable is the name of a numeric or string variable that receives the value.
expression is a numeric or string expression whose value will be assigned to a variable.
INPUT Statement
The INPUT statement is used to accept input from the keyword during program execution. It facilitates the use of same program for various sets of data to obtain different results in different executions. The data typed by the user must be in the correct order as that of the variable in the INPUT statement. If the various entered is incorrect or insufficient, QBASIC gives the error message "Redo from start". The general format of INPUT statement is:
INPUT["definer,] list of variables
Where, definer is a string constant, enclosed in equation marks, that will be displayed when the statement is executed.
list of variable contains the numeric or string variable that stores the data.
SOLVED_PROBLEM
REM "Program to find the circumference of a circle"
PI = 3.141
INPUT "Enter a radius:"; R
C = 2* PI * R
PRINT "the circumference of a circle is:"; C
END
LINE INPUT Statement
LINE INPUT statement accepts input from the keyword. The advantage of the LINE INPUT statement over the INPUT statement is that the delimiting characters are also read as part of the data. The general format of LINE INPUT statement is:
LINE INPUT ["prompt";] variable
Where, prompt is a string constant that will be displayed when the statement is executed.
variable is the name of string variable or array element to which the line will be assigned.
READ...DATA Statements
READ statement is used to read values from DATA statement is to store the numeric and string constant that are accessed by the program's READ statement (S). The general format of READ...DATA statement is:
READ [variable1, variable2,...]
...
...
DATA [constant1, constant2,...]
SOLVED_PROBLEM
REM "This program finds the profit percent"
CLS
READ S , C
DATA 850,800
PROFIT = S - C
PERCENT = ( PROFIT / C ) * 100
PRINT " The actual profit:"; PROFIT
PRINT " The profit percent:"; PERCENT
END
PRINT Statement
PRINT statement is used to display data on screen. This statement will print constants, variables or expressions. A question mark (?) may be used instead of the word PRINT. The general format of PRINT statement is:
PRINT [list of expression][ , \ ; ] or
?[list of expression][ , \ ; ]
Where, ( , ) separate zone wise.
( ; ) separate side by side
SOLVED_PROBLEM
INPUT " Enter the sales for day 1:"; D1
INPUT " Enter the sales for day 2:"; D2
INPUT " Enter the sales for day 3:"; D3
T = D1 + D2 + D3
PRINT " Total sales:"; T
END
PRINT USING Statement
PRINT USING statement is used to display string or number using specified format. The general format of PRINT USING statement is:
PRINT USING "string"; expression [, \ ; expression]...[ , \ ; ]
Where, string is a string constant or variable that consists of special formatting characters. It determines the field and format of displayed string or number.
expression is the numeric or string expression to be displayed. Multiple expressions must be seprated by commas or semicolon.
SOLVED_PROBLEM
A$ = "Hello"
B$ = "You"
PRINT USING "\\"; A$, B$
END
LPRINT and LPRINT USING Statement
LPRINT and LPRINT USING statement print data on the printer. The statements are very similar to PRINT and PRINT USING statements, except that the output goes to the printer instead of the screen. The general format is:
LPRINT [ expression [ , \ ; expression]...][;]
LPRINT USING "string" ; expression [ , \ ; expression]...[;]
Where, expression is a numeric or string expression to be printed.
string is a string constant or variable that identifies the format in which expression is to be printed.
LPRINT assumes that the printer uses an 80-character have been printed. Consequently, if you print a line that is exactly 80 character long, two lines will be skipped after the line unless you end the LPRINT statement with a semicolon.
END statement
END statement denotes the end of the program. Once the program encounters the END statement, the computer stops processing any further as it has reached the termination point. It must be written as the last statement in every program. The general format of the END statement is:
END

Comments
Post a Comment