Visual C++ Programming: Concepts and Projects Chapter 11B: Pointers (Tutorial)

Slides:



Advertisements
Similar presentations
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 10 Arrays and Tile Mapping Starting Out with Games & Graphics.
Advertisements

Programming and Data Structure
Chapter 6: The Repetition Structure
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Chapter 10 Introduction to Arrays
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Visual C++ Programming: Concepts and Projects
Programming with Microsoft Visual Basic 2005, Third Edition
VBA Modules, Functions, Variables, and Constants
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
An Introduction to Programming with C++ Fifth Edition
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Introduction to Arrays Chapter 7 Why use arrays? To store & represent lists of homogeneous values To simplify program code To eliminate the need to reread.
Visual C++ Programming: Concepts and Projects
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
CS 104 October 26, 2011 App Inventor. Agenda Discuss guest speakers Discuss quiz Finish Paint Pot Discuss concepts from Chapters 2 & 3 Mole Mash (if time.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es.
Visual C++ Programming: Concepts and Projects Chapter 6A: Methods (Concepts)
Microsoft Visual Basic 2008: Reloaded Fourth Edition
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
Programming with Visual C++: Concepts and Projects Chapter 3B: Integral Data (Tutorial)
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Fundamentals of GUI Programming. Objectives: At the end of the session, you should be able to: describe the guidelines that are used for creating user-friendly.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Tutorial 6 The Repetition Structure
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Visual C++ Programming: Concepts and Projects Chapter 12B: Linked List (Tutorial)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3B Integral Data (Tutorial)
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Programming with Visual C++: Concepts and Projects Chapter 4B: Selection (Tutorial)
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Times Table Quiz This will contribute towards your online portfolio for this module.
Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Visual C++ Programming: Concepts and Projects Chapter 10B: Recursion (Tutorial)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine.
Making Interactive Programs with Visual Basic .NET
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Visual C++ Programming: Concepts and Projects
Chapter 8 Arrays Objectives
Chapter 8 Arrays Objectives
Visual Basic: Week 5 Review User defined functions
Chapter 8 Arrays Objectives
Presentation transcript:

Visual C++ Programming: Concepts and Projects Chapter 11B: Pointers (Tutorial)

Tutorial: Sorting with a Pointer Array Problem description – Create an array of integers and display its values and the address of each element – Create an array of pointers to integers – Assign the address of each element in the integer array to the corresponding elements of the pointer array – Sort the data by swapping pointers – Display the sorted data by using a for loop to access each element of the pointer array 2Programming with Visual C++

Problem Description 3Programming with Visual C++

Problem Description (continued) 4Programming with Visual C++

Problem Description (continued) 5Programming with Visual C++

Design Interface sketch Control table Instance variables – Data table – Drawing objects 6Programming with Visual C++

Design (continued) 7Programming with Visual C++

Design (continued) 8Programming with Visual C++

Design (continued) 9Programming with Visual C++

Design (continued) Variables for DrawLines() Each line drawn from the pointer array to the data array text boxes needs starting and ending coordinates 10Programming with Visual C++

Design (continued) 11Programming with Visual C++

Design (continued) Event handlers – btnData_Click() Generates random numbers in the data array Captures data array element addresses and assigns to the pointer array Displays data and pointers Draws lines connecting them 12Programming with Visual C++

Design (continued) 13Programming with Visual C++

Design (continued) Event handlers – btnSort_Click() Sort the data by swapping pointers Draw lines from each pointer to the appropriate data item Display the sorted data in a MessageBox 14Programming with Visual C++

Design (continued) 15Programming with Visual C++

Design (continued) Algorithm for DrawLines() – Uses the following textbox properties Location.X Location.Y Width Height 16Programming with Visual C++

Design (continued) 17Programming with Visual C++

Design (continued) 18Programming with Visual C++

Design (continued) Algorithm for DrawLines() (continued) – Draws lines connecting pointer array text boxes to data array text boxes – Lines begin at the midpoint of the right side of each pointer text box (ptrX, ptrY) 19Programming with Visual C++

Design (continued) 20Programming with Visual C++

Design (continued) 21Programming with Visual C++

Design (continued) Algorithm for DrawLines() (continued) – In this example, the pointer text boxes are separated by 32 pixels vertically 22Programming with Visual C++

Design (continued) 23Programming with Visual C++

Design (continued) 24Programming with Visual C++

Design (continued) Algorithm for DrawLines() (continued) – Lines end at the midpoint of the left side of the appropriate data text box (arrX, arrY) – Variable startX stores the y coordinate of the first data text box 25Programming with Visual C++

Design (continued) 26Programming with Visual C++

Design (continued) 27Programming with Visual C++

Design (continued) Algorithm for DrawLines() (continued) – The location of arrY is calculated by: Determining how many elements away from the first element you must go Multiplying the number of elements by 32 (the number of pixels separating each element) 28Programming with Visual C++

Design (continued) 29Programming with Visual C++

Design (continued) Algorithm for DrawLines() (continued) – To determine how many elements away from the first element you must go, subtract the pointer array value from the address of the first data element ( &(arr[0]) ) 30Programming with Visual C++

Design (continued) 31Programming with Visual C++

Development The interface – Based on Figure Coding – Instance variable declarations and Form1_Load() – The btnData_Click() event handler – The btnSort_Click() event handler – The drawLines() method 32Programming with Visual C++

Development (continued) 33Programming with Visual C++

Development (continued) The btnData_Click() event handler – Assigns random numbers to each array element – Displays the data values in arr to the data text boxes – Displays the addresses of each element of the data array To the data text box labels To the pointer array elements – Displays the pointer array values – Draws the lines connecting pointer and data text boxes 34Programming with Visual C++

Development (continued) 35Programming with Visual C++

Development (continued) 36Programming with Visual C++

Development (continued) 37Programming with Visual C++

Development (continued) 38Programming with Visual C++

Development (continued) 39Programming with Visual C++

Development (continued) The btnSort_Click() event handler – Sorts the pointer array according to the values in the data array – Displays the pointers – Creates output string – Draws the connecting lines (once before and once after the MessageBox is displayed) 40Programming with Visual C++

Development (continued) 41Programming with Visual C++

Development (continued) The DisplayPointer() method – Displays pointer values on the interface 42Programming with Visual C++

Development (continued) 43Programming with Visual C++

Development (continued) The drawLines() method – Calculates ptrX, ptrY – Calculates the corresponding arrX and arrY – Draws lines between (ptrX, ptrY) on the pointer array and (arrX, arrY) on the data array for each element of the pointer array 44Programming with Visual C++

Development (continued) 45Programming with Visual C++

Testing Run your program several times – btnSort should be initially disabled – When btnData is clicked, random numbers are generated and displayed, and the memory cell addresses of the data array are displayed – When btnSort is clicked, the pointer array elements are swapped until they point to the data array elements in sorted order 46Programming with Visual C++

On Your Own Descending order – Rewrite your bubble sort method Removing the swap() method – Place the instructions back in their proper place in the bubble sort 47Programming with Visual C++