Structures 11/5/10. Reading  Read pp.219-226  Review of scope ch6/review.cpp ch6/review.cpp What is the output? What is the output?

Slides:



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

Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
CS-2135 Object Oriented Programming
Classes and Objects April 6, Object Oriented Programming Creating functions helps to make code that we can reuse. When programs get large it becomes.
Accessor Functions 04/13/11. Encapsulation  Like case on my watch Protect from outside Protect from outside Have member functions control data Have member.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Structures  2 nd aggregate data type: struct  Recall:
1 Structures. Structure (struct) Definition A Structure is a container, it can hold a bunch of things. –These things can be of any type. Structures are.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
1 Chapter 13 Introduction to Classes. 2 Topics 12.1 Procedural and Object-Oriented Programming 12.2 Introduction to Classes 12.3 Defining an Instance.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
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.
Classes Definition A class is a data type whose variables are objects Object – a variable that has member functions as well the ability to hold.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
11 Introduction to Object Oriented Programming (Continued) Cats.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Objects and Classes Project 2 description.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Slide 1 Chapter 6 Structures and Classes. Slide 2 Learning Objectives  Structures  Structure types  Structures as function arguments  Initializing.
1 CS161 Introduction to Computer Science Topic #15.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Matthew Small Introduction to Object-Oriented Programming.
Functions Venkatesh Ramamoorthy 21-March Examples #include double y ; … y = sin(45*3.1416/180) ; std::cout
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
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.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Class Definitions and Writing Methods Chapter 3 3/31/16 & 4/4/16.
Class Definitions and Writing Methods Chapter 3 10/12/15 & 10/13/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
CSIS 123A Lecture 1 Intro To Classes Glenn Stevenson CSIS 113A MSJC.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
Structures and Classes
Procedural and Object-Oriented Programming
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Chapter 7: Introduction to Classes and Objects
Abstract Data Types Programmer-created data types that specify
Andy Wang Object Oriented Programming in C++ COP 3330
10.2 Classes Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.
Class Definitions and Writing Methods
Review: Two Programming Paradigms
Exam 3 Review.
Introduction to Classes
Chapter 7: Introduction to Classes and Objects
Concepts and Basics of C++ Programming
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
This technique is Called “Divide and Conquer”.
Concepts and Basics of C++ Programming
Introduction to Classes
Learning Objectives Classes Constructors Principles of OOP
From C to C++: Summary of weeks 1 - 4
COP 3330 Object-oriented Programming in C++
NAME 436.
Recitation Course 0603 Speaker: Liu Yu-Jiun.
Chapter 9 Introduction To Classes
Chapter 6 Modular Programming chap6.
Class rational part2.
CS 201(Introduction To Programming)
Constructors & Destructors
Presentation transcript:

Structures 11/5/10

Reading  Read pp  Review of scope ch6/review.cpp ch6/review.cpp What is the output? What is the output?

Structures  Record Information pertaining to an entity Information pertaining to an entity  Structure The programmer defines new data type. The programmer defines new data type. Data type for a record composed of multiple components. Data type for a record composed of multiple components.

Structures  Example: Represent Date Represent Date Components: Month, Day and Year Components: Month, Day and Year In C++ the components are called data membersIn C++ the components are called data members ch6/sec6.1/struct.cpp ch6/sec6.1/struct.cpp

Structures  Format: struct Name { type component; type component;..};

Structures  Accessing Structure components  Use member access operator The period The period  e.g. holiday.mo = 11;  Another example in sec6.1/metal.cpp

Exercises  p. 222 #1, 2

Classes and Objects

Class  Model Real-World Objects  Take struct one step further  Have: data members data members member functions member functions

Object  Class is a type that you define as a programmer.  Object is a variable of that type.

Class and Object  example: ch6/sec6.2/temperature.cpp

Class Definition class Sample { public: fnc_prototype(); public: fnc_prototype(); fnc_prototype2(); fnc_prototype2(); //... etc. //... etc. member_var1; member_var1; member_var2; member_var2; // … etc. // … etc.};

Member Function Definition return_type class_name :: function_name(parmlist)‏ {statements}  :: is scope resolution operator

Calling a function Object_name.function_name(arg list); e.g. High.input_T( );

Scope of data members  Can use data members in any of the functions in the class.  There is no need to pass them to functions.

Example  Create a class for a phone number. Have a char that tells if it is work, 'w', home. 'h', or cell, 'c'. Have a char that tells if it is work, 'w', home. 'h', or cell, 'c'. Have the number and area code as separate ints. Have the number and area code as separate ints. Write member functions to: Write member functions to:  Input a phoneNumber  Output a phoneNumber.  Change a phoneNumber.

Encapsulation  Like case on my watch Protect from outside Protect from outside Have member functions control data Have member functions control data Like buttons on watchLike buttons on watch Protect data from outside world. Protect data from outside world. Like the internal workings of my watch are protected.Like the internal workings of my watch are protected. Don’t let the outside functions change the data.Don’t let the outside functions change the data.

Access Specifiers  Indicate accessibility of class members  public: Open access to outside functions Open access to outside functions Member functions are usually public. Member functions are usually public.  private: Access restricted to other members of class Access restricted to other members of class Member variables private Member variables private  Example: sec6.2/rectangle.cpp

Correction  rectangle1.cpp – has accessor functions.

Accessor Functions  Main program can't directly access private data members.  Create accessor function to allow access. Name usually begins with “get” Name usually begins with “get”  dog.cpp