Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

VB Numbers and Strings School of Business Eastern Illinois University (Week 4, Monday 2/03/2003) © Abdou Illia, Spring 2003.
List box & Combo box controls School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 14, Monday 4/21/2003)
Chapter seven review Monther Aldwairi. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
Chapter 4 - Visual Basic Schneider
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
Chapter seven review. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For.
User-Defined Data Types School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 13, Monday 11/18/2002)
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
Chapter 7 - Visual Basic Schneider
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will –Learn about arrays One-dimensional arrays Two-dimensional arrays –Learn about searching.
IE 212: Computational Methods for Industrial Engineering
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Database Management School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 16, Monday 12/09/2002)
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
Homework #3: Classes and Constructors
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
Chapter Six: Working With Arrays in Visual Basic.
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
Arrays Chapter 8. Chapter 8 - Part 12 Variable and Variable Array Variable Stores only one value Variable Array Variable that has 1 symbolic name but.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Chapter 71 Repetition - Do Loops n A Loops, is used to repeat a sequence of statements a number of time n There are two loops commands in Visual Basic.
Input and Output. Announcements  Exam Next Wednesday –Next Monday: Review session.  Invited talk: –7:30 PM,Tuesday, Oct 28th. –Prof. Katherine Socha.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Chapter 8 - Visual Basic Schneider
Count and add list of numbers From user input and from file.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
Sequential files School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 12, Monday 4/07/2003)
Repetition Structures
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Chapter 71 Arrays Creating and Accessing Arrays Using Arrays Some Additional Types of Arrays.
Arrays and others. Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call.
VB Objects & Events (Exercises) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Friday 1/31/2003)
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Chapter six exercises
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
Chapter81 For....Next Loops n For i = m To n statement (s) Next i n For statement designates a numeric variable, called control variable. n It is initialized.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
User-Defined Data Types
Chapter 7 Arrays.
Chapter 4 - Visual Basic Schneider
Department Array in Visual Basic
Lbound and Ubound Functions
For...Next Statements.
Presentation transcript:

Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)

Recall from last class

3 Using Array variables in Visual Basic 1.Use Dim statements to declare the array variables Examples: Score (1) 00…..00 Score (2) Score (3)Score (30) …… Dim Student (1 To 30) As String Dim Score (1 To 30) As Integer Default values

4 Using Array variables in Visual Basic 2.Assign values to Subscripted variables: – Using individual Assignment statements. Examples: Score (1) 8792…..00 Score (2) Score (3)Score (30) …… Score (1) = 87 Score (3) = 92

5 Using Array variables in Visual Basic 2.Assign values to Subscripted variables: – Passing by Open and Input statements Dim Student (1 To 30) As String Dim Score (1 To 30) As Integer Ind = 0 Total = 0 Open "A:\Score.txt" For Input As #1 Do While Not EOF(1) Ind = Ind + 1 Input #1, StuName, StuScore Student (Ind) = StuName Score (Ind) = StuScore Total = Total + Score (Ind) Loop : "John", 78 "Lynn", 91 "Okra", 88 "Paul", 77 "Bako", 91 "Kyli",78 "Doll",56 : "King",67 Score.txt

Exercises

7 Determine the values in the computer memory after the execution of this program Private Sub cmdButton_Click() Dim Num (1 To 15) As Integer Num (3) = 10 Num (15) = Triple (Num(3)) End Sub Private Function Triple (x As Integer) As Integer Triple = 3 * x End Function ….. Num (1) Num (2) Num (3)Num (15) ……

8 Determine the output displayed in the picture box when the command button is clicked Private Sub cmdButton_Click() Dim Num (1 To 15) As Integer Num (3) = 10 picOutput.Print Num (3) * Value (Num(3)) picOutput.Print Num (2) + Num(15) End Sub Private Function Value (x As Integer) As Integer Value = 3 * x End Function

9 Visual Basic provides two functions that can be used with arrays: LBound(arrayName) which returns the smallest available subscript of an array and UBound(arrayName) which returns the largest available subscript of an array. Determine what will be displayed on the picture box when the command button cmdDisplay is clicked. Private Sub cmdDisplay_Click() Dim Num(1 To 15) As Integer Num(3) = 10 Num(15) = Triple(Num(3)) picOutput.Print LBound(Num) picOutput.Print UBound(Num) picOutput.Print Num(LBound(Num)) picOutput.Print Num(UBound(Num)) End Sub Private Function Triple(x As Integer) As Integer Triple = 3 * x End Function

10 Suppose that the file Score.txt contains 3 records (see below). Determine the values of the following variables after the program is executed. Private Sub cmdButton_Click() Dim Student (1 To 30) As String Dim Score (1 To 30) As Integer Ind = 0 Total = 0 Open "A:\Score.txt" For Input As #1 Do While Not EOF(1) Ind = Ind + 1 Input #1, StuName, StuScore Student (Ind) = StuName Score (Ind) = StuScore Total = Total + Score (Ind) Loop Average = Total / Ind End Sub Student (3) = Score (2) = Ind = Average = "John", 9 "Nathalie", 10 "Greg", 10 Score.txt

11 Private Sub cmdButton_Click() Dim Student (1 To 30) As String Dim Score (1 To 30) As Integer Ind = 0 Total = 0 Open "A:\Score.txt" For Input As #1 Do While Not EOF(1) Ind = Ind + 1 Input #1, StuName, StuScore Student (Ind) = StuName Score (Ind) = StuScore Total = Total + Score (Ind) Loop Average = Total / Ind End Sub 1)Suppose that the statement picOutput.Print Student(30); "has"; Score(30) appears after Loop, what will be displayed in the picture box: ? 2) Suppose that the following statements appear after Loop For i = 1 To 4 picOutput.Print Student(i); Score(i) Next i What will be displayed in the picture box ? "John", 9 "Nathalie", 10 "Greg", 10 Score.txt

12 Identify the error(s) Private Sub cmdDisplay_Click() Dim planet (1 To 9) As String Call Assign (planet) picOutput.Print planet (1) End Sub Private Sub Assign (planet As String) planet (1) = "Venus" End Sub Answer:

13 Identify the error(s) n Private Sub cmdDisplay_Click() Dim p (1 To 100) As Single Dim i As Integer For i = 1 To 200 p (i) = i / 2 Next i End Sub Answer: n Private Sub cmdDisplay_Click() Dim b (2 To 8 Step 2) As Integer Dim t As Integer Open "Data.txt" For Input As #1 For t = 2 To 8 Step 2 Input #1, b (t) Next t Close #1 End Sub Answer: