Overview of Previous Lesson(s) Over View VP is the methodology in which development allows the user to grab and use the desired tools like menus, buttons,

Slides:



Advertisements
Similar presentations
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Advertisements

C Language.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
The Assembly Language Level
Kernighan/Ritchie: Kelley/Pohl:
Overview of Previous Lesson(s) Over View  Assertions  assert() library function is declared in the cassert header to check logical conditions in native.
Overview of Previous Lesson(s) Over View  In computing, a visual programming language (VPL) is any programming language that lets users create programs.
Chapter 14: Overloading and Templates
Run time vs. Compile time
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Linked Lists Chained nodes of information create what are called linked lists, with each node providing a link to the next node. A useful feature of linked.
C++ for Engineers and Scientists Third Edition
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
C++ fundamentals.
C Programming Lecture 14 Arrays. What is an Array? b An array is a sequence of data items that are: all of the same typeall of the same type –a sequence.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
1.  Collections are data structures that holds data in different ways for flexible operations  C# Collection classes are defined as part of the ◦ System.Collections.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
A First Book of ANSI C Fourth Edition
17. ADVANCED USES OF POINTERS. Dynamic Storage Allocation Many programs require dynamic storage allocation: the ability to allocate storage as needed.
Overview of Previous Lesson(s) Over View  Operator Overloading:  Operator overloading is a very important capability, it enables to make standard C++
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
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.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Java SE 8 for Programmers, Third Edition
1 Chapter 8 Destructor & Operator Overloading. 2 Destructor  A destructor is a function that is called when an object is no longer required. A constructor.
Learners Support Publications Classes and Objects.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Overview of Previous Lesson(s) Over View .NET Framework is a software framework developed by Microsoft that runs primarily on Microsoft Windows.  It.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Recap Visual Perception and Data Visualization Types of Information Display Examples of Diagrams used for Data Display Planning Requirement for Data Visualization.
Chapter 8: Arrays and Functions Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
Vladimir Misic: Characters and Strings1Tuesday, 9:39 AM Characters and Strings.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Overview of Previous Lesson(s) Over View 3 Program.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
CS 31 Discussion, Week 7 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
Overview of Previous Lesson(s) Over View 3  CLR Programming  Common Language Runtime (CLR) is a programming, that manages the execution of programs,
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Chapter 5 Arrays Copyright © 2016 Pearson, Inc. All rights reserved.
Prepared by Andrew Jung. Contents A Simple program – C++ C++ Standard Library & Header files Inline Functions References and Reference Parameters Empty.
Data Structures & Algorithms CHAPTER 2 Arrays Ms. Manal Al-Asmari.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Arrays Chapter 7.
Object Oriented Programming in java
Classes and Objects.
Chapter 8 (Part 2) Destructor & Operator Overloading (P.331)
Presentation transcript:

Overview of Previous Lesson(s)

Over View VP is the methodology in which development allows the user to grab and use the desired tools like menus, buttons, controls and other elements from a palette. 3

Over View  Operator Overloading:  Operator overloading is a very important capability, it enables to make standard C++ operators, such as +, -, *, and so on, work with objects of user defined data types.  Following operators can’t be overloaded: 4

Over View..  Class Template  A class template is not a class, but a sort of recipe for a class that will be used by the compiler to generate the code for a class. 5

Over View…  Problem Definition:  The principal function of a box is to contain objects of one kind or another, so, in one word, the problem is packaging.  Basic operations on CBox class include:  Calculate the volume of a Cbox.  Compare the volumes of two CBox objects.  Compare the volume of a CBox object with a specified value, and vice versa. 6

Over View...  Add two CBox objects to produce a new CBox object that will contain both the original objects.  Multiply a CBox object by an integer (and vice versa).  Determine how many CBox objects of a given size can be packed in another CBox object of a given size.  Determine the volume of space remaining in a CBox object after packing it with the maximum number of CBox objects of a given size. 7

8

Contents  A Multi-file Project  Organizing Program Code  Naming Program Files  CLR Programming  Arrays  Sorting Arrays 9

A Multi-file Project  Before we actually start writing the code to use the CBox class and its overloaded operators, first we assemble the definition for the class into a coherent whole.  We are going to take a rather different approach from what we have done previously.  We are also going to start using the facilities that Visual C / 2010 provides for creating and maintaining code for our classes.  This mean that practically we do rather less of the work, but it will also mean that the code will be slightly different in places. 10

A Multi-file Project..  Lets Code some files.. 11

Organizing Program Code  In our project we distributed the code among several files for the first time.  It is not a common practice with C++ applications generally, but with Windows programming, it is essential.  The sheer volume of code involved in even the simplest program necessitates dividing it into workable chunks.  There are basically two kinds of source code files in a  Header Files  Source Files 12

Organizing Program Code.. 13

Naming Program Files  For classes of any complexity, it’s usual to store the class definition in a.h file with a file name based on the class name.  Store the implementation of the function members of the class that are defined outside the class definition in a.cpp file with the same name. 14

Naming Program Files..  On this basis, the definition of our CBox class appeared in a file with the name Box.h  Similarly, the class implementation was stored in the file Box.cpp.  With programs of any size it would be a good idea to get into the habit of creating.h and.cpp files to hold your program code from now on. 15

Naming Program Files..  Segmenting a C++ program into.h and.cpp files is a very convenient approach, as it makes it easy to find the definition or implementation of any class.  As long as you know the class name, you can go directly to the file you want.  However you can choose to structure your files, the Class View still displays all the individual classes, as well as all the members of each class 16

C++ / CLI Programming 17

Arrays  CLR arrays are different from the native C++ arrays.  Memory for a CLR array is allocated on the garbage - collected heap.  The general form for specifying the type of variable to reference a one - dimensional array is array ^  CLR array is created on the heap so an array variable is always have a tracking handle. array ^ data;  The array variable, data can store a reference to any one - dimensional array of elements of type int. 18

Arrays..  CLR array can be created using the gcnew operator at the same time that you declare the array variable: array ^ data = gcnew array (100);  Functional notation can also be used to initialize the variable data : array ^ data(gcnew array (100));  Elements in a CLR array are objects; here storing objects are of type Int32 in the array.  An array variable can store the address of any array of the same rank (the rank being the number of dimensions, which in the case of the data array is 1) and element type. 19

Arrays data = gcnew array (45);  This statement creates a new one - dimensional array of 45 elements of type int and stores its address in data.  The original array referenced by the handle, data, is discarded.  static Clear() function of the Array class can be used to set any sequence of numeric elements in an array to zero.  You call a static function using the class name. Array::Clear(samples, 0, samples- > Length); 20

Arrays  The first argument to Clear() is the array that is to be cleared.  The second argument is the index for the first element to be cleared.  The third argument is the number of elements to be cleared.  Thus, this example sets all the elements of the samples array to 0.0.  If Clear() function is applied to an array of tracking handles such as String^, the elements are set to nullptr.  Apply it to an array of bool elements they are set to false. 21

Using a CLR Array  Lets do the practical work … 22

Sorting Arrays  The Array class in the System namespace defines a Sort() function that sorts the elements of a one - dimensional array so that they are in ascending order.  To sort an array, just pass the array handle to the Sort() function.  Here ’ s an example: array ^ samples = { 27, 3, 54, 11, 18, 2, 16}; Array::Sort(samples); // Sort the array elements for each(int value in samples) // Output the array elements Console::Write(L"{0, 8}", value); Console::WriteLine(); 23

Sorting Arrays..  The call to the Sort() function rearranges the values of the elements in the samples array into ascending sequence.  The result of executing this code fragment is:  We can also sort a range of elements in an array by supplying two more arguments to the Sort() function, specifying the index for the first element of those to be sorted, and the number of elements to be sorted. array ^ samples = { 27, 3, 54, 11, 18, 2, 16}; Array::Sort(samples, 2, 3); // Sort elements 2 to 4 24

Thank You 25