Understanding Arrays in QBasic Programming

acc 106 qbasic lecture note on array n.w
1 / 13
Embed
Share

Learn about arrays in QBasic programming, including definitions, divisions, declarations, and demonstrations. Explore examples of numeric and string arrays, linear arrays, multidimensional arrays, and how to declare and use arrays in QBasic programs.

  • QBasic programming
  • Arrays
  • Declarations
  • Examples
  • Tutorials

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. ACC 106 (QBasic) Lecture Note on: ARRAY AJAYI, Olusola Olajide Department of Computer Science, Faculty of Science, Adekunle Ajasin University, Akungba-Akoko, Ondo State, Nigeria. olusola.ajayi@aaua.edu.ng / ajayiprogrammer@gmail.com 08113699553 / 07056433798 / 08137044500

  2. ARRAY DEFINITION DIVISIONS DECLARATIONS DEMONSTRATIONS

  3. DEFINITIONS An array is a collection of data element, captured name (storage location name) and having the same data type. with the same The nature of data stored in an array depicts the type of array been created (i.e. numeric array, string array etc.)

  4. PICTORIAL REPRESENTATION 34 56 87 90 43 21 11 NUMERIC / INTEGER ARRAY 365.1 77.0 76.89 43.22 76.54 90.9 44.55 ADE YEMI SOLA WALE PETER SEGUN GBENGA STRING ARRAY

  5. DIVISIONS We have two divisions of array: One Dimensional Array OR Linear Array Multidimensional Array OR Matrix

  6. LINEAR ARRAY An array that consist of a one- columnar set of data. 34 56 87 90 43 21 11

  7. FORMAT To declare a linear array, we have DIM array_name(size of the array) as INTEGER e.g. DIM A(10) as INTEGER

  8. Illustration: A Program to Capture 10 elements into an integer array, named A 5 CLS 10 REM 15 DIM A(10) AS INTEGER 20 FOR I = 1 TO 10 25 PRINT Enter element ; I; of the array: ; 30 INPUT A(I) 35 NEXT I 40 END

  9. Illustration II: Consider a company with the sales data for the year given as shown below (data in millions): {4, 1, 3, 5, 3, 7, 8, 2, 7, 4, 5, 6} Code in QBasic to (i) capture the sales data (ii) sum up the sales for the year

  10. Solution: 5 CLS 10 REM 15 DIM sales(12) as INTEGER 20 sumsales = 0 25 FOR I = 1 TO 12 30 PRINT Sales ; I; 35 INPUT sales(I) 40 sumsales = sumsales + sales(I) 45 NEXT I 50 Print The total sales is: ; sumsales 55 END

  11. Illustration III: I have two companies with the sales data for the year given as shown below (data in millions): COY A= {4, 1, 3, 5, 3, 7, 8, 2, 7, 4, 5, 6} COY B= {7, 6, 4, 2, 1, 8, 9, 4, 6, 5, 6, 7} Code in QBasic to (i) capture the sales data for each company (ii) sum up the sales for the year for each company (iii) determine which company has the highest sales and report accordingly.

  12. Solution: 5 CLS 10 REM 15 DIM salescoy1(12) as INTEGER 20 DIM salescoy2(12) as INTEGER 25 sumsalescoy1 = 0 30 sumsalescoy2 = 0 35 PRINT Processing for Company 1 40 FOR I = 1 TO 12 45 PRINT Sales ; I; 50 INPUT salescoy1(I) 55 sumsalescoy1 = sumsalescoy1 + salescoy1(I) 60 NEXT I

  13. Solution: 65 PRINT Processing for Company 2 70 FOR I = 1 TO 12 75 PRINT Sales ; I; 80 INPUT salescoy2(I) 85 sumsalescoy2 = sumsalescoy2 + salescoy2(I) 90 NEXT I 95 Print The total sales for COY1 is: ; sumsalescoy1 100 Print The total sales for COY2 is: ; sumsalescoy2 105 If sumsalescoy1>sumsalescoy2 Then PRINT Company1 has the highest sales Else PRINT Company2 has the highest sales 110 END

More Related Content