Last week lecture Loops (lets look at for loop again) Dry Runs

Slides:



Advertisements
Similar presentations
Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
Advertisements

The Area Model of Multiplication Using Base Ten Pieces And Boxes To Build Understanding of Multiplication.
1 Arrays, Strings and Collections [1] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
Operations of Polynomials
Outline lecture Revise arrays Entering into an array
Dry Run You can test your program without using a computer by dry running it on paper You act as the computer – following the instructions of the program,
Learning to show the remainder
SOLVING EQUATIONS AND EXPANDING BRACKETS
GCSE Higher Revision Starters 11 Module 3 and 5 Revision.
Introduction to R Brody Sandel. Topics Approaching your analysis Basic structure of R Basic programming Plotting Spatial data.
1.
Chapter 7: Arrays In this chapter, you will learn about
Recursion.
Network, Local, and Portable Storage Media Computer Literacy for Education Majors.
Your boss asks… How many of these things do we have to sell before we start making money? Use your arrow keys to navigate the slides.
Memory Test. -Write down your age (whole number) -Circle your gender (Male or Female)
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
11 Data Structures Foundations of Computer Science ã Cengage Learning.
Briana B. Morrison Adapted from William Collins
Example 2. The length of a rectangle is 7 more than the width. Its area is 30. Find the dimensions of the rectangle. x x + 7 A = 30 A = lw 30 = x(x + 7)
R for Macroecology Aarhus University, Spring 2011.
= First write the numbers one on top of the other Make sure the tens and units line up ____.
WU # y +1 < 19 5y +2 -y > 8 -7y  -14 4y – 7y -7 < y y + 6  21 y < 2 y  - 3 y > -4 y  2.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
The simple built-in data types of the C language such as int, float, - are not sufficient to represent complex data such as lists, tables, vectors, and.
a*(variable)2 + b*(variable) + c
Microsoft® Small Basic
9-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Week 12: Data Structures 1 Stewart Blakeway FML 213
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
An Introduction to Programming with C++ Fifth Edition
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Processing Arrays Lesson 8 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
11 Finding Winners Using Arrays Session 8.2. Session Overview  Find out how the C# language makes it easy to create an array that contains multiple values.
 Data is always stored in a logical way so that it can be accessed efficiently. Ex:A telephone directory  The way data is stored is called the structure.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Arrays Chapter 13 How to do the following with a one dimensional array: Declare it, use an index.
17 November 2015Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
Counting Loops.
Intermediate 2 Computing Unit 2 - Software Development.
Processing Arrays Lesson 9 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Introduction to programming in java Lecture 23 Two dimensional (2D) Arrays – Part 3.
Selection Using IF THEN ELSE CASE Introducing Loops.
CIS 115 All Exercises Devry University (Devry) FOR MORE CLASSES VISIT CIS 115 All Exercises Devry University.
Outline lecture Revise arrays Entering into an array
EGR 2261 Unit 10 Two-dimensional Arrays
Chapter 5: Control Structure
ALGORITHMS & FLOWCHARTING II
Arrays & Functions Lesson xx
Control Structure Senior Lecturer
Data Structures & Algorithms
Presentation transcript:

Last week lecture Loops (lets look at for loop again) Dry Runs Nested layouts - if then else statements, loops More complex loops Test plans

This week lecture - Arrays Data is stored in a computer in a logical way so that it can be found as quickly as possible Consider a telephone directory – how is data stored The way data is stored is called the structure of the data, hence the term data structures You have come across one data structure – which one ? Another type of data structure is an array Often we solve problems in everyday life by using tables Can you think of when you may want to use a table to organise you data?

What is an Array We are interested in one-dimensional arrays An array has a fixed number of elements and all elements are of the same type Each box has an index which in java and C++ starts with 0 Here is an array which holds the ages of 10 people 0 1 2 3 4 5 6 7 8 9 32 34 56 32 12 67 21 34 21 45

Lets look at this array in detail What do you notice about the array ? 0 1 2 3 4 5 6 7 8 9 32 34 56 32 12 67 21 34 21 45 Lets look at this array in detail What do you notice about the array ? Is the data organised in any particular way?

Examples of Arrays Draw an array of 20 elements which contains student marks – what type will it be ? Draw an array of 15 elements which contains student grades ranging form A-E – what type will it be?

Entering data into an array When you enter data into an array we use a loop What type of loop do you think we will use? Hint – we know the number of elements there are in the array Use a counter to keep track of how many elements are entered into the array

Entering data into an array Read Algorithm Loop : R = 1 to 10 Enter A( R) Loop end The number of elements in array is 10 The counter of loop (R ) allows the computer to increase the element number by 1 each time a piece of data is entered into a memory location The computer can find a particular element in the array by using the reference number index represented by R R = loop counter A(R ) = element R in the A array R 10 1 Enter A(R ) R B

Accumulating the elements of array Calc You may need to sum the elements of an array Initialise the sum variable which contains the total to zero The instruction Sum = Sum + A(R ) tells the computer to add the valve of element A(R ) to the old valve of the sum (Sum) and to store the result into sum memory location (Sum) Algorithm Loop : R = 1 to 10 sum = Sum + A( R) Loop end The number of elements in array is 10 The counter of loop (R ) allows the computer to increase the element number by 1 each time a piece of data is entered into a memory location Sum = Sum of the elements of A A(R ) = element R in the A array R 5 1 Sum = Sum + A(R ) R B

Dry run Dry run the previous array algorithm using the following data (remember sum was 0 initially) Loop counter Array valves sum 1 2 4 6 8 10

Dry run Dry run the previous array algorithm using the following data (remember sum was 0 initially) Loop counter Array valves sum 1 2 4 6 3 12 8 20 5 10 30

Question Trendyclothes is a corporation that sells clothes and has 10 stores. Write an algorithm and flowchart to read the sales figures for all 10 stores for Trendyclothes into an array Do a dry run for entering the sales data Dry run should only include 2 columns, one for array index element and second for sales figures for each store Sales figures :- 200 ,300,150,40,25,233,256,123,562, 128 c) Write an algorithm and flowchart to print the array element and the sales figures of the array (remember to print the headings) (for those who want something more challenging – in the lab session - print the sales figures as a percentage of total sales of the corporation also Hint – you will need to sum the sales first and then work out the sales percentage for each store)

Answer Entering the Sales valves into an array b) answer Loop counter Sales 1 200 2 300 3 150 4 400 5 275 6 125 7 175 8 450 9 475 10 350 Read Algorithm Read (*Sales) Loop : R = 1 to 10 Enter Sales Loop end The number of elements in array is 10 The counter of loop (R ) allows the computer to increase the element number by 1 each time a piece of data is entered into a memory location A(R ) = element R in the A array R 10 1 Enter Sales (R ) R B

Answer c) Print Loop counter Sales 1 200 2 300 3 150 4 400 5 275 6 125 7 175 8 450 9 475 10 350 Print headings Algorithm Print (store number, Sales, Percentage) Loop : R = 1 to 10 Enter Sales Loop end The number of elements in array is 10 The counter of loop (R ) allows the computer to increase the element number by 1 each time a piece of data is entered into a memory location A(R ) = element R in the A array R 10 1 Print R, Sales (R ) Percent(R ) R B