We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20
Applications of C++
1. For Development of Graphical related applications like
computer and mobile games. 2. To evaluate any kind of mathematical equation use C++ language. 3. C++ Language are also used for design OS. Like window xp. 4. Google also use C++ for Indexing 5. Few parts of apple OS X are written in C++ programming language. 6. Internet browser Firefox are written in C++ programming language 7. All major applications of adobe systems are developed in C++ programming language. Like Photoshop, ImageReady, Illustrator and Adobe Premier. 8. Some of the Google applications are also written in C++, including Google file system and Google Chromium. 9. C++ are used for design database like MySQL. • Object • Class • Encapsulation • Abstraction • Inheritance • Polymorphism Encapsulation is a process of wrapping of data and methods in a single unit is called encapsulation. Abstraction Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context. Hiding of data is known as data abstraction. Inheritance The process of obtaining the data members and methods from one class to another class is known as inheritance. Polymorphism The process of representing one Form in multiple forms is known as Polymorphism. Here one form represent original form or original method always resides in base class and multiple forms represents overridden method which resides in derived classes. #include<iostream.h> #include<conio.h> class sum { // hidden data from outside world private: int a,b,c; public: void add() { clrscr(); cout<<"Enter any two numbers: "; cin>>a>>b; c=a+b; cout<<"Sum: "<<c; } }; void main() { sum s; s.add(); getch(); } Advantage of Encapsulation To secure the data from other methods Benefits of encapsulation
• Provides abstraction between an object and
its clients. • Protects an object from unwanted access by clients. • Example: A bank application forbids a client to change an Account's balance. Polymorphism in C++ • A Constructor is a special member method which will be called implicitly (automatically) whenever an object of class is created. #include<iostream.h> #include<conio.h> class sum { int a,b,c; sum() { a=10; b=20; c=a+b; cout<<"Sum: "<<c; } }; void main() { sum s; getch(); } Destructor Destructor is a member function which deletes an object. A destructor function is called automatically when the object goes out of scope: #include<iostream.h> #include<conio.h> class sum { int a,b,c; sum() { a=10; b=20; c=a+b; cout<<"Sum: "<<c; } ~sum() { cout<<"call destructor"; } delay(500); }; void main() { sum s; cout<<<<endl;"call main"; getch(); } Inline Function If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time. Why to use Inline function saving the register, pushing arguments, returning to calling function Eg #include<iostream.h> #include<conio.h> inline void show() { cout<<"Hello world"; } void main() { show(); // Call it like a normal function getch(); } Where inline function not work ?
• If inline function are recursive
• If function contain static variables. • If return statement are exits but not return any value. Function Overloading in C++
Different ways to overload the
method There are two ways to overload the method in C++ • By changing number of arguments or parameters • By changing the data type #include<iostream.h> #include<conio.h> class Addition { public: void sum(int a, int b) { cout<<a+b; } void sum(int a, int b, int c) { cout<<a+b+c; } }; void main() { clrscr(); Addition obj; obj.sum(10, 20); cout<<endl; obj.sum(10, 20, 30); } By changing the data type #include<iostream.h> #include<conio.h> class Addition { public: void sum(int a, int b) { cout<<a+b; } void sum(float a, float b) { cout<<a+b+c; } }; void main() { clrscr(); Addition obj; obj.sum(10, 20); cout<<endl; obj.sum(10, 20, 30); }