Oops and c fundamentals

16

Transcript of Oops and c fundamentals

Page 1: Oops and c fundamentals
Page 2: Oops and c fundamentals

HISTORY OF C++

• Created by Bjarne stroustrup.

• The C language is still supported with C++.

• BCPL language contributed many ideas.

• Class and oop comes from Simula67.

• Originally known as c with class.

• C++ named by Rick Mascitti in 1983.

Page 3: Oops and c fundamentals

• Still low level enough to be efficient.

• Still high level enough to be easy to code in.

• Makes heavy use of additional libraries.

• Comes with intrinsic math function etc.

• Able to coexit with other language.

Page 4: Oops and c fundamentals

Will not help a bad programmer to be good one. Oop will assist in the design of the program. C is not necessary to know before C++. If you know c , it’s good. But i am not recommmedning

you to use some bad procedurial way of programming. So better stay away from those and make you life more easier with C++.

Page 5: Oops and c fundamentals

MOST USED SHORTCUT KEYS IN TC

• As a good programmer you must use the short cut keys.

• Save – F2

• Compile – F9

• Make – Alt+F9

• Run – Ctrl+F9

Page 6: Oops and c fundamentals

YOUR FIRST PROGRAMME

Header file – the function description and it’s action code in those file.

Main function – Your programe execution strats from here.

Hence all code must be inside of main function

Cout is used to display something on screen.

#include<stdio.h>#include<iostream.h>

int main(){cout<<"Hi! Welcome to OOP's world";return 0;}

Page 7: Oops and c fundamentals

WHAT IS OBJECT-ORIENTED PROGRAMMING?

In structured programming techniques programs are typically organized around code. In Object-oriented programming techniques programs are organized around data, with the key

principle being "data controlling access to code." In an object-oriented language, you define the data and the routines that are permitted to act on that data.

We must define precisely the data type what sort of operations can be applied to that data.

Page 8: Oops and c fundamentals

THREE TRAITS OF OOP

• According to the principles of object-oriented programming, all OOP languages have three traits in common:

• Encapsulation

• Polymorphism

• inheritance

Page 9: Oops and c fundamentals

ENCAPSULATION

Encapsulation is the mechanism that binds together code and the data it manipulates. It keeps both safe from outside interference and misuse. In object – oriented language code and data may be combined in such a way that a self-

contained "black box" is created.

Page 10: Oops and c fundamentals

• code and data are linked together in this fashion, an object is created. We can say this as an object is the device that supports encapsulation.

• Within an object, code, data, or both may be private to that object or public.

• An object is a variable of a user-defined type. We can use it as like variable. However, in object-oriented programming, Each time you define a new type of object, you are creating a new data type. Each specific instance of this data type is a compound variable.

Page 11: Oops and c fundamentals

PRIVATE AND PUBLIC

Page 12: Oops and c fundamentals

POLYMORPHISM

Polymorphism is characterized by the phrase "one interface, multiple methods”. polymorphism is the attribute that allows one interface to control access to a general class of

actions. The specific action selected is determined by the exact nature of the situation.

Page 13: Oops and c fundamentals

It helps reduce complexity by allowing the same interface to be used to access a general class of actions.

It is not our job to select the specific action as it applies to each situation. It is the job of our compiler(which compiles your program writeen in high level language).

C++, both run-time and compile-time polymorphism are supported.

Page 14: Oops and c fundamentals

INHERITANCE

Inheritance is the process by which one object can acquire the properties of another object like son has some father’s characters.

This is important because it supports the concept of classification. Without inheritance we have to define properties or behaviour explicitly for each and every class

even those are related to some one.

Page 15: Oops and c fundamentals

Example of inheritance

Page 16: Oops and c fundamentals

• However, through the use of classifications, an object need only define those qualities that make it unique within its class. It is the inheritance mechanism that makes it possible for one object to be a specific instance of a more general case.

• Go to my blog to download the program excellentprogramming