Thursday, November 22, 2018

QBASIC STATEMENTS CLASS-VI

CONTROL STATEMENT- 
 The Control Statements are used for controlling the Execution of the program. We use control statements by two way
1) Unconditionally &
2) Conditionally


GOTO STATEMENT-

Unconditionally, we use GOTO statement. The Goto Statement is used for transferring the control to the other location for example- if you wants to transfer the control to the other place of the program then we can use the goto statement. When we use goto Statement then we have to supply a name along with a Goto Statement on which Control is transferred. The Name is user choice and Name must be defined with the help of a Colon. When Compiler transfers the Control of program to the Goto statement then statements of Goto block will be Executed and The Name of Goto Statements block is also called as the Label Name.

GOTO statement uses line number or label

Here, We will understand by an example

CLS
1 PRINT " MY NAME IS  AMIT " :GOTO ABC
2 PRINT " I LIVES IN RAEBARELI " : GOTO 4
3 PRINT " MY MOTHER NAME IS SHAILJA " :GOTO 2
ABC:
PRINT "MY FATHER NAME IS RAJESH " :GOTO 3
4 END

In the above program, line 1 will be executed and then goto will call the label ABC which has code MY FATHER NAME IS RAJESH & will call to line number 3 i.e. MY MOTHER NAME IS SHAILJA & then line 2 will be called I LIVES IN RAEBARELI & then line 4 will be executed with END.
In this way, GOTO statement will execute.


Example:-



Output:- 


IF THEN STATEMENT-

IF THEN checks the condition and execute the code if condition becomes true otherwise it move to the next call code. It uses Relational operators to check the conditions.

RELATIONAL OPERATORS
> greater than
>= greater than equal to
< less than
<= less than equal to
= equal to
<> not equal to
Note :- Relational operators always return Boolean values i.e. either ZERO or NON-ZERO. ZERO means false & NON-ZERO means true

Let's how IF statements works

Example:- 

CLS
A=10
IF A>5 THEN
PRINT A ; " IS GREATER"
END IF
END

Output:-

10 IS GREATER

In the above program, we have declared the value to A=10, and then applied condition using IF , IF will check the condition i.e. A > 5, if A will  be greater than 5 then it will print 10 IS GREATER, Otherwise, IF will end and then program will end


IF THEN ELSE-

IF THEN ELSE statement is used to check the condition. 

Example:-




 Output:-


 Here AGE is a variable which store age which you enters and if statement will checks the condition i.e. age is greater than equal to 18 or not ,if you will enter age greater than equal to 18 then it will display YOU ARE ELIGIBLE FOR VOTING and if you will enter less than 18 then it will display  YOU ARE NOT ELIGIBLE FOR VOTING. 


Let's see one more example-
Example:- 
Make a program in which ask the user to type amount which he/she has. If amount is greater than 100 then it will display you can order pizza otherwise it will display you can not buy pizza.


Output:-


IF THEN ELSEIF-

IF THEN ELSEIF is used to when we have to check multiple conditions and user has to select to one then we use IF THEN ELSEIF.

Lets see a brief description of IF THEN ELSEIF with an example.

Here, We will make a program to check greatest values among three values.

Example:-


Output:-




LAB ACTIVITY 
1) Write a program. (PAGE NO. 119)

a) To Accept the name from the user and print it.


CLS
INPUT " ENTER NAME "; N$
PRINT  " MY NAME IS ";N$
END


b) To Accept first name and last name in two separate variables and print that continuously


CLS
INPUT " ENTER YOUR FIRST NAME "; F$
INPUT " ENTER YOUR LAST NAME " ; L$
PRINT " MY NAME IS  "; F$ ; L$
END


c) To Accept two numbers and print their sum.


CLS
INPUT  " ENTER FIRST NUMBER "; NUM
INPUT " ENTER SECOND NUMBER "; NUM2
NUM3= NUM + NUM2
PRINT " THE SUM OF TWO NUMBER IS "; NUM3
END


d) To ask the user to enter three numbers , and calculate the product of them. Print with appropriate message.


 CLS
INPUT " ENTER FIRST NUMBER "; A
INPUT " ENTER SECOND NUMBER "; B
INPUT " ENTER THIRD NUMBER ";C
P= A * B * C
PRINT " THE PRODUCT OF THREE NUMBERS IS "; P
END



e) To ask the user to enter principal, rate and time , and calculate simple interest.



CLS
INPUT " ENTER PRINCIPAL "; P
INPUT " ENTER RATE OF INTEREST P.A "; R
INPUT " ENTER TIME IN YEARS" ; T
SI=P * R* T / 100
PRINT " THE SIMPLE INTEREST OF GIVEN VALUES IS "; SI
END

3) Write a program. (PAGE NO. 120)

a) To Accept the name from user , and print "HELLO" with name , if the name is RAMAN


CLS
INPUT " ENTER NAME " ; N$
IF N$= " RAMAN" THEN
PRINT " HELLO " ; N$
END IF
END


b) To Accept name and nationality of the person and print welcome, if he is INDIAN.


CLS
INPUT " ENTER YOUR NAME " N$
INPUT " ENTER YOUR NATIONALITY " ; A$
IF A$="INDIAN"  THEN
PRINT " WELCOME....." ; N$
END IF
END


c) To Accept two numbers and print the greater one.


CLS
INPUT " ENTER TWO NUMBERS "; A, B
IF A > B THEN 
PRINT A ; "IS GREATER"
ELSEIF B > A THEN 
PRINT B" "IS GREATER"
ELSE 
PRINT " BOTH ARE EQUAL"
END IF 
END


d) To Ask the user to enter any number, and print it is even or odd.


CLS
INPUT " ENTER NUMBER "; A
R= A / 2
IF R =0 THEN
PRINT " IT IS EVEN NUMBER "
ELSE
PRINT "IT IS ODD NUMBER "
END IF 
END


e) To Ask the user to enter two numbers, and divide the greater one with smaller.


CLS
INPUT " ENTER FIRST NUMBER "; A
INPUT " ENTER SECOND NUMBER " ; B
IF A > B THEN
D= A / B
PRINT " THE QUOTIENT IS "; D
ELSEIF B> A THEN
Q= B / A
PRINT " THE QUOTIENT IS "; Q
ELSE
PRINT " THE QUOTIENT IS " ; 1
END IF 
END






 

 
 
























 

Thursday, November 15, 2018

STRING HANDLING IN QBASIC CLASS VII

String in QBASIC is used to store string values.  In previous chapter we have learnt to store and work with numeric values. In this lesson we will learn to manipulate string / alphanumeric values.
As we know that for storing string value in memory, we need to declare the variable as string. For declaring variable as string we use $ sign infront of variable name.
Example n$="Raja" 
Here, we have declared the variable with name n and for declaring it as string we put $ sign with it.
Always remember that string value always enclosed in double quote. As we seen in the example, we have provided the value Raja.

QBASIC ARRAY & GRAPHICS CLASS VIII

ARRAY in QBASIC  is used to store sequential values of same kind.We can use array instead of using number of separate variables. Using different variables to store values will makes our program lengthy and complicated. So, in such cases QBASIC provides us facility to store values of same type.

So, Basically there are two types of array in QBASIC:

1) SINGLE DIMENSIONAL ARRAY
2) DOUBLE / TWO DIMENSIONAL ARRAY 

SINGLE DIMENSIONAL ARRAY

Declaration:-
                       We use DIM keyword to declare array.
Syntax: DIM  (number of items).

Example:- DIM A(10)
The above will open 10 dimensions in memory to store 10 numbers. i.e.
   1              2           3           4           5           6            7           8          9           10










 
Each index store a single value which is called by A(1), A(2), A(3) ......etc


Here we will make program to store value in an array.




In the above program we have declared array with the name , size 5 and we have stored values manually in each index of the array by calling them directly.
The program will display each value stored in an array.
Output:- 

 
 DOUBLE / TWO DIMENSIONAL ARRAY  

The double dimensional array is used to store values in two dimensions i.e. columns and rows. You may think of a double dimension array as a table like structure , 4 rows of 4 elements. 4*4 unique elements' space will be created in the memory.

Declaration-
              Syntax-       DIM (row,column)
              Example-    DIM NUM(3,3)
In the above declaration NUM is the array name with size of 3 rows and 3 columns. It will create 3*3=9 unique elements to store numeric values because it is numeric array.
                                    
 NUM(1,1)
 NUM(1,2)
 NUM(1,3)
 NUM(2,1)
 NUM(2,2)
 NUM(2,3)
 NUM(3,1)
 NUM(3,2)
 NUM(3,3)
 

In the above table we have addressed the each element of an array in detail.
Now, we will observe example to see how it works.

Example-
Write a program to declare an array with dimension 3*3.

CLS
DIM num(3,3)
END

The above program will created 3*3 i.e. 9 locations to store numeric values. Now, we will see how to store values in an double dimensional array.

Example- 



Output:- 



   The above program will  store values only in an array.

Now, we will make program to display values stored in an array using double dimensional array.


 Output:- 





 ACTIVITY 

1. Write the statement for:
      a)  Declaring a numeric array of 10 numbers
Ans- DIM A(10)



     b) To Input numbers into an array named n(15)
Ans-   
                      CLS
                      DIM n(15)
                      FOR a= 1 TO 10

                      INPUT "ENTER NUMBER- " ; n(a)
                      NEXT a
                      END

     c) To Print the number at 6th Location in the array name arr.
Ans- 
                       REM IN THIS PROGRAM ASSUME THAT YOU HAVE ALREADY STORED VALUES IN AN ARRAY n(10)
                       CLS
                       DIM n(10)
                       PRINT n(6)

                       END

     d) To Print the last element of the array name comp.
Ans- 
                           REM IN THIS PROGRAM ASSUME THAT YOU HAVE ALREADY STORED VALUES IN AN ARRAY num(5)
                       CLS
                       DIM num(5)
                       PRINT num(5) 
                       END

     e) Declare an array to store 15 names
Ans- 
                       CLS
                       DIM N$(15)
                       FOR X = 1 TO 15
                       INPUT " ENTER NAME-"; N$(X)
                       NEXT X
                       END
     f) To be updated......................


2) How do we draw a box in QBASIC? Explain

     a) HORIZONTAL LINE



       Output:-     

         
      b) VERTICAL LINE



Output:-      

  
     c) A Box filled with red colour

     
  Output:-     

                   
     d) A Cirlce

 

  Output:-


 LAB  ACTIVITY   
More Programs of Graphics 

DRAW A PENTAGON-

 DRAW A DIAMOND SHAPE-




 Lab Activity
Will be updated soon..............