Skip to main content

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











Comments

Popular posts from this blog

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

My Profile....

Mr. Shravan Kumar (IT Engineer) " Success is not final; failure is not fatal: It is the courage to continue that counts." It's pleasure to say that IT field is improving day by day and minute by minute. Today, Everything controlled and managed by computer. Businesses and companies use a computer to do marketing and business planning, they use a computer to record customer data, they use a computer to manage goods and services etc. Computer with an internet connection is really important for businesses and individuals. You can understand and analyze the importance of computer by seeing a revolution in offline and online business, online education, online business, online communication and internet banking. To store, access, manipulate, calculate, analyze data and information we use hardware devices and software application. Schools and colleges around the world are using computer and internet technologies to teach students digitally and creatively with...

QBASIC MULTIPLE CHOICE & SUB PROCEDURES CLASS VII

1) ELSEIF- When there are multiple choices and the user has to select one, the ELSEIF statement can be used. Example:- In the above program, program will determine greatest number among three entered number. Remember, while entering numbers , enter three different  numbers. Output:- 2) SELECT CASE:-  SELECT CASE , is used to automatically determine a program decision by checking the value of a variable. Syntax: - SELECT CASE variable CASE comparison value :  execution code : : : CASE ELSE END SELECT Example:- 1 We will make a program to print weekly day, by entering corresponding number.   In the above program, program will print day after entering corresponding day number. Output:-  Example:- 2   Output:-  In the above program we will enter character & program will show you related months staring from the entered character.   LAB ACTIVITY 1. Write Programs for the following problems. ...