Introduction to the Array

Slides:



Advertisements
Similar presentations
Importing and linking through Access Please use speaker notes for additional information!
Advertisements

PHYS 2020 Pseudocode. Real Programmers Program in Pencil!  You can save a lot of time if you approach programming in a methodical way.  1) Write a clear.
Session Objectives# 24 COULD code the solution for an algorithm
Group functions using SQL Additional information in speaker notes!
Relational example using donor, donation and drive tables For additional information see the speaker notes!
PL/SQL - Using IF statements Please use speaker notes for additional information!
Pseudocode.
Pseudocode.
P.6 English Lesson Greetings How do you do, I’m Peter Chan? How do you do, Mr Chan? I’m very pleased to meet you. people meet at the first time.
SQL Use of Functions Character functions Please use speaker notes for additional information!
Two dimensional arrays Please use speaker notes for additional information!
Cursors in PL/SQL Includes cursor example and continuation of first cursor example Please use speaker notes for additional information!
Introduction to Computational Thinking Vicky Chen.
Simple Program Design Third Edition A Step-by-Step Approach
Introduction to Tables/Arrays Please use the speaker notes for additional information. Tables/Arrays.
Computer Science 101 Introduction to Programming.
Functions. Warm Up Solve each equation. 1.2x – 6 = x = X + 29 = x – 5 – 4x = 17 x = 14 x = - 7 x = -15 x = 11.
Array - adding to array at run time Please see speaker notes for additional information!
Using XML with ASP and the ASP:Repeater Please use speaker notes for additional information!
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
XML and DTD Please you speaker notes for additional information!
Examples dealing with cursors and tables Please use speaker notes for additional information!
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
More on views Please refer to speaker notes for additional information!
SQL and Conditions Speaker notes will provide additional information!
Introduction to Access 2010 CIS120first.accdb is the database I am creating.
When I want to work with SQL, I start off as if I am doing a regular query.
Indexes in Oracle An Introduction Please check speaker notes for additional information!
Introduction to ASP.NET Please use speaker notes for additional information!
1 Review for test 2 Chapters 7, 8, 9, 11, What is wrong with the following paragraphs? PARA-A. PARA-B. ADD A TO B MOVE 0 TO X PERFROM PARA-A PERFORM.
Label Assignment Please use speaker notes for additional information!
Programming Assignment #2 in CIS12 Please use speaker notes for additional information!
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
Guide to Assignment 3 and 4 Programming Tasks 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas.
Introduction to PL/SQL As usual, use speaker notes for additional information!
Introduction to Arrays. Objectives Distinguish between a simple variable and a subscripted variable. Input, output, and manipulate values stored in a.
Visual Basic - Break Processing
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Tables In COBOL An Introduction
Output “Funds not available”
1-1 Logic and Syntax A computer program is a solution to a problem.
Department of Computer Science,
Screen I/O ACCEPT DISPLAY Relevant to the Fujitsu Compiler.
Exam 3 Review.
Introduction to Procedures
CMIS 102 Competitive Success-- snaptutorial.com
CMIS 102 Education for Service-- snaptutorial.com
CMIS 102 Teaching Effectively-- snaptutorial.com
Siti Nurbaya Ismail Senior Lecturer
MySQL - Creating donorof database offline
Please use speaker notes for additional information!
Computer Programming.
Access and Condition Statements
One-Dimensional Array Introduction Lesson xx
Department Array in Visual Basic
Programming Right from the Start with Visual Basic .NET 1/e
Introduction to Views and Reports
ARRAYS 1 GCSE COMPUTER SCIENCE.
The Programming Process
Searching an Array or Table
Notes on SQL This slide show will introduce SQL using Access. It assumes only an introductory level of knowledge about Access.
Data Structures and Algorithm: SEARCHING TECHNIQUES
Introduction to Access 2010
More and Still More on Procedures and Functions
Functions and Tables.
Introduction to Relational Database Introducing PRIMARY KEY
Please use speaker notes for additional information!
Print a list of all people in department 15 who either are salaried and make more than or are part time or full time and make more than 25 per hour.
Presentation transcript:

Introduction to the Array Please use speaker notes for additional information! This presentation will introduce some of the concepts of arrays. Note that in COBOL, arrays are sometimes called tables so in the followup slide presentation that gives examples in COBOL, the array is called a table.

deptNo deptName 1 dept 1 is MENS Assume that I have a file that contains a department number along with other data. The layout of the file is: empIdno, empName, deptNo and Salary. Assume also that I have a report where I want to print out the department name. To solve this problem, I am going to use an array. deptNo deptName 1 dept 1 is MENS 2 dept 2 is WOMENS 3 dept 3 is GIRLS 4 dept 4 is BOYS This shows the basic information that I have to work with. It is laying out the problem.

This solution works, but if there were a lot of departments, it would go on forever. An array provides a better solution. Pseudocode: if deptNo = 1 deptName = “MENS” else if deptNo = 2 deptName = “WOMENS” if deptNo = 3 deptName = “GIRLS” if deptNo = 4 deptName = “BOYS” endif One solution is to use IF statements. This works fine when you only have 4 departments, but it would be very code heavy if you had 100 departments.

Second: MENS WOMENS GIRLS BOYS deptName (1) deptName (2) deptName (3) The solution is to use a pointer to point to the different elements as first use of deptName, second use of deptName, third use of deptName and fourth use of deptName. By using the pointer, we make the name unique. The pointer is usually called an index or subscript in programming. MENS WOMENS GIRLS BOYS deptName (1) deptName (2) deptName (3) deptName (4) First: When I establish an array, I set up a table or list of the elements I want in my array and I give each element the same name. In this case, I am calling each one deptName. The problem is that in programming we know that each variable needs a unique name. This presents a problem. Now we know that: deptName(1) = “MENS” deptName(2) = “WOMENS” deptName(3) = “GIRLS” deptName(4) = “BOYS” The pointer is usually called an index or subscript as noted above. Also, in some languages the index/subscript/pointer starts with 1, in other languages it starts with 0 and with other languages you can choose whether you want it to start with 1 or 0.

move deptName (deptNo) to the line To apply this to our problem, the data coming in has the following data: empIdno empName deptNo salary MENS WOMENS GIRLS BOYS deptName (1) deptName (2) deptName (3) deptName (4) Remember our problem is to display or print the department name on our report. If we use deptNo as the pointer we can accomplish this goal: move deptName (deptNo) to the line The syntax for the statement to move things varies from language to language. However, in most languages you have the data in the array followed by the index/pointer in with ( ) or [ ] or { }.

empName deptNo salary 11111Mary Smith 24000000 Before we apply this to our problem, lets look at the data on the file: empIdno empName deptNo salary 11111Mary Smith 24000000 12121Jennifer Ames 34000000 12345Stephen Daniels 44000000 13456Carl Hersey 14000000 14567Linda Anderson 23500000 17890John Alden 14500000 18900Peter Lincoln 44000000 21212Ann Reynolds 33500000 22222Donald Costa 13500000 23456Joyce Raymond 23500000 24567David Jones 13000000 This slide shows the layout of the data file. The first field is empIdno, the second field is empName, the third field is deptNo and the fourth field is salary. Hopefully by color coding the fields, the data stands out.

1 2 3 4 MENS WOMENS GIRLS BOYS ARRAY: deptName 11111Mary Smith 24000000 INPUT 12121Jennifer Ames 34000000 12345Stephen Daniels 44000000 13456Carl Hersey 14000000 14567Linda Anderson 23500000 17890John Alden 14500000 18900Peter Lincoln 44000000 21212Ann Reynolds 33500000 22222Donald Costa 13500000 23456Joyce Raymond 23500000 24567David Jones 13000000 ARRAY: deptName 1 2 3 4 MENS WOMENS GIRLS BOYS PROCESSING: move deptName (deptNum) to deptName-PR. OUTPUT: 11111 Mary Smith WOMENS $40,000.00 12121 Jennifer Ames GIRLS $40,000.00 12345 Stephen Daniels BOYS $40,000.00 13456 Carl Hersey MENS $40,000.00 14567 Linda Anderson WOMENS $35,000.00 17890 John Alden MENS $45,000.00 18900 Peter Lincoln BOYS $40,000.00 21212 Ann Reynolds GIRLS $35,000.00 22222 Donald Costa MENS $35,000.00 23456 Joyce Raymond WOMENS $35,000.00 24567 David Jones MENS $30,000.00 The first input record has department 2. I use that deptNum to go to the array and extract the deptName that deptNum is pointing to. That means WOMENS is extracted and moved to the print line. On the second input record, the department is 3. This takes the third element from the array, GIRLS and moves it to the line. On the third input record, the department is 4. This takes the fourth element from the array, BOYS and moves it to the line. On the fourth input record, the department is 1. This takes the first element from the array, MENS and moves it to the line. See the COBOL table presentation for an example in COBOL.