C++ Concepts

Description

C++ Concepts

Comments
Would you like to comment?

Sign In if already a member, or Join Now for a free account.

Presentation Transcript Presentation Transcript

Introduction to C++ : Introduction to C++ 1998. 5. 4. Pang Min-seok KAIST Dept. of I.E. SPARCS ’97 noticeme@sparcs.kaist.ac.kr

Today’s Topic : Today’s Topic Let’s taste C++! Let’s feel Object Oriented Programming! Let’s look at Class !

What is C++? : What is C++? C++ = C + OOP + etc…. C++ is superset of C. Enable Object Oriented Programming Why C++? - for Java, for Windows Programming

Programming Paradigms : Programming Paradigms Sequential Programming - Fortran, BASIC Structured Programming - Algol, Pascal, C Object Oriented Programming - C++, Java

Object Oriented Programming (OOP) : Object Oriented Programming (OOP) for ‘Data’ rather than ‘Function’.. Encapsulation Polymorphism Inheritance

Encapsulation : Encapsulation Object = Data + Code Class = Variables + Functions Object is a kind of variable itself.

Polymorphism : Polymorphism Polymorphism mean ‘many forms’ from Greek. One Interface, Multiple Methods.. Function Overloading, Operator Overloading Ex) abs(), labs(), fabs() -> abs()

Inheritance : Inheritance One object acquire the properties of another. Hierarchical Classification Ex) CObject - CCmdTarget - CWnd - CDialog

Structure of Class : Structure of Class class class-name { // accessible by only inside of class private functions and variables of the class protected : // accessible by derived classes protected functions and variables of the class public : // accessible by outside of class public functions and variables of the class }

Example of Class : Example of Class class myclass { int a; public : void set_a(int num); int get_a(); } void myclass::set_a(int num) { a = num; } int myclass::get_a() { return a; }

Example of Class (continued) : Example of Class (continued) void main() { myclass ob1, ob2; ob1.a = 100; // Error !! ob1.set_a(10); ob2.set_a(99); cout << ob1.get_a() << “\n”; cout << ob2.get_a() << “\n”; }

Example of Function Overloading : Example of Function Overloading #include void date(char *date) { cout << “Date:” << date << “\n”; } void date(int month, int day, int year) { cout << “Date:” << month << “/” << day << “/” << year << “\n”; } main() { int month, day, year; date(“5/4/98”); date(5, 4, 98); cin >> month >> day >> year; date(month, day, year); }

Constructor and Destructor : Constructor and Destructor class myclass { int *a; public : myclass(); // constructor ~myclass(); // destructor set_a(int num); int get_a(); } myclass::myclass() { a = new int; } myclass::~myclass() { delete a; } void myclass::set_a(int num) { a = num; } int myclass::get_a() { return a; }

Constructor with Parameters : Constructor with Parameters #include class myclass { int a; public : myclass(int x); // constructor int get_a(); } myclass::myclass(int x) { a = x; } int myclass::get_a() { return a; } main() { myclass ob1; // Error !! myclass ob2(10); cout << ob2.get_a() << “\n”; }

2 Members Recommend this Teacher

Related Online Classes

Girish S.C
Overview of Design Patterns with C# Examples by Girish
Sun, November 15, 09 8:00 AM
(IST)
Soubhagya Mishra
Fundamental in "C" Part-2 by Soubhagya
Sat, May 16, 09 5:30 PM
(IST)
Soubhagya Mishra
C++ Fundamental (Re Scheduled) by Soubhagya
Fri, April 24, 09 7:00 PM
(IST)
Ekolama
Introduction to C# by Ekolama
Thu, September 10, 09 8:00 AM
(W. Central Africa Standard Time)
Soubhagya Mishra
C++ Fundamental Part - VI by Soubhagya
Fri, April 17, 09 5:30 PM
(IST)
Copyrights © 2009 authorGEN. All rights reserved.