ㅎㅎ Fourth step for Learning C++ Programming Two functions

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

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.
CS 106 Introduction to Computer Science I 02 / 29 / 2008 Instructor: Michael Eckmann.
C++ Spring 2000 Arrays1 C++ Arrays. C++ Spring 2000 Arrays2 C++ Arrays An array is a consecutive group of memory locations. Each group is called an element.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
CS 106 Introduction to Computer Science I 02 / 28 / 2007 Instructor: Michael Eckmann.
Multiple-Subscripted Array
ARRAYS AND POINTERS Although pointer types are not integer types, some integer arithmetic operators can be applied to pointers. The affect of this arithmetic.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Chapter 8 Arrays and Strings
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
C Static Arrays Pepper. What is an array? Memory locations – same type – next to each other (contiguous) – Same name – Indexed by position number of type.
Methods Divide and conquer Programmer-declared methods Prepackaged methods – Java API Software reusability Debug-ability and maintainability AKA functions.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
Review Binary Numbers Bit : 0 or 1 Byte: 8 bites 256 different values 2 8 KB : 1024 bytes 2 10 bytes MB : 1024 * 1024 bytes 2 10 * 2 10 (2 20 ) bytes GB.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Bubble Sort Notes David Beard CIS220. Bubble Sort for Strings Double pass algorithm to sort a single dimensional array. Inner loop “bubbles” largest element.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
2D Arrays Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Spring 2006.
ADVANCED POINTERS. Overview Review on pointers and arrays Common troubles with pointers Multidimensional arrays Pointers as function arguments Functions.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
1 Chapter 2 Program Performance. 2 Concepts Memory and time complexity of a program Measuring the time complexity using the operation count and step count.
Arrays. C++ Style Data Structures: Arrays(1) An ordered set (sequence) with a fixed number of elements, all of the same type, where the basic operation.
C++ Arrays SarMag Trimester 31 C++ Arrays. C++ Arrays SarMag Trimester 32 C++ Arrays An array is a consecutive group of memory locations. Each group is.
Windows Programming Lecture 03. Pointers and Arrays.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
Objectives You should be able to describe: One-Dimensional Arrays
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Arrays in C. What is Array? The variables we have used so far can store a single value. Array is a new type of variable capable of storing many values.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
INC 161 , CPE 100 Computer Programming
Chapter 6 Arrays in C++ 2nd Semester King Saud University
Two-Dimensional Arrays
CHAPTER 3 ARRAYS.
An Introduction to Programming with C++ Sixth Edition
Computer Programming BCT 1113
C programming---Arrays
New Structure Recall “average.cpp” program
Arrays … The Sequel Applications and Extensions
Arrays, For loop While loop Do while loop
Peer Instruction 6 Java Arrays.
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Review for Final Exam.
Lecture 18 Arrays and Pointer Arithmetic
CS 1428 Final Exam Review.
Multidimensional Arrays
MSIS 655 Advanced Business Applications Programming
Review for Final Exam.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
To refer to an element, specify
COP 3330 Object-oriented Programming in C++
C++ winter2008(by:J.Razjouyan)
Arrays Arrays A few types Structures of related data items
Arrays.
Peer Instruction 4 Control Loops.
Exercise 5 1. We learned bubble sort during class. This problem requires you to modify the code for bubble sorting method to implement the selection sorting.
Arrays and Strings CSCI293 - C# September 26, 2005.
ㅎㅎ Fourth step for Learning C++ Programming Call by value
Arrays.
Presentation transcript:

ㅎㅎ Fourth step for Learning C++ Programming Two functions Recursive function Call by value Call by reference Array 2-D Array Array Searching

You have decide on what the function will look like: Writing a function You have decide on what the function will look like: Return type Name Types of parameters (number of parameters) You have to write the body (the actual code). 09/2014

[ Practice 01 Two functions ]

[ Explain 01 Two functions ]

[ Practice 02 Recursive function ]

[ Explain 02 Recursive function ]

[ Practice 03 Call by value ]

[ Explain 03 Call by value ] ① ③ ②

[ Practice 04 Call by reference ]

[ Practice 04 Call by reference ] ① ③ ②

An array is a sequence of consecutive memory elements. C++ Arrays An array is a sequence of consecutive memory elements. The contents of all elements are of the same type. Could be an array of int, double, char, … We can refer to individual elements by giving the position number (index) of the element in the array. 10/2014

int foo[6]; Each int is 4 bytes foo[0] foo[1] foo[5] 4 bytes Memory and Arrays 4 bytes Each int is 4 bytes foo[0] foo[1] int foo[6]; foo[5] 10/2014

C++ Arrays indexing start at 0 !!!!!!! The first element is the 0th element! If you declare an array of n elements, the last one is number n-1. If you try to access element number n it is an error! 10/2014

foo[17] foo[i+3] foo[a+b+c] Array Subscripts The element numbers are called subscripts. foo[i] A subscript can be any integer expression: These are all valid subscripts: foo[17] foo[i+3] foo[a+b+c] 10/2014

Initialization Rules for Arrays 1. int cards[4] = {3, 6, 8, 10}; //valid 2. int hand[4] = {}; 3. hand[4]; //invalid 4. float hotelTips[5] = {5.0, 2.5}; //valid - hotelTips[0] = 5.0, - hotelTips[1] = 2.5 5. long totals[500] = {0}; 6. short things[] = {1, 5, 3, 8}; Ο Ο X O Ο Ο

[ Practice 05 Array ]

[ Explain 05 Array ] index→ 0 1 2 index → 0 1 2

[ Practice 06 Array 2 ]

[ Explain 06 Array 2 ]

2-D Array: int A[3][4] Col 0 Col 1 Col 2 Col 3 Row 0 A[0][0] A[0][1] 10/2014

2-D Array: int A[3][4] Memory Organization { A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2] A[2][0] A[2][1] A[2][2] A[3][0] A[3][1] A[3][2] A[0] A[1] A[2] A[3] char A[4][3]; { A is an array of size 4. Each element of A is an array of 3 chars { { 10/2014

[ Practice 07 2-D Array ]

[ Expain 07 2-D Array ]

[ Practice 08 Array Searching ]

[ Explain 08 Array Searching ]

Bubble-Sort description The index j in the inner loop travels up the array, comparing adjacent entries in the array (at j and j+1), while the outer loop causes the inner loop to make repeated passes through the array. After the first pass, the largest element is guaranteed to be at the end of the array, after the second pass, the second largest element is in position, and so on. 10/2014

[ Practice 09 Bubble Sort ]

[ Explain 09 Bubble Sort ]