fjj hreees vlaks opea

Upload: matthew-recto

Post on 02-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 FJJ Hreees Vlaks Opea

    1/29

    C++ Programming

    Preliminaries

  • 8/10/2019 FJJ Hreees Vlaks Opea

    2/29

    Origins of C++

    Creation started in 1979 by Bjarne Stroustrup

    Initially called C with classes

    In 1983 it was called C++

    19791980s 1990s development and refinementof C++.

    May 1990 C++ was released

    1998 ANSI version of C++ was adopted

    C++ is the object-oriented version of C.C++ began as a set of object-oriented extensions toC

    Presently, C++ is twice the size of C, it is one of the

    most powerful programming languages ever devised.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    3/29

    What is OOP

    OOP is a new way of approaching the job ofprogramming.

    Evolution Binary machines toggle instructions

    Assembly Language for larger programs, usessymbolic representations of the machineinstructions.

    High level languages (fortran, 1stwidely usedlanguage)impressive step

    1960s gave birth to structured programming

  • 8/10/2019 FJJ Hreees Vlaks Opea

    4/29

    OOP

    Structured Programming Method encouraged by languages such as C and

    Pascal

    It made programming a lot easy Size problems (25K100K SLOC)

    Object Oriented Programming Takes the best ideas of structured programming

    and combines them with powerful, new conceptsthat encourage you to look at the task ofprogramming in a new perspective.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    5/29

    OOP

    Allows you to easily decompose aproblem into subgroups of related

    parts.These subgroups can be translated intoself-contained units called objects.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    6/29

    Objects

    The single most important feature of anobject-oriented language.

    An object is a logical entity containing dataand code that manipulates that data.

    An object is a variable of a user-defined type.

    Within an object some of the code or datamaybeprivateto the object and inaccessibleby anything outside the object.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    7/29

    PrivateObject

    Object provides a significant level ofprotection against accidental

    modification or incorrect use.The linkage of code and data is oftenreferred to as encapsulation.

    In OOP, when you define an object youare implicitly creating a new data type.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    8/29

    Class

    Class is the root of C++.

    Before creating objects classes must be

    defined first. (to instantiate)It can contain private (by default) andpublic parts

    It is suggested to keep all data private.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    9/29

    Polymorphism

    It allows one name to be used for severalrelated but slightly different purposes.

    The purpose is to let one name to be used tospecify a general class of action.

    Depending upon what type of data it isdealing with, a specific instance of the

    general case is executed.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    10/29

    Inheritance

    Is the process by which one object canacquire the properties of another object.

    It supports the concept of classification

    With classification, an object need only definethose qualities that make it unique within itsclass.

    This mechanism makes it possible for oneobject to be a specific instance of a moregeneral case.

  • 8/10/2019 FJJ Hreees Vlaks Opea

    11/29

    Inheritance Example

  • 8/10/2019 FJJ Hreees Vlaks Opea

    12/29

    Visual C++ Environment

  • 8/10/2019 FJJ Hreees Vlaks Opea

    13/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    14/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    15/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    16/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    17/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    18/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    19/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    20/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    21/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    22/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    23/29

    Hello World (,)

  • 8/10/2019 FJJ Hreees Vlaks Opea

    24/29

  • 8/10/2019 FJJ Hreees Vlaks Opea

    25/29

    // Reads values for the length and width of a rectangle

    // and returns the perimeter and area of the rectangle.

    #include

    void main()

    {

    int length, width;

    int perimeter, area; // declarations

    cout > length; // enter length

    cout > width; // input width

    perimeter = 2*(length+width); // compute perimeter

    area = length*width; // compute area

    cout

  • 8/10/2019 FJJ Hreees Vlaks Opea

    26/29

    // Reads values for the length and width of a rectangle

    // and returns the perimeter and area of the rectangle.

    #include

    void main(void)

    {

    int length, width;

    int perimeter, area; // declarations

    cout > length; // enter length

    cout > width; // input width

    perimeter = 2*(length+width); // compute perimeter

    area = length*width; // compute area

    cout

  • 8/10/2019 FJJ Hreees Vlaks Opea

    27/29

    C++ Statements

    cout

  • 8/10/2019 FJJ Hreees Vlaks Opea

    28/29

    C++ Statements

    cin >> i;

    //variable i is int

    /*variable i is

    char*/

    Single line

    comment

    Multi-line

    comment

    refers to

    the

    keyboard

    -- input

    input

    (right shift)

    operator

  • 8/10/2019 FJJ Hreees Vlaks Opea

    29/29