1 Lab Session-XII CSIT121 Spring 2002 b Arrays and Their Usage b Finding the largest element b Lab Exercise 12-A b Lab Demo (12-B) b Practice Problems.

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

Why not just use Arrays? Java ArrayLists.
Recursion.
Lists: An internal look
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.
Searching for Data Relationship between searching and sorting Simple linear searching Linear searching of sorted data Searching for string or numeric data.
Week 8 Arrays Part 2 String & Pointer
Aalborg Media Lab 2-May-15 Exercises/Summary Lecture 10 Summary, Exercises.
Monday, 11/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Monday, 11/11/02  Questions? HW 04 due today at 5.  Today – Lists and an introduction to searching.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
1 Lab-1 CSIT-121 Spring 2005 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
1 Lab Session-XI CSIT121 Fall 2000 b Arrays and Their Usage b Finding the largest element b Lab Exercise 11-A b Searching for some value b Lab Exercise.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
Overview Sort – placing data in an array in some order (usually decreasing or increasing order) Bubble Sort More efficient bubble sort.
1 Chapter 18 Recursion Dale/Weems/Headington. 2 Chapter 18 Topics l Meaning of Recursion l Base Case and General Case in Recursive Function Definitions.
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 1 Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
 2003 Prentice Hall, Inc. All rights reserved Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
Sorting and Searching Algorithms Week 11 DSA. Recap etc. Arrays are lists of data 1-D, 2-D etc. Lists associated with searching and sorting Other structures.
Searching Arrays Linear search Binary search small arrays
1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
1 Lab Session-IX CSIT121 Fall 2000 w Arrays and Their Usage w Examples and Lab Exercises w Passing Arrays to Functions w Examples and Exercises w Sorting.
1 Lab Session-12 CSIT121 Fall 2004 Structures and Their Usage Passing Struct Variables to Functions.
The Binary Search Textbook Authors: Ken Lambert & Doug Nance PowerPoint Lecture by Dave Clausen
1 C++ Plus Data Structures Nell Dale Chapter 7 Programming with Recursion Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
Subroutines in Computer Programming Svetlin Nakov Telerik Corporation
1 Lab Session-XI CSIT121 Spring 2002 w Sorting the arrays (array application) w Bubble Sort w Structures and Their Usage w Passing Struct Variables to.
Chapter 6 One-Dimensional Arrays ELEC 206 Computer Tools for Electrical Engineering.
INTRODUCTION TO BINARY TREES P SORTING  Review of Linear Search: –again, begin with first element and search through list until finding element,
Higher Grade Computing Studies 4. Standard Algorithms Higher Computing Software Development S. McCrossan 1 Linear Search This algorithm allows the programmer.
Starting Out with C++, 3 rd Edition 1 Searching an Arrays.
COMP102 Lab 121 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
SEARCHING. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
1 Special Programming Workshop CSIT-120 Fall 2000 Workshop Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming.
Lecture 6 : Intro. to Generic Programming Acknowledgement : courtesy of Prof. Dekai Wu lecture slides.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 12 – Data Structures – Trees Sorting Algorithms.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
ECE 103 Engineering Programming Chapter 50 Structures Unions, Part 2 Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE.
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
Chapter 7 Arrays. Introductions Declare 1 variable to store a test score of 1 student. int score; Declare 2 variables to store a test score of 2 students.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
Class Method Read class Student { private: string id; string firstName, lastName; float gpa; public: // Will the method change any data members? // Yes!
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
Searching Arrays Linear search Binary search small arrays
Sorted Dynamic Array Bag and Set
Vectors.
Dr. Joe Anderson September 6, 2017
7. 11 Introduction to C++ Standard Library Class Template vector (Cont
Ken Lambert & Doug Nance
The Binary Search by Mr. Dave Clausen
Presentation transcript:

1 Lab Session-XII CSIT121 Spring 2002 b Arrays and Their Usage b Finding the largest element b Lab Exercise 12-A b Lab Demo (12-B) b Practice Problems

2 Arrays and Their Usage b Arrays hold similar and related data items however data values are different b We can use arrays in any program where we have to deal with large amount of similar data using an INDEX into the data

3 Finding Largest Value b Often we will need to find the largest value in an array. b We can designate the first element as the largest in the beginning b As we compare one by one, we change mind if a larger value is found

4 Lab Exercise 12-A b Let us define an array and initialize it with some values b const int PLACES=15 b int distances[PLACES]={24,56,78,24, b 12,94,18,91,77,11,97,82,45,95,88}; b We wish to find the largest distance value in this array

5 Lab Exercise 12-A Data Modeling b an array int distances[] b an integer largest as index to largest value Algorithm b largest=0, for (1 to PLACES-1) Repeat 1 & 2 b 1. Designate distances[largest] as largest b 2. Compare with current value and change the largest index if found higher

6 Lab Exercise 12-B (Demo Required) b Develop a program that keeps information of names and ages of a group of 5 people.. An array of structs is recommended. This program calls a function and passes the array to it. The function prints the names and ages of all people in a nicely formatted way. Sample Data that can be used is as follows:

7 Sample Data for Ex 12-B b b Jason Anderson, 21 b b Christina Smith, 35 b b Brian Smith Jr., 42 b b Derek Dustin, 18 b b Jason Geiger, 19

8 Practice Problem b Given an array of ID numbers of library defaulters, search for the occurrence of a specific ID number to see if this person is a library defaulter or not Data Modeling b int defaulters[MAXSIZE]; b int target_ID; b bool not_found;

9 Practice Problem Algorithm b not_found=true; b While (not_found) b Match the target_ID with contents of the defaulters array one by one b If matched, assign not_found=false b Else if array end reached, person not found

10 Sample Data b const int MAXSIZE=20; b int defaulters[MAXSIZE] = b {2435,1211,7643,2437,9834,2001,1029,1290, b 2340,2200,1214,4438,2105,4355,8254,9120, b 2502,9403,1006,1205}; b target_ID = 8254 b target_ID=2000

11 Additional Practice Problems b Define a union that can hold temperature. The temperature can be stored in degrees Celsius or degrees Fahrenheit. Assign 35 degrees Celsius to the appropriate union member and display. Then convert it to Fahrenheit, store and display b Modify 12-B to include a union in the struct. This union should be able to sore the age in months or years

12 For Lab 13, Demo Problem b Write a value returning recursive function that implements the recursive formula: b F(N) = F(N-1) – F(N-2) b Where F(1) equals 9 and F(0) equals 3; b HINT: The base case here could be reached when N-1 equals 1 and N-2 equals zero