Programming 2. Arrays & structure Arrays : allow you to define variables that combine several data items of the same kind. Structure : is another user.

Slides:



Advertisements
Similar presentations
Chapter 7 Completing a Program
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 1.
1 Records C++ Structs Chapter 14 2 What to do with records?  Declaring records  Accessing records  Accessing the field of a record  What is a union?
1 Structures. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc) and other.
Operator Overloading. Introduction Operator overloading –Enabling C++’s operators to work with class objects –Using traditional operators with user-defined.
1 Chapter 11 Introducing the Class Pages ( )
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
1 Programming Structures COMP102 Prog. Fundamentals, Structures / Slide 2 2 Structures l A Structure is a collection of related data items, possibly.
Structure.
EC-241 Object-Oriented Programming
Inheritance Math 130 B Smith: Consider using the example in SAMS Teach Yourself C++ in 24 hours B Smith: Consider using the example in SAMS Teach Yourself.
C++ Classes & Data Abstraction
Destructors Math 130 Lecture # xx Mo/Da/Yr B Smith: New lecture for 05. Use this for evolving to Java B Smith: New lecture for 05. Use this for evolving.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types.
1 Using Classes and Working With Class Interfaces November 20, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 1 Overview – Chapter Section 4 Arrays and Classes (10.4)
1 C++ Structures Starting to think about objects...
C++ Classes & Object Oriented Programming. Object Oriented Programming  Programmer thinks about and defines the attributes and behavior of objects. 
Structured Data Types array array union union struct struct class class.
Module 4: Structures ITEI222 Advanced Programming.
Box 1Box 4Box 3Box 2 Box 5Box 8Box 7Box 6 My Shadow Box.
Programmer Defined Structures (Records)
DATA STRUCTURES LAB 1 TA: Nouf Al-harbi
Access Control Under Inheritance tMyn1 Access Control Under Inheritance The private data members of a base class are also members of the derived class,
1 Data Structures CSCI 132, Spring 2014 Lecture 10 Dynamic Memory and Pointers.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11: Structured Data.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Functions in C CSE 2451 Rong Shi. Functions Why use functions? – Reusability Same operation, different data – Abstraction Only need to know how to call.
1 Structs. 2 Defining a Structure Often need to keep track of several pieces of information about a given thing. Example: Box We know its length width.
Chapter 11 – Pointer Variables. Declaring a Pointer Variable u Declared with data type, * and identifier type* pointer_variable; u * follows data type.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Programming in C++ Michal Brabec Petr Malý. Class / Struct Class / Struct consists of: data members function members constructors destructor copy constructor.
Lecture 19: Introduction to Classes Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Struct Data Type in C++ What Are Structures?
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Matthew Small Introduction to Object-Oriented Programming.
Classes.  A collection of variables combined with a set of related functions MemberFunctions (methods) (methods) MemberVariables (data members) (data.
Enum,Structure and Nullable Types Ashima Wadhwa. Enumerations, Enumerations, or enums, are used to group named constants similar to how they are used.
AL-HUSEEN BIN TALAL UNIVERSITY College of Engineering Department of Computer Engineering Object-Oriented Programming Course No.: Fall 2014 Templates.
In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students.
Class & Objects C++ offers another user-defined data type known class which is the most important feature of the object-oriented programming. A class can.
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
Chapter 11 Structures, Unions and Typedef 11.1 Structures Structures allow us to group related data items of different types under a common name. The individual.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
Topic 4 Data Structures Program Development and Design Using C++, Third Edition.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Chapter 5 Classes.
This technique is Called “Divide and Conquer”.
Pointers Psst… over there.
Concepts and Basics of C++ Programming
C++ Classes & Object Oriented Programming
Pointers Psst… over there.
Introduction to Classes
Linked List Lesson xx   In this presentation, we introduce you to the basic elements of a linked list.
Starting to think about objects...
Static in Classes CSCE 121 J. Michael Moore.
CLASSES AND OBJECTS.
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Structures In C Programming By Rajanikanth B.
A “User – Defined Data Type”
Chapter 11 - Templates Outline Introduction Function Templates Overloading Function Templates Class Templates Class.
Types of Computer Languages
Structures Structured Data types Data abstraction structs ---
Topics to cover Instance variables vs. local variables.
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
Presentation transcript:

Programming 2

Arrays & structure Arrays : allow you to define variables that combine several data items of the same kind. Structure : is another user defined data type which allows you to combine data items of different kinds. Structures are used to represent a record.

Accessing Elements To access any member of a structure, we use themember access operator (.) intmain( ) { structBooks Book1; // Declare Book1 of type Book // book 1 specification strcpy( Book1.title, "Learn C++ Programming"); strcpy( Book1.author, "ChandMiyan"); strcpy( Book1.subject, "C++ Programming"); Book1.book_id = ; return 0; }

Classes & Objects Define classes

Define Objects

Example Int main( ) { Box Box1; // Declare Box1 of type Box double volume = 0.0; // Store the volume of a box here // box 1 specification Box1.height = 5.0; Box1.length = 6.0; Box1.breadth = 7.0; // volume of box 1 volume = Box1.height * Box1.length * Box1.breadth; cout<< "Volume of Box1 : " << volume <<endl; return 0; }

Public and Private Members public: The member (data or function) is accessible and available to all in the system. private: The member (data or function) is accessible and available within this class only.

Class Class: data member and functions. Object: instantiation of a class. type variable Int num; Student s1;

How to create and use a class!! First think about: a. data member b. functions Write your class code. Instantiate object of the class

Define a class Class is defined using: keyword class or keyword struct. Then class_name which must be a valid identifier for the class. The body of the class can contain members(data or function).

Accessing the members By inserting dot (.) between object_name and membername. Ex: Box1.length

Example Declared within the class Declared outside the class