Topics covered:

Introduction

A Simple C++ Program

Why C++?

History

Basic Concepts of C++

Standard Libraries

The ANSI Standard

Introduction

C++ is a high-level programming language developed by Bjarne Stroustrup at Bell Labs.

C++ adds object-oriented features to its predecessor C.

C++ is one of the most popular programming languages for graphical applications.

C++ is very similar to C.

C++ includes the following features in it:

A Simple C++ Program

Here is an example of running the program in C++.

Example:

#include<conio.h>

#include<iostream.h>

//main() is a function where program execution begins

int main()

{

clrscr();

cout<<"WAGmob on-the-go Learning and Reference\n";

getch();

return 0;

}

Output :

WAGmob on-the-go Learning and Reference

The above program shows:

The C++ language defines several headers, which contain information that is either necessary or useful to our program.

For the above program, the header <iostream.h> is needed.

The next line//main() is a function where program execution begins is a single-line comment available in C++.

Single-line comments begin with // and stop at the end of the line.

The line int main() represents that int is return type and main() is function name.

The next line cout<<"WAGmob on-the-go Learning Reference\n"; causes the message “WAGmob on-the-go Learning Reference" to be displayed on the screen.

The next line return 0; terminates main() function and causes it to return the value 0 to the calling process.

Why C++?

Almost as efficient as C and supports Object Oriented Programming.

Appropriate for many design methodologies.

Can be easily use by C programmers.

Extensive standard library.

Designed to scale well.

ANSI/ISO standard.

History

C++ was written by Bjarne Stroustrup at Bell Labs during 1983-1985.

C++ is an extension of C.

Prior to 1983, Bjarne Stroustrup added features to C and formed what he called "C with Classes."

He had combined the Simula's use of classes and object-oriented features with the power and efficiency of C.

The term C++ was first used in 1983.

Basic Concepts of C++

Class

A representation of objects and the sets of operations that can be applied to such objects.

Objects

Object is an instance of a class

An object has state, behavior and identity.

The structure and behavior of similar objects are defined in their common class.

The term instance and object are interchangeable.

Class consists of Data members and methods:

Class class_name

{

 Data Members;

 Member Function;

};

Primary purpose of a class is to hold data/information.

This is achieved with attributes which are also known as data members.

The Member Functions determine the behavior of the class i.e. provides
definitions for supporting various operations on the data held in the form of an object.

Object oriented features of C++

Inheritance

Inheritance is a mechanism of reusing and extending existing classes without modifying them, thus producing hierarchical relationships between them.

Abstraction

Abstraction refers to, providing only essential information to the outside word and hiding their background details.

Encapsulation

Encapsulation describes the ability of an object to hide its data and methods from the rest of the world.

Polymorphism

Polymorphism means that some code or operations or objects behave differently in different contexts.

Overloading is a 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.

Standard Libraries

Standard C++ consists of three important parts:

Variables

Data types

Literals

The C++ Standard Library gives a rich set of functions manipulating files, strings etc.

The Standard Template Library (STL) gives a rich set of methods manipulating data structures etc.

Variables:

A Variable is like a container that can hold certain content/values.

Data Types:

In computer science and computer programming, a data type or simply type is a classification identifying one of various types of data, such as real-valued, integer or boolean.

Literals:

Invariant program elements are called "literals" or "constants." The terms "literal" and "constant" are used interchangeably.

Literals fall into four major categories: integer, character, floating-point, and string literals.

The ANSI Standard

The ANSI standard is an attempt to ensure that C++ is portable.

The American National Standards Institute is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States.

The ANSI standard has been stable for a while, and all the major C++ compiler manufacturers support the ANSI standard.


Translate

CR Zaman. Powered by Blogger.

Recent Posts

Popular Posts