Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Data Management

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

156 3 2

171 Share

Data Management
Business Intelligence Data Mining Data Modeling Data Warehousing

Learn Concepts
Application Development Client Server Cloud Computing Cluster Computing CRM Electronic Data Interchange ERP Neuro Linguistic Programming OOPS Concepts Programming Concepts Service Oriented Architecture Supply Chain Management Technology Trends UML Virtualization Web 2.0

Learn J2EE
Java JSP

Learn Microsoft
Analysis Services ASP.NET ASP.NET 2.0 C# MS Project Training

Silverlight SQL Server 2005 VB.NET 2005

Learn Networking
Networking Wireless

Learn Oracle
Oracle 10g Training Oracle 11g PL/SQL Tutorials Oracle 11g Training Oracle 9i Training Oracle Apps 11i

Learn Programming
Ajax C Language C++ Tutorials CSS CSS3 JavaScript jQuery MainFrame PHP VBScript XML

Software Testing
Software Testing Types SQA Tutorials Testing Articles Home Tutorials C++ Tutorials

Basic concepts of OOPS and Structure of C++ program


Author: Sripriya R Published on: 26th Jul 2006 | Last Updated on: 25th Jul 2011 In this tutorial you will learn about Objects, Classes, Inheritance, Data Abstraction, Data Encapsulation, Polymorphism, Overloading, and Reusability.

Before starting to learn C++ it is essential to have a basic knowledge of the concepts of Object oriented programming. Some of the important object oriented features are namely:

Ads

Objects Classes Inheritance Data Abstraction Data Encapsulation Polymorphism Overloading Reusability

In order to understand the basic concepts in C++, a programmer must have a good knowledge of the basic terminology in object-oriented programming. Below is a brief outline of the concepts of object-oriented programming languages :

Objects:
Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class. There can be more than one instance of a class. Each instance of a class can hold its own relevant data.

An Object is a collection of data members and associated member functions also known as methods.

Classes:
Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represents a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects become functions of the class and are referred to as Methods.

For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Color, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, and Stop form the Methods of Car Class.

No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.

Inheritance:
Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class. The new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in objectoriented programming.

Data Abstraction:
Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details.

Data Encapsulation:

Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible.

Polymorphism:
Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways.

Overloading:
Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an existing operator or function begins to operate on new data type, or class, it is understood to be overloaded.

Reusability:
This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

The implementation of each of the above object-oriented programming features for C++ will be highlighted in later sections.

A sample program to understand the basic structure of C++


Sample Code 1. 2. //program to read employee details and to output the data 3. 4. ////////// code begins here ///////////////////////////// 5. #include < iostream > // Preprocessor directive

6. using namespace std; 7. class employee // Class Declaration 8. { 9. private: 10. char empname[50]; 11. int empno; 12. 13. public: 14. void getvalue() 15. { 16. cout<<"INPUT Employee Name:"; 17. cin>>empname; // waiting input from the Keyboard for the name 18. cout<<"INPUT Employee Number:"; 19. cin>>empno; // waiting input from the Keyboard for the number 20. } 21. void displayvalue(){ 22. cout<<"Employee Name:"<< empname << endl; // displays the employee name 23. cout<<"Employee Number:"<< empno << endl; // displays the emloyee number 24. 25. } 26. }; 27. void main() 28. { 29. employee e1; // Creation of Object 30. e1.getvalue(); // the getvalue method is being called 31. e1.displayvalue(); // the displayvalue method is being called 32. } 33. 34. ///// code ends here ////////////// 35.
Copyright exforsys.com

Output:

Ads

A Overview of the Basic Structure of C++ Programming


The // in first line is used for representing comment in the program. The second line of the program has a # symbol which represents the preprocessor directive followed by header file to be included placed between < >. The next structure present in the program is the class definition. This starts with the keyword class followed by class name employee. Within the class are data and functions. The data defined in the class are generally private and functions are public. These explanations we will be detailed in later sections. The class declaration ends with a semicolon. main() function is present in all C++ programs. An object e1 is created in employee class. Using this e1 the functions present in the employee class are accessed and there by data are accessed. The input named ename and eno is received using the input statement named cin and the values are outputted using the output statement named cout.

You might also like