Quick Revision of QBASIC Commands and Programs
- Categories QBasic
Below are QBasic Commands and questions.
Q 1.What is QBasic?
Ans:
QBasic is a version of BASIC programming language developed by Microsoft Corporation.
Q 2.What is full form of BASIC?
Ans:
Full form of Basic is Beginners All Purpose Symbolic Instruction Code.
Q 3.Why is QBasic so popular?
Ans:
QBasic is popular as
- It is available as freeware and many tutorials, forums are available to learn the language.
- It is easy to understand and write programs using a IDE (Integrated Development Environment)
Q 4.What is LET statement?
Ans:
LET statement is used to initialize variables with values at the start of the program. Data is stored in variables by using LET statement.
e.g. LET A = 12
Q 5.What is READ DATA statement?
Ans:
READ … DATA statement allows us to read many data items in a single statement. The syntax for it is as below
Syntax
Read var1, var2
Read var3…
:
DATA val1, val2, val3
Key Points:
- DATA statement can appear anywhere in the program but before END
- Read statement reads the data in the order in which they are written in DATA statement.
- If DATA values are less than that required by READ, then “Out of DATA” message is displayed.
- If there is a mismatch in data type of variable, it will give an error.
Q 6.What are functions? What are the advantages of using functions?
Ans:
Functions are ready made programs that can be used anywhere in the programs. The advantages of functions are
- It helps to make our work simpler and faster
- It reduces the length of the program
Q 7.What are different types of Standard Library Functions in QBasic?
Ans:
There are three types of functions in QBASIC.
- Mathematical Functions
- String Functions
- Conversion Functions
Q 8.What are various Mathematical Functions?
Ans:
Different Mathematical Functions are.
- ABS(): Returns absolute value of numeric expression
- SYNTAX: ABS(n)
- EXAMPLE: ABS (-5) gives output as 5
- SGN(): Returns -1,1 or 0 to indicate sign of numeric expression.
- SYNTAX: SGN(n)
- EXAMPLE: SGN (-5) gives output as -1
- INT(): Returns the next integer which is less than or equal to given value.
- SYNTAX: INT(n)
- EXAMPLE: INT (-5.3) gives output as -6
- FIX(): Truncates the fractional part to give Integer value.
- SYNTAX: FIX(n)
- EXAMPLE: FIX (5.3) gives output as 5
- CINT(): Rounds off the value to nearest integer.
- SYNTAX: CINT(n)
- EXAMPLE: INT (5.6) gives output as 6
- SQR(): Gives the square root of the number.
- SYNTAX: SQR(n)
- EXAMPLE: SQR (4) gives output as 2
- ABS(): Returns absolute value of numeric expression
Q 9.What are various String Functions?
Ans:
String functions are used for working with Strings. Different String Functions are –
- + Operator: Addition (+) operator can be used to concatenate two strings
- SYNTAX: String1 + String2
- EXAMPLE: “Name ” + “Surname”
- LEN(): Returns the length of string in characters
- SYNTAX: LEN(String)
- EXAMPLE: LEN( “name”) gives output as 4
- RIGHT$(): Returns n characters from the right of the string
- SYNTAX: RIGHT$(String,n)
- EXAMPLE: RIGHT$( “name”, 2) gives output as “me”
- LEFT$(): Returns n characters from the left of the string
- SYNTAX: LEFT$(String,n)
- EXAMPLE: LEFT$( “name”, 2) gives output as “na”
- MID$(): Returns substring, starting from m returns n characters from the beginning of the string
- SYNTAX: MID$(String,m,n)
- EXAMPLE: MID$( “name”, 2,1) gives output as “m”
- LCASE$(), UCASE$(): Converts to lower case and upper case respectively.
- SYNTAX: UCASE$(String), LCASE$(String)
- EXAMPLE: UCASE$( “name”) gives output as “NAME”
- STRING$(): Returns a string formed by repeating a character for a specified number of times
- SYNTAX: STRING$(n,Character)
- EXAMPLE: STRING$( 2,”x”) gives output as xx
- SPACE$(): Returns n number of spaces
- SYNTAX: SPACE$(n)
- EXAMPLE: SPACE$( 5 ) gives output as “ ”
- + Operator: Addition (+) operator can be used to concatenate two strings
Q 10. What are various Conversion Functions?
Ans:
Conversion functions are used to perform conversion operations on variables.
- ASC(): Returns the ASCII code of given character
- SYNTAX: ASC(Character)
- EXAMPLE: ASC(“A”) will return 65
- CHR$(): Returns the character of given ASCII code
- SYNTAX: CHR$(n)
- EXAMPLE: CHR$(65) will return A
- STR$(): Converts numeric value to String
- SYNTAX: STR$(n)
- EXAMPLE: ASC(234) will return string “234”
- VAL(): Converts String into its numeric value
- SYNTAX: VAL(String)
- EXAMPLE: VAL(“23”) will return 23
- ASC(): Returns the ASCII code of given character
Q 11.What is ASCII?
Ans:
ASCII Stands for American Standard Code for Information Interchange. There are 256 ASCII codes from 0 to 255. Codes for common alphabets are as following
- A to Z = 65 to 90
- a to z = 97 to 122
- 0 to 9 = 48 to 57
QBasic Questions
Q 1. Fill in the blanks
- ______________ function returns length of the string
Ans. LEN()
- ______________ function return n number of spaces
Ans. SPACE$()
- ______________ function returns n character from right of the string
Ans. RIGHT$()
- ______________ function converts string to number
Ans. VAL()
- ______________ function returns ASCII code of character
Ans. ASC()
- ______________ function returns a value indicating the sign of number
Ans. SGN()
- ______________ function converts all characters to uppercase
Ans. UCASE$()
- ______________ function truncates the fractional part of the number
Ans. FIX()
- ______________ function returns a substring from any position
Ans. MID$()
- ______________ function rounds off a number to the nearest integer
Ans. CINT()
- ______________ function returns n number of characters from right of the string
Ans. RIGHT$()
- ______________ function returns nearest integer which is less than or equal to value
Ans. INT()
- ______________ function returns character of given ASCII code
Ans. CHR$()
- ______________ function converts numeric value to string
Ans. STR$()
- ______________ operator can concatenate string.
Ans. +
- ______________ statement is used to initialize a variable at the start of the program
Ans. LET
- ______________statement is used to read many data items in single statement
Ans. READ … DATA
- The values stored in DATA statement are separated by ______________.
Ans. comma
- DATA statement must appear before the ______________
Ans. END
- ______________ message is displayed if DATA statement contains less values than what is required by READ statement.
Ans. “Out of DATA”
- _______, _______, _________are three types of standard library functions.
Ans. Mathematical,String, Conversion.
Q 2.What is full form of following
- ASCII
- IDE
- BASIC
Ans:
- American Standard Code for Information Interchange
- Integrated Development Environment
- Beginners All Purpose Symbolic Instruction Code
Q 3.What is the output of following statements
- ABS(-22.8)
- SGN(-22.8)
- INT(22.8)
- INT(-22.8)
- FIX(22.8)
- CINT(22.5)
- CINT(22.6)
- CINT(-22.5)
- CINT(-22.6)
Ans
- 8
- -1
- 22
- -23
- 22
- 22
- 23
Q 4.Identify if it is the right syntax for the command
- LEN$(“ABC”)
- SGN(“1.23”)
- RIGHT(“ABC”,2)
- ASC(“ABC”)
- VAL$(4)
- LEFT$(2,”ABC”)
- STRING(2,”ABC”)
- MID$(2,4,”ABC”)
Ans
- LEN(“ABC”)
- SGN(1.23)
- RIGHT$(“ABC”,2)
- ASC(“ABC”) – Will only return ASCII value of A
- VAL(“4”)
- LEFT$(”ABC”,2)
- STRING(2,”ABC”) – Will replicate A 2 times
- MID$(”ABC”, 2,4)
Q 5.What is the output of following statements
- LEN(“I AM”)
- RIGHT$(“SIMPLY”,10)
- LEFT$(“SIMPLY”,3)
- MID$(“SIMPLY”,2,3)
- UCASE$(“Simply”)
- STRING$(4,“Simply”)
- PRINT “SIMPLY”;SPACE$(4);”CODING”
- PRINT “SIMPLY”, “CODING”
Ans
- 8
- SIMPLY
- SIM
- IMP
- SIMPLY
- SSSS
- SIMPLY CODING
- SIMPLY CODING
Q 6.What is the output of following statements
- ASC(“B”)
- STR$(65)
- VAL(“22.4”)
- CHR$(98)
Ans
- 66
- 65
- 22.4
- b
Programs
Q 1. Write a program to enter your name and print it?
Ans.
CLS Input 'Enter you name';n$ Input " Enter the age";A Print " The age is ";A Print 'The name is';n$ End
Q 2. Write a program to find the area of rectangle.
Ans.
Cls Input " enter the length " ;l Input " enter the breadth " ;b let A = l*b Print" the area of rectangle=" ;a End
Q 3.Write a program to find the area of the triangle.
Ans.
Cls Input " enter the base" ;b Input " enter the height" ;h let T = 1/2*b*h Print" The area of triangle=" ;T End
Q 4.Write a program to find the area of the circle.
Ans.
Cls Input" Enter the radius " ;R Let C=22/7*R^2 Print " The area of circle =" ;C End
Q 5.Write a program to find the circumference of the circle.
Ans.
Cls Input" Enter the radius " ;R Let Circumference=22/7*R*2 Print " The area of circle =" ;Circumference End
Q 6.Write a program to find out the simple Interest.
Ans.
Cls Input " Enter the Principal";P Input " Enter the Rate";R Input " Enter the Time";T Let I = P*T*R/100 Print " The simple Interest = ";I End
Q 7.Write a program to find the average of three different numbers.
Ans.
Cls Input" Enter the number " ;A Input" Enter the number " ;B Input" Enter the number " ;C Let Avg= (A+B+C)/3 Print" The average=" ;Avg End
Q 8.Write a program to enter any number and find out whether it is negative or positive.
Ans.
CLS Input “Enter the number”; N If N>0 Then Print “ The number is positive” Else Print “The number is negative” EndIf End
Q 9.Write a program to enter any number and find out whether it is even or odd using select case statement.
Ans.
Cls Input “Enter any number” ;N R=N mod 2 Select case R Case = 0 Print “The number is Even number” Case Else Print “The number is odd number” End Select End
Q 10. Write a program to check the numbers between 1 & 3.
Ans.
Cls Input “Enter the numbers between 1-3”;N Select case N Case 1 Print “It’s number 1”; Case 2 Print “It’s a number 2”; Case 3 Print “It’s a number 3” Case else Print “It’s out of range”; End select End
Q 11. Write a program to enter any alphabet and test alphabet is ‘a’ or not using the select case statement.
Ans.
Cls Input “Enter the alphabet”;A$ A$=UCase$ (A$) Select Case A$ Case ‘A’ Print “It’s alphabet A” Case Else Print “It’s not alphabet A” End Select End
Q 12. Write a program to enter any alphabet and find out whether the number is vowel or alphabet.
Ans.
Cls Input “Enter Letters/Alphabet”;A$ A$ = UCase $ (A$) Select case A$ Case “A”, “E”, “I”, “O”, “U” Print “Its’ a vowel” Case Else Print “ It’s not a vowel” End Select End
Q 13. Generate the following numbers using For….Next…..Loop. 1,2,3,4,…,50
Ans.
CLS For I = 1 to 50 Step 1 Print I Next I End
Q 14. Generate the following numbers using For….Next…..Loop. – 2,4,6,8,10,…50
Ans.
Cls For I = 2 to 50 Step Print I Next I End