Introduction to C++ Programming Language - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Introduction to C++ Programming Language

Share This

A program is organized in one of two ways:

  • around its code (what is happening)
  • around its data (who is being affected)


In structured programming techniques, programs are typically organized around code ("code acting on data")


Object-oriented programming took the ideas of structured programming and combined them with several new concepts.


The principles of Object-Oriented Programming are discussed below:


Encapsulation


Encapsulation is the mechanism that binds code and data together. It keeps data safe from outside interference and misuse. The access to the code and data is managed by access specifiers.

Within an object, code, data, or both may be private to that object or public. Private code or data is accessible only within the object, they are not accessible by outside object. If code or data is public, other parts of the program may access it even though it is defined within an object.

Generally, the public parts of an object are used to provide a controlled interface to the private elements of the object.


Polymorphism


Polymorphism can be characterized by the phrase "one interface, multiple methods." Polymorphism allows one interface to control access to a general class of actions.


Inheritance


Inheritance is the process by which one object acquires the properties of another object(s). It supports hierarchical classification.


Let us try our first program which will print Hello World and will test the environment.


#include <iostream> using namespace std; int main(void){ cout << "Hello World!" << endl; return 0; }


Standard Input/Output


In the following program, we will show you, how to take input from a standard input device (i.e. keyboard) and how to print in a standard output device (i.e. monitor).

Note that, cout , cin and cerr are the objects of the standard output stream, standard input stream and standard error stream, respectively.

The cout object is used in conjunction with the stream insertion operator (<<) to display the output on the console.

The cin object is used in conjunction with the stream insertion operator (>>) to display the output on the console.


#include <iostream> using namespace std; int main(void){ int x, y, z; cout << "Enter the value of x: " << endl; cin >> x; cout << "Enter the value of y and z: " << endl; cin >> y >> z; cout << "The values are : " << x << " " << y << " " << z << endl; return 0; }


Happy Exploring!

No comments:

Post a Comment