C to C - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

C to C

Description:

Pure virtual methods in abstract base classes can be defined in different ways ... The classes are the abstract data types, which ancapsulate the common attributes ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 16
Provided by: homesI
Category:
Tags: abstract | base | classes

less

Transcript and Presenter's Notes

Title: C to C


1
C to C Chapter 13 prepared by Ilker Korkmaz
2
Moving from C to C
  • C is not a pure object oriented programming
    language. C provides the programmers with both
    imperative programming and object oriented
    programming styles.
  • It means that C programs can also be compiled
    with C compilers.
  • Why do we need C?
  • object oriented programming

3
Why Object Oriented Design Approach?
  • To implement the real world.
  • The world consists of objects.
  • A type of object includes the common members
    attributes and the methods.
  • The attributes are the information data, whereas
    the methods are the behaviours.
  • A class, which an object instantiates from, is
    the basic structure in the object-oriented world.
    The subclasses can be inherited from the base
    classes.
  • At first, an object is to be constructed from a
    class, and at last the object is to be
    destructed.
  • Above mentioned design approach is similar to the
    lives of the objects in the world.

4
Object Oriented Programming
  • Object oriented programming usually requires
    object oriented design.
  • 3 main concepts of object oriented design ans so
    object oriented programming
  • encapsulation
  • inheritance
  • polymorphism

5
encapsulation
  • to hide the information from irrelevant acces.
  • 3 main properties to access to data
  • private
  • public
  • protected

6
inheritance
  • A subclass (or child class), can be inherited
    from a super class (or base class, or parent
    class).
  • The subclass objects inherit the common
    attributes and the common methods from their
    parents.

7
polymorphism
  • 2 main polymorhism styles
  • compile-time polymorphism
  • overloading
  • The methods with the same names can be differed
    with different signatures.
  • The operators can be overloaded.
  • run-time polymorphism
  • virtual methods
  • Pure virtual methods in abstract base classes can
    be defined in different ways for different
    subclasses.

8
Basics for moving from C to C
(I)
  • source file
  • source.c --gt source.cpp / source.C / source.cxx
  • header file
  • ltmath.hgt --gt ltcmathgt
  • ltheader.hgt --gt ltcheadergt
  • compiler
  • gcc --gt g
  • Every C source file can be compiled with a C
    compiler or with a C compiler. However, C
    source files can only be compiled with C
    compilers.

9
Basics for moving from C to C
(II)
  • standard I/O
  • scanf --gt cin
  • printf --gt cout
  • ltstdio.hgt --gt ltiostreamgt
  • using namespace std

10
Basics for moving from C to C
(III)
  • Reference
  • type
  • call-by-reference concept
  • function(type) --gt
    function(type)
  • void swap(int, int) --gt void swap(int,
    int)

11
Basics for moving from C to C
(IV)
  • The structure declarations of C source files are
    to be redesigned as the class declarations in
    C.
  • struct ---gt class.
  • The classes are the abstract data types, which
    ancapsulate the common attributes and provide the
    common methods for the objects to be instantiated.

12
overloading
  • method overloading
  • double add(double, double)
  • int add(int, int)
  • operator overloading
  • double operator(double, double)

13
constructor/destructor
  • constructor
  • The special method of a class with the same name
    of the class.
  • The constructor can be seen as the object
    initializing method that every class has to
    include either explicitly or implicitly.
  • An object instantiates through its class's
    constructor method.
  • Destructor
  • Another special method of a class, which is
    automatically invoked when an object is destroyed.

14
inheritance
  • A new class can be implemented as a child of
    another existing class.
  • A subclass inherits the common data of its
    parent(s).
  • Good object oriented programming needs to use the
    inheritance properly.

15
Examples
  • First of all, how to write Hello World in
    C...
  • Then, how to convert struct Student declaration
    into class Student declaration...
  • Finally,
  • How to declare a convenient Student abstract
    data type...
  • How to use the encapsulation and the inheritance
    concepts through the Student class...
  • ...
Write a Comment
User Comments (0)
About PowerShow.com