Logical Questions                                                     NEXT I                                                                        END  1. Write the output of Following:  a. CLS                                                            Output : ................................................        W$ = \"NEPAL\"                                                  ................................................................      FOR I = LEN(W$) TO 1 STEP -1      	 X$ = X$ + MID$(W$, I, 1)                                    ................................................................      NEXT I      PRINT X$                                                      ................................................................      END                                                                    ...............................................................  Output : .................................................  b. CLS                                                            e. CLS                                                                        W$ = \"NEPAL\"      W$ = \"NEPAL\"                                                      N = 1 : SP = 5      FOR I = 1 TO LEN(W$)                                              FOR I = 1 TO LEN(W$)      X$ = MID$(W$, I, 1) + X$                                          	 PRINT MID$(W$, SP, N)      NEXT I                                                            	 SP = SP - 1      PRINT X$                                                          NEXT I      END                                                               END    Output : .................................................        Output : ................................................  c. CLS                                                                    ................................................................      W$ = \"NEPAL\"      N=1                                                           ................................................................      FOR I = 1 TO LEN(W$)      	 PRINT LEFT$(W$, N)                                          ................................................................      	 N=N+1      NEXT I                                                        ................................................................      END                                                           f. CLS    Output : ................................................             T = 40                                                                        FOR I = 1 TO 5  ................................................................      	 PRINT TAB(T); \"*\"                                                                        	 T=T-1  ................................................................      NEXT I                                                                        END  ................................................................    ...............................................................   Output : ................................................                                                                    ................................................................  d. CLS                                                            ................................................................      W$ = \"NEPAL\"                                                  ................................................................      N=1                                                           ................................................................      SP = 1      FOR I = 1 TO LEN(W$)      PRINT MID$(W$, SP, N)      SP = SP + 1    Smart Computer Science Book-9                                     301
g. CLS                                                                NEXT                                                                        PRINT S  W$ = \"NEPAL\"                                                          END    SP = 1                                                            Output : .................................................    N=1                                                               i. CLS                                                                        N=153  FOR I = 1 TO LEN(W$)                                                  N$ = STR$(N)                                                                        N$ = LTRIM$(N$)  	 X$ = MID$(W$, SP, N)                                                FOR I = 1 TO LEN(N$)                                                                                X$ = MID$(N$, I, 1)  	 R = I MOD 2                                                               X = VAL(X$)                                                                              S=S+X^3  	 IF R = 0 THEN                                                       NEXT                                                                        PRINT S  		        PRINT LCASE$(X$)                                            END    	ELSE                                                             Output : .................................................                                                                    j. CLS  		        PRINT UCASE$(X$)                                                                       D=  	 END IF                                                              WHILE D >= 1    	 SP = SP + 1                                                               R = D MOD 8                                                                              R$ = STR$(R)  NEXT I                                                                      R$ = LTRIM$(R$)                                                                              O$ = R$ + O$  END                                                                         D=D\\8                                                                        WEND  Output : .................................................            PRINT O$                                                                        END  ................................................................                                                                    Output : .................................................  ................................................................                                                                    2. To perform the following:  ................................................................                                                                       a. 	Write a program to ask a word  ...........................................................              and display first character, last                                                                           characters and two characters  h. CLS                                                                   from second position.      N=456      N$ = STR$(N)                                                     b. 	Write a program to ask a word and      N$ = LTRIM$(N$)                                                      display only alternate characters.      FOR I = 1 TO LEN(N$)                                                 [NEPAL as NPL)      X$ = MID$(N$, I, 1) + X$      NEXT                                                             c. 	Write a program to as a word in      PRINT X$      END    Output : .................................................    i. CLS      N=      N$ = STR$(N)      N$ = LTRIM$(N$)      FOR I = 1 TO LEN(N$)      X$ = MID$(N$, I, 1)      X = VAL(X$)      S=S+X            302 Library Functions
small letter and print in alternate      q. 	Write a program to ask a sentence      letters in capital letters.[Hint: nepal      and display each word in different      as NePaL)                                    lines.    d. 	Write a program to ask a your name       r. 	 Write a program to ask a word and      and find out total vowel letter.             print second last charter.    e. 	Write a program to ask your name         s. Write a program to ask a number      and find out how many times 'e' or           and find out it is armstrong number      'E' is repeated.                             or not. If the sum of the cube of                                                   each digit equal to given number  f. 	 Write a program to ask a word and           that is known as Armstrong      display in reverse order.                    number. Eg. 153=13+53+33, This                                                   153 is Armstrong number.  g. 	Write a program to ask a word and      find out total number of characters.     t. 	 Write a program to display all ASCII                                                   code value 0 to 255 along with their  h. 	Write a program to ask a number              character.      and find out total vowels.                                               u. 	Write a program to ask a sentence  i. 	 Write a program to ask a word and           and find out total capital letters,      display only consonants.                     small letters, digits and special                                                   characters.  j. 	Write a program to ask a your      name and find out total vowels and       Range of Asci code Character      consonants.                                               65 to 90      A to Z  k. Write a program to ask a number      and find the sum of digits.              97 to 122     a to z    l. 	 Write a program to as a word and        48 to 57      numbers 0 to 9      display in reverse order.                                               Accept these  Special characters  m. Write a program to ask a word and      find out it is palindrome or not. If     v. Write a program to ask a number      the word can be read same from               and find out it is perfect square      both sides that is called palindrome         root number or not. Eg. 4, 9, 16      word.                                        are example of perfect square root                                                   number.  n. Write a program to ask a number      and find out it is palindrome            w. Write a program to ask a number      numbers or not.                              and find out it is positive, negative                                                   or neutral.  o. Write a program to ask a number      and find out total odd and even          x. Write a program to ask a number      digits.                                      and find out it can read same from                                                   both side or not.  p. Write a program to as a word and      find out repetition of first character.    Smart Computer Science Book-9                                      303
Application Based Questions                        e.	 Why is D=D+X*2^P expression written?    Study the following programs and                   f.	 Why is integer division using?  answer the given questions:                        g.	 Why is B$ added in the last of expression?  1. CLS                                                     3. CLS     D=20                                               INPUT \"Enter Binary No:\";B$     WHILE D >= 1                                       FOR I = LEN(B$) TO 1 STEP -1                                                               X$ = MID$(B$, I, 1)            R = D MOD 2                                        X = VAL(X$)            B$ = STR$(R) + B$                                  D=D+X*2^P            D=D\\2                                              P=P+1     WEND                                               NEXT     PRINT B$                                           PRINT D                                                        WHILE D >= 1     END                                                       R = D MOD 8                                                               R$ = STR$(R)  a. 	 Write the output of this program.                       R$ = LTRIM$(R$)                                                               O$ = R$ + O$  b. 	Why is WHILE-WEND using? Can you use                     D=D\\8      FOR-NEXT loop or not? Give reason.                WEND                                                        PRINT B$  c.	 What is the function of MOD? Why is it            PRINT O$      necessary in this program?                        END    d.	 What is the function of STR$()? Why is it      a. 	 Write the output of this program.      necessary in this program?                                                     b.	 What is the function of VAL()? Why is it used in  e.	 Why is B$ combined in the last of expression?      this program? Give reason.    2. CLS                                             c.	 Why is value of D divided by 8?     INPUT \"Enter a Binary No:\"; B     B$=STR$(B)                                      d.	 Why is value of R changing into string?     B$=LTRIM$(B$)     FOR I = LEN(B$) TO 1 STEP -1                    e.	 Why is RTRIM$() necessary in this program?            X$ = MID$(B$, I, 1)            X = VAL(X$)                              f.	Why is written O$=R$+O$? Why not            D=D+X*2^P                                    O$=O$+R$?            P=P+1     NEXT     PRINT B     PRINT D     END    a. Write the output of this program.    b.	 Why is STR$() using?    c.	 Why is VAL() using?    d.	 Why is the value of C increased by 1?    304 Library Functions
Array in QBASIC                                                              CHAPTER                                                                                  15          Chapter Includes  •	 Introduction of Array    •	 Types of Array: i) Single dimension array and ii) Double dimension array    •	 Sorting data    •	 Searching data    INTRODUCTION    Array is a variable which collects similar type of data. You can use two different  types of variable in QBASIC, in the basis of nature of data storage; they are:    	 i) simple variable 	 ii) array variable.    Simple variable stores only one data at a time, such as N=20; N$= “Ramu”; etc.  N and N$ are simple variable.    Array variable allows you a convenient way to store group of similar type of data  under a single variable name which is called array. Consider a case in which  name of hundred students are to be stored, it would not be feasible for you to  define hundred variables with each name. In such a case, you can use an array  variable to store hundred students name as a group.    WHAT IS AN ARRAY?    An array is a collection of similar type of data, all the data are referred by a single  variable with the unique subscript name. A subscript is a constant value or variable  written within a parenthesis (). For example N(5) where, N is an array variable  name and 5 is a subscript. N(5) creates the following array subscript in the  memory:                 N = N(0) N(1) N(2) N(3) N(4) N(5)    Here, whole memory space is denoted by 'N' that creates six subscripts memory  location due to DIM () statement which are denoted by N(0) to N(5). by default the  lower bound starts from 0 subscription. QBASIC supports 0 or 1 for lower bound  subscription. If you want to set the lower bound by 1, you can use OPTION BASE  1 statement.    OPTION BASE statement  Function	:	 Its function is to set the lower bound subscript value for an array variable.    Smart Computer Science Book-9                                                305
Syntax	:	 OPTION BASE n  Where, n is numerical value 0 or 1.    Example	:	 OPTION BASE 1    •	 Note: This statement is placed before the delactation of array, otherwise QBASIC       displays the error message.    Advantages of Array  a.	 Multiple same data can be stored in a single variable, so program code is also       reduced.    b.	 Once data is entered using array variable that can be used repeatedly. So, it is     more efficient.    c.	 Array makes more convenient to compare and process data in the comparison     of non array variable.    Disadvantages of Array  a.	 An array is a static structure (which means the array is fixed of size). Once       declared the size of the array cannot be modified.    c.	 Insertion and deletion are quite difficult in an array as the elements are stored     in consecutive memory locations.    d.	Allocating more memory than the requirement leads to wastage of memory     space and less allocation of memory also leads to a problem.    Types of Array    Arrays are classified into different types based on the requirement of the program.  The classifications are based on the number of data elements requires. QBASIC  supports two types of array:    	 i)	 Single dimensional Array		  ii) Multi dimensional Array    SINGLE DIMENSIONAL ARRAY    The array which collects series of similar type of data represented by a variable  name having the single subscript is called a single dimensional array. For  example: N(5), where N is a variable and 5 is subscript. The single dimensional  array has single row and multiple columns. The following figure illustrates the  single dimension array:    N = 10          20 30 40 50          N(1)    N(2) N(3) N(4) N(5)    306 Array in QBASIC
DIM statement    Function	:	 The DIM is a declaration statement which declares array variable                   explicitly and allocates the memory space for data of an array.    Syntax	:	 DIM <variable name>(Subscript) [AS type]                 •	 Where, variable is a QBASIC legal variable name.                 •	 Subscript is a dimension of an array which may constant, variable or expres-                     sion. If you are using double or multi-dimensional array, the subscript will be as                     [lower TO] upper [, [lower TO] upper]...                 •	 The default lower value is zero.                 •	 AS type define the data type of an array. It may be string, integer, long integer,                     single precision, double precision.    Example	:	 DIM A(8) AS INTEGER     		 DIM A(0 TO 8) AS INTEGER     		 DIM N(10) AS STRING    		 DIM N(0 TO 10) AS STRING    		 DIM N AS INTEGER    Sample Program                         •	 In this program, N(I) is an array variable     CLS                                   with subscript which stores five different     DIM N(5)                              numbers entered from the keyboard. Af-     FOR I = 1 TO 5                        ter storing, it prints all the values stored            INPUT \"Enter Number:\"; N(I)    in the array. It is possible only in the array     NEXT I                                variable.     REM: Print content of array     CLS     FOR I = 1 TO 5            PRINT N(I)     NEXT I    END    Sample Program     CLS     REM: To display only even numbers from the list of array     CLS     DIM N(10)     FOR I = 1 TO 10            INPUT \"Enter number\"; N(I)     NEXT I         Smart Computer Science Book-9                           307
REM: Start to display only even numbers  CLS  FOR I = 1 TO 10          R = N(I) MOD 2        IF R = 0 THEN PRINT N(I)  NEXT I  END    Sample Program    CLS    DIM A(3), B(3), C(3), D(3)       •	 The above program displays the output  FOR I = 1 TO 3                     in matrix form of data with row wise to-                                     tal. You have to practice with print control        READ A(I), B(I), C(I)        statement and without print control state-        D(I) = A(I) + B(I) + C(I)    NEXT I                                   ment.    FOR I = 1 TO 3         PRINT USING \"######\"; A(I); B(I); C(I); D(I)    NEXT I    DATA 10,20, 30    DATA 40,50,60    DATA 70,80,90    END    SORTING DATA    Sorting refers to arrange the numeric or string data in ascending or descending  order. It is very important in the programming for data searching. The sorted data  gives the clear information instead of unsorted data. There are different types  sorting technique but we will discus bubble sorting.    Bubble Sorting  Bubble sorting is a kind a technique of data sorting. It is a one of the easiest,  quickest and strong sorting technique. In this method, single dimensional array is  used and two adjacent elements are compared and arrange the data in ascending  or descending order.    For example: the following shows the operation of bubble sorting. The first table  is the initial stage. There are five elements, so it takes four rounds of verification  with the two adjacent cells.                       40 30 50 20 10         308 Array in QBASIC
First stage:    The value of first cell 40 is compared with value of second cell of array, if it is  satisfied, value is interchanged. If it is not satisfied, values remain in the same  cell. In this case it is satisfied.                    30 40 50 20 10    Second Stage:    Now, due to first step comparison the data will form as given in the table. Now,    value of second cell is compared with value of third cell. If it is satisfied, value is    interchanged. If it is not satisfied, values remain in the same cell. In this case it is    not satisfied.    Third stage:    30 40 50 20 10    Due to the second stage comparison the data will form as given in the table. Now    value of third cell is compared with value of fourth cell. If it is satisfied, value is    interchanged. If it is not satisfied, values remain in the same cell. In this case it is    satisfied.      30 40 20 50 10    Fourth Stage:    Due to the third stage comparison, the data will form as given in the table. Now    value of fourth cell is compared with value of fifth cell. If it is satisfied, value is    interchanged. If it is not satisfied, values remain in the same cell. In this case it is    satisfied.      40 30 20 10 50    In the second round processing leads three stages because it leaves the last  item. So, second greatest value will be placed in the second last cell and keep so  on until the every round is completed. While every round is completed, values of  array will be arranged in the following manner:                            10 20 30 40 50    Sample Program                             DATA 40, 30, 50, 20, 10  REM: Data storing in the array variable N  REM: Start to perform verification and  CLS                                        interchange with SWAP statement  DIM N(5)                                   FOR I = 1 TO 4  FOR I = 1 TO 5                                                   FOR J = 1 TO 5 - I        READ N(I)                                        IF N(J) > N(J + 1) THEN SWAP  NEXT I                                             N(J), N(J + 1)                    Smart Computer Science Book-9  309
NEXT J                                   CLS  NEXT I                                         DIM N$(10)  REM: Start to display sorted data              FOR I = 1 TO 10  FOR I = 1 TO 5                                                       INPUT \"Enter student Name:\"; N$(I)        PRINT N(I)                               NEXT I  NEXT I                                         FOR I = 1 TO 9  END                                                       FOR J = 1 TO 10 - I  Sample Program                                              IF N$(J) > N$(J + 1) THEN  CLS                                                                SWAP N$(J), N$(J + 1)  REM: Data storing in the array variable N                   END IF  DIM X(5)  FOR I = 1 TO 5                                       NEXT J                                                 REM: Start to display sorted data        READ X(I)                                NEXT I  NEXT I                                         FOR I = 1 TO 10  DATA 40, 30, 50, 20, 10  REM: Start to arrange without SWAP statement.        PRINT N$(I)  FOR I = 1 TO 4                                 NEXT I                                                 END        FOR J = 1 TO 5 - I                       •	 The above program asks and store 10               IF X(J) > X(J + 1) THEN                      TEMP = X(J)                   students name and arranges in alphabet-                      X(J) = X(J + 1)               ic order in the basis of ASCII code value                      X(J + 1) = TEMP               of first character of name of the students.               END IF                                                 b. 	Write a program to ask 5 students        NEXT J                                       roll number and average marks and  NEXT I                                             arranges in ascending order in the  REM: Start to display sorted data                  basis of average marks.  FOR I = 1 TO 5                                                 CLS        PRINT X(I)                               DIM R(5), AV(5)  NEXT I                                         FOR I = 1 TO 5  END                                                       INPUT \"Enter Roll Number:\"; R(I)  Sample Program                                      INPUT \"Enter Average marks:\"; AV(I)  a. Write a program to ask 10 students          NEXT I                                                 FOR I = 1 TO 4      name and store in array subscript                FOR J = 1 TO 5 - I      variable, then display in ascending      order.                                                  IF AV(J) > AV(J + 1) THEN                                                                     SWAP R(J), R(J + 1)                                                                     SWAP AV(J), AV(J + 1)    310 Array in QBASIC
END IF                                               ................................................................        NEXT J                                                      ................................................................  NEXT I                                                            ...............................................................  FOR I = 1 TO 5                                                    2.	 To ask name and average marks        PRINT R(I), AV(I)  NEXT I                                                                 of 15 students, obtained in the final  END                                                                    examination and display in ascending                                                                         order in the basis of average marks  Skill Test                                                             and display name of the students                                                                         and their average mark. The program  After the explanation of single dimension                              also finds out names and display  array and sorting concept, class IX                                    along with their average marks who  students are assigned practical work                                   is getting highest and lowest marks.  to implement of learning concept. They  have to write a program in the following                          Ans:........................................................  matter:                                                           ................................................................  1.	 To ask Average marks of 15 students,                          ................................................................                                                                    ................................................................       obtained in the final examination                            ................................................................       and display in ascending order. The                          ................................................................       program also finds out the highest                           ................................................................       and lowest marks.                                            ................................................................                                                                    ................................................................   Ans:.......................................................      ................................................................  ................................................................  ................................................................  ................................................................  ................................................................  ................................................................  ...............................................................  ................................................................  ................................................................  ................................................................  ...............................................................  ................................................................  ................................................................  ................................................................  ................................................................  ................................................................  ................................................................  ................................................................  ................................................................  ................................................................  ...............................................................  ................................................................  ...............................................................  ................................................................  ................................................................    Smart Computer Science Book-9                                     311
SEARCHING    Searching is a process to seek the particular data or record needed by user.  Single dimension array is used to store data for searching, which makes easy and  convenient to search a record. There are different types of searching technique.  But we will discuss about the sequential search.    Sequential Search    Sequential search is a technique to seek or find the data required by user. In this  method, value of an array is read and compared with the value required by user  and searching starts and proceeds until the given value is found or last items of  an array and gives the appropriate message.    Sample Programs    1. Write a program to read 10 different numbers and search your lucky number is in    the list or not.    CLS                                     •	 In this program, R(10) array variables  DIM R(10)                                 stores 10 different numbers and allows  FOR I = 1 TO 10                           you to enter your lucky number. The en-                                            tered lucky number is compared with all       READ R(I)                          the values in the array. If the number is    NEXT I                                  match, it displays ‘Your lucky number is  DATA 10,20,45,8,5,4,3,2,90,25           found’. If the number is not match, it dis-  INPUT \"Enter your lucky number:\", L     plays ‘Your lucky number is not found’.  REM :Start to search your lucky number  FlaG is a variable that returns 0 or 1.    FlaG = 0    FOR I = 1 TO 10         IF L = R(I) THEN              PRINT \"Your lucky number is found\"              FlaG = 1         END IF    NEXT I    IF FlaG = 0 THEN         PRINT \"Your lucky number is not found.\"    END IF    END    2. Write a program to read 10 different names of the people and search your name     is in the list or not.    CLS              312 Array in QBASIC
DIM N$(10)                                   and search your roll number is in the  FOR I = 1 TO 10                              list or not.          READ N$(I)                          Ans:.......................................................  NEXT I                                       ..........................................................  DATA RAM, HARI, KAMAL, GOPAL,                ..........................................................  BIDHAN, PRANJAN, NIRAJ, SUSHMA,              ..........................................................  NISHA, ANUPAM                                ..........................................................  INPUT \"Enter your Name:\", X$                 ..........................................................  X$ = UCASE$(X$)                              ..........................................................  FOR I = 1 TO 10                              ..........................................................  IF x$ = N$(I) THEN                           ..........................................................                                               ..........................................................        PRINT \"Your name is in the list\"       ..........................................................        GOTO abc                               ..........................................................  END IF                                       ..........................................................  NEXT I                                       ..........................................................  PRINT \"Your name is not in the list\"         ..........................................................  abc:                                         ..........................................................  END                                          ..........................................................                                               ..........................................................  Skill Test    1. 	 Write a program to ask and store 10       numbers in single dimension array    DOUBLE DIMENSIONAL ARRAY    The array which consist of row and columns is called double dimension array.  It allows you to store data in both row and column. The double dimension array  stores similar type of data by a variable name with two subscripts. First subscript  represents number of rows and second subscript represents number of columns.  The intersection of row and column is called cell. The double dimensional array is  more convenient to process the data in matrix form. The following table is trying  to illustrate the double dimensional array.                                            N(1,1) N(1,2) N(1,2)                                            N(2,1) N(2,2) N(2,3)                                            N(3,1) N(3,2) N(3,3)    In the above table, there are 3 rows and three columns where 3*3 =9 similar types    Smart Computer Science Book-9             313
of data can be stored in this dimension under a name N.    Syntax	:	 DIM <variable> (subscript, subscript)               •	 Where, variable is a array variable. Subscript is numeric constant or numeric                    variable which reserve the space to store data. First subscripts represent number                    of rows and second one represents number of columns. Subscripts in DIM                    statements have the following form:    Example:	 DIM A(8,3)                 •	 This example creates 8*3 dimensional array where you can store 24 similar types                    of data. You can store 8 data in each row and 3 data in each column.    Points to use of double dimensional Array  a.	 All elements of array should be similar type, either string or numeric.    b.	 It is not possible to mix numeric and string type of data in an array.    c.	 It is possible to mix single dimension and double dimension in the same DIM     statement.    Sample Programs       •	 In this program, it creates 3*3 double dimension array and  CLS                     stores 9 different values and prints the contents of array in  DIM N(3, 3)             matrix form. The nine different data are stored in 9 different                          cell of the array, which are given below:    FOR I = 1 TO 3                             Cell name of array  Data assigns in the cell        FOR J = 1 TO 3                             N(1,1)                    10               READ N(I, J)                        N(1,2)                    20        NEXT J                                     N(1,3)                    30                                                   N(2,1)                    40  NEXT I                                           N(2,2)                    50  DATA 10, 20, 30                                  N(2,3)                    60  DATA 40, 50, 60                                  N(3,1)                    70  DATA 70, 80, 90                                  N(3,2)                    80  REM: Start to display content of an array        N(3,3)                    90  FOR I = 1 TO 3    FOR J = 1 TO 3                                    OUTPUT       30        PRINT N(I, J);                       10 20    NEXT J          PRINT                                40 50 60  NEXT I                                     70 80 90  END    314 Array in QBASIC
Sample Program    CLS    'REM: Read the unit consumed of electricity of first three months of 10 consumers    DIM U(10, 3)               •	 In the above program, N(10,3) is a double dimension array  FOR I = 1 TO 10              having 10 rows and 3 columns. It reads 30 values, 10 values                               in each row and 3 values in each column and gives the out-        FOR J = 1 TO 3         put which represents unit consumed by 10 customers. The               READ U(I, J)    output of the program is given below:          NEXT J    NEXT I                                                       OUTPUT                     Ashad  DATA 40,50,60,80,90,70,50,40,30,20,67,70,89,90,78  Baishakh Jestha                      60  DATA 89,89,76,75,74,73,72,97,96,95,94,94,95,93,82  40 50                                70  REM: Start to print the content of array           80 90                                30  PRINT \"Baishakh\", \"Jesth\", \"Ashad\"                 50 40                                70  FOR I = 1 TO 10                                    20 67                                45                                                     89 90                                76        FOR J = 1 TO 3                               89 89               PRINT U(I, J),         NEXT J                                        75 74 73         PRINT                                         72 97 96    NEXT I                                             95 94 94  END                                                95 93 82    Sample Programs    CLS    REM: To read and print the name of customer and their units consumed of first three months    DIM U(10, 3)               •	 In the above program, N$(10) is a single dimension array  DIM N$(10)                   where 10 customers name is assigned. U(10,3) is double  FOR I = 1 TO 10              dimension array where unit consumed by 10 customers in                               first three months are assigned. The program stores name        READ N$(I)             of the customer and unit consumed in respective variable        FOR J = 1 TO 3         and print the content of both arrays. The out put of the pro-                               gram is given below:               READ U(I, J)        NEXT J    NEXT I    DATA	 Anil,40,50,60,Rahul,80,90,70    DATA Manish,50,40,30,Kriti,20,67,70    DATA Sumi,89,90,45 Manarama,89,89,76                 Smart Computer Science Book-9                                         315
DATA Rohit,75,74,73,Tara,72,97,96                   OUTPUT  DATA Mohit, 95,94,94,Ritu,95,93,82  REM: Start to print the content of array     Name   Baishakh Jestha  Ashad  PRINT \"Name\", \"Baishakh\", \"Jestha\", \"Ashad\"                          60  PRINT                                        Anil 40 50              70  FOR I = 1 TO 10                                                      30                                               Rahul  80      90       70        PRINT N$(I),                                                   45        FOR J = 1 TO 3                         Manish 50      40       76                                                                       73               PRINT U(I, J),                  Kriti 20 67             96        NEXT J                                                         94        PRINT                                  Sumi 89        90       82  NEXT I  END                                          Manarama 89    89                                                 Rohit 75       74                                                 Tara 72        97                                                 Mohit  95      94                                                 Ritu 95 93    Sample Program                             •	 In this program, it reads the 9 values in double  'Calculation in double dimension array       dimension array and calculate total of each                                               row. Finally, it displays the result along with  CLS                                          total in right alignment of values.  DIM N(3, 4)  FOR I = 1 TO 3                                                      OUTPUT                                                         10 20 30 60        FOR J = 1 TO 3                                   40 50 60 150               READ N(I, J)               N(I, 4) = N(I, 4) + N(I, J)          NEXT J  NEXT I  DATA 10, 20, 30  DATA 40, 50, 60  DATA 70, 80, 90    REM: Start to display content of an array    70 80 90 240    FOR I = 1 TO 3         FOR J = 1 TO 4            PRINT USING \"########\"; N(I, J);         NEXT J         PRINT    NEXT I    END            316 Array in QBASIC
Skill Test                                                       Ans:........................................................                                                                        ..........................................................  1. 	 Write a program to read the following                            ..........................................................       data and perform the column wise                                 ..........................................................       total.                                                           ..........................................................      10 20 30 40                                                       ..........................................................                                                                        ..........................................................      50 60 70 80                                                       ..........................................................                                                                        ..........................................................      90 75 55 45                                                       ..........................................................                                                                        ..........................................................      ????                                                              ..........................................................                                                                        ..........................................................  Ans:........................................................          ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       .........................................................       ..........................................................       .........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................       ..........................................................    2. 	 Write a program to read the following       data and perform the sum of row and       column.    10 20 30  ?  50 60 70  ?  90 75 55  ?  ???       ?    Smart Computer Science Book-9                                    317
Points to Know    •	 An array is a collection of similar type of data, all the data are referred by single variable     with the unique subscript name.    •	 A subscript is a constant value or variable written within a parenthesis ().  •	 QBASIC supports 0 or 1 for lower bound subscription.  •	 The array which collects series of similar type of data represented by a variable name       having the single subscript is called single dimensional array.  •	 Sorting refers to arrange the numeric or string data in ascending or descending order.  •	 In this method, single dimension array is used and two adjacent elements are com-       pared and arrange the data in ascending or descending order.    •	 Searching is a process to seek the particular data or record needed by user.    •	 The array which is consisted by row and columns is called double dimension array. It     allows you to store data in both row and column.    Terms to Know    Variable	 : 	  Reference or name to any data for the computer memory. 	  Constant	: 	   Data item whose values do not change during the execution of pro-                 gram.  String	: 	     A data type used in programming to represent text rather than num-                 bers.	  Precision	: 	  Refers to the closeness of two or more measurements to each other.  Integer	: 	    Number which may negative or positive whole number.    Worksheet    1 . Fill in the Blanks:      a. ...................... is a variable which collects similar type of data.      b. Subscript is written within ..............................      c. QBASIC supports ............... and ................. for lower bound subscription.      d. 	 .......................... statement is used to set the lower bound subscript value for           an array variable.      e. ..................... statement is used to declare the array.    318 Array in QBASIC
f.	......................... refers to arrange the numeric or string data in ascending or           descending order.        g. 	 ....................... is a process to seek the particular data or record needed by           user.    2. 	State whether the following statements are true or false:           a. 	Simple variable stores only one data at a time.             b. 	A subscript is always constant value.             c. 	By default the lower bound starts from 0 subscription.             d. 	Multiple different type of data can be stored in an array variable.             e. 	Once data is entered using array variable that can be repeated.             f. 	 Once declared the size of the array can not be modified.             g. 	TAB() is a device input/output function.    Descriptive Questions    1. Answer the following questions in depth:     a. What is single dimension array?     b. Write the advantages and disadvantages.     c. What is an array?     d. What is sorting?     e. Differentiate between single dimension and double dimension array?    Logic Based Questions    1. Answer the following questions logically:     a. Why do you use OPTION BASE statement?     b. Why do you use array in the programming?     c. Why do you use searching technique?     d. Why do you sort data?    Smart Computer Science Book-9  319
2. Write the output :                                                      NEXT J                                                                      NEXT I  a. CLS                                                              FOR I = 1 TO 5      DIM N(5)      FOR I = 1 TO 5                                                         PRINT X(I)            READ N(I)                                                 NEXT I      NEXT I                                                          END      DATA 50, 30, 50, 20, 10      FOR I = 1 TO 4                                                 Output ...............................................        FOR J = 1 TO 5 - I           IF N(J) < N(J + 1) THEN                                   .............................................................      		 SWAP N(J), N(J + 1)      	 END IF                                                     c. CLS         NEXT J                                                       DIM N(3, 3)      NEXT I                                                          FOR I = 1 TO 3      FOR I = 1 TO 5                                                  FOR J = 1 TO 3            PRINT N(I);                                                      READ N(I, J)      NEXT I                                                          NEXT      END                                                             NEXT                                                                      DATA 10, 20, 30  Output .................................................            DATA 40,50,60                                                                      DATA 70, 80, 90  ...............................................................     FOR I = 1 TO 3                                                                      FOR J = 1 TO 3  b. CLS                                                                     IF I = J THEN S = S + N(I, J)      DIM X(5)                                                        NEXT      FOR I = 1 TO 5                                                  NEXT            READ X(I)                                                 FOR I = 1 TO 3      NEXT I                                                          FOR J = 1 TO 3      DATA 10, 30, 50, 30, 20                                         	 PRINT N(I, J);      FOR I = 1 TO 4                                                  NEXT J         FOR J = 1 TO 5 - I                                           PRINT             IF X(J) < X(J + 1) THEN                                  NEXT                TEMP = X(J)                                           PRINT S                 X(J) = X(J + 1)                                      END                  X(J + 1) = TEMP              END IF                                                 Output ...............................................                                                                       .............................................................    320 Array in QBASIC
3. 	Write a program to read the following data in the single dimension arrays      and display complete table.    NAME		ENG		NEP 		COM		TOT    Radha		     50		  60		  70		               x    Rukmini		80		70		90		x    Hema		      80		  75		  40		               x    Kaman		90		89		98		x    Helen		89		90		92		x    4. Write a program to store any 10 numbers in an array N(10) and search      your 10 friend's roll number is in the list or not.    5. Write a program to store any 10 numbers in an array and find out greatest      and smallest number.    6.	 Write a program to store ‘n’ numbers and display in descending order.    7.	 Write a program to store 10 students name in single dimension subscript      array N$(10) and display in alphabetical order Z to A.    8.	 Write a program to store 10 words in single dimension subscript array      W$(10) and print longest and shortest word.    9.	 Write a program store 10 students name and their average marks in single      dimension arrays and display in descending order name and marks in the      basis of average marks.    10. Write a program to read the following data in single dimension arrays and      display complete table as given heading.    	 ITEM		QTY		RATE		TOTAL    	 PEN		     50		  40		  x    	 COPY		    60		  45		  x    	 ERASER		  80		  10		  x    	 G. BOX		  20		  25		  x    11. Write a program to read the following data and display complete table.    	NAME		AVG.		Grade.    Rahul		62		x    Janak		70		x    Mohan		     35		  x    Pranu		     45		  x    Bidhu		     56		  x    Arpit		     58		  x                Smart Computer Science Book-9     321
The grade is calculated in the basis of following conditions:    Average		 Division    <40 			  \"D\"    <50			   \"C\"    <60			   \"B\"    >=60			  \"A\"    12. 	 Write a program to read the following two matrixes in double dimension        arrays and find the sum of both matrixes.    	 10	 20	 30 				 40	 50	 60    	 40	 50	 60        	 70	 80	90	    	 70	 80	90         	 10	 20	 30    13.	 Read the following matrix in double dimension subscript array and find        the sum of right diagonal.    	 10	 20	 30    	 40	 50	 60    	 70	 80	90    14.	 Read the following matrix in double dimension subscript array and dis-        play the matrix with row-wise and column- wise total.    	 10	 20	 30	    	 40	 50	 60	    	 70	 80	90		    15.	 Read the following matrix in double dimension subscript array and dis-        play the matrix with column wise and row wise total.    	 10	 20	 30	    	 40	 50	 60	    	 70	 80	90	    16.	 Write a program to store numbers in ‘n’ by ‘n’ double dimension sub-        script array and display in row wise and column wise total.    322 Array in QBASIC
                                
                                
                                Search
                            
                            Read the Text Version
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
 
                    