Travel the world

Climb the mountains

Post Page Advertisement [Top]

 

C++ PROGRAMMING LANGUAGE.


Hey guys, I am come with my new post about c++ programming. In the last post, I told you about basics of c programming. In this post, giving you information about C++.

C++ is just like c: in fact, it`s considered a superset of c. essentially, c++ is c with additional functionality.

C++ is an object oriented programming language supports data abstraction and supports generic programming.

C++ was introduced by Bjarne Stroustrup at bell labs in 1980 in Murray hi, new USA as an extension to the c language. In c++ adding new features that included virtual functions ,function name and operator overloading ,references ,constants, type- safe free - store memory allocation (new /delete ) ,improved type checking inheritance ,abstract classes ,static member factions ,protected members, later templates,exceptions,name space ,new casts , Booleans type features, and BCPL(basic combined programming language ) style single line comments with two forward slashes (//) .the motivation behind abject oriented programming is to try to see the whole world in the form of classes and objects.

Key word in C++ is predefined or reserved word in C++ library with fixed meaning and used to perform an internal operation C++ language supports more than 64 key words .every keyword exists in lower case ,const,continue ,int etc. you cannot use any keyword as variable name or identifier and cannot overload.

In OOP everything is represented as an object and when programs are executed ,the object interact with each other by passing message .an object need not know the implementation details of another object for communicating.



Special feature of object oriented program

ABSTRACTION

Abstraction the process of hiding irrelevant information from the user .using abstraction in programming, we can hide unnecessary details from the user. By using abstraction in our application, the end user is not affected even if we change the internal implementation.

ENCAPSULATION

The term simply grouping related data and functions together such as object and defining an interface to those objects. In object oriented programming, encapsulation is defined as binding together the data and the functions that manipulate them.

By doing this data is not easily accessible to the outside world; in OOP we achieve encapsulation by making data members as private and having public factions to access these data members.

INHERITANCE

Inheritance is one of the most important feature of object oriented programming this mechanism allowing  code to reused between related types i.e. derived new class from existing one .

When creating a class, instead of writing completely new data members and member functions the programmer can designate that the new class should inherit the members of an existing class the new class is referred to as the derived class .the main advantages of inheritance are code reusability and read ability.

POLYMORPHISM

Poly means many and morphism means forms, so it can refers many forms. Polymorphism is an important feature of OOP and is usually implemented as operator overloading or function overloading. This terms allowing a single value from one of several types and determining at runtime which functions to call on it based on its type .it is term that allow single name to be used for more than one related to be used for more than one related purpose ,which are technically not same.

It is the ability of one object to have may types .polymorphism means “many shapes”

 A real life example of polymorphism, a person at the same time can have different characteristics, like a same at the same time is a mother a wife an employee. So the same person posses different behavior in different situations. This is called polymorphism.


Why use C++ application

C++ is a versatile language for handling very large program.

C++program are easily maintainable.

C++ is an object oriented language which gibes a clear structure to program and allows code to be reused, lowering development cost.  

C++ is portable and can be used to develop applications that can be adapted to multiple platforms.

C++ can be found in today’s operating systems graphical user interfaces and embedded systems.

C++ is suitable for any program in task including development of editors, compiler,data base ,communications system and any complex real life application systems .

C++ allows us to create hierarchy related objects. We can build special object oriented library which can be used later by many programmer.

Data types  in C++

Data type is a keyword used to identify type of data. It is used for storing the input of the program into the main memory (RAM)of the computer by allocating amount of memory space in the main memory of the computer.

FUNDAMENTAL OR PRIMITIVE DATA TYPES

 Primitive data types are referred as built in data type .these are the data types. whose   variable can hold maximum one value at a time. The primitive types are the most basic building blocks for any programming language and are the base for more complex data types.

In C++ languages built in data types are,

1

Character

Keyword used for character data type is char. character type requires 1 bytes of memory space.

 

2

Integer

Keyword used for integer data types is int. integer typically requires 4 bytes of memory space.

 

3

Boolean

Stores either value true or false. Keyword used for Boolean data type is bool.

 

5

Floating point

Floating point data type is used for storing single precision floating pointy values or decimal value .float variables typically required 4 bytes of memory space.

 

6

Double floating point

Double float variables typically required 8 bytes of memory space.

 

7

Wide character

Wide character data type is also a character data type but this data type has size greater than the normal 8 bit data type. Represented by wchar_t. it is generally 2 or 4 bytes long.

 

8

Void

Void mean without any value .void data type is used for those functions which do not return value.

 

DERIVED DATA TYPES

These data type are derived from fundamental data type. Variable of derived data type, allow us to store multiple values of same type in one variable but never allows storing multiple values of different types .these are the data type whose variable can hold more than one value of similar type. Time complexity comes in case of derived data types as it mainly deals with manipulation and execution of logic over data that it stored.

·         Array

·         Function

·         Pointer

·         Reference

 

USER -DIFINED DATA TYPE

As the programming languages allow the user to create their own data types according to their needs. Hence, the data types that are defined by the user are known as user-defined data types. User defined data types related variables allows us to store multiple values either of same type or deferent type or both. This is a data type whose variable can hold more than one value of dissimilar type.

In C++ language user-defined data types can be developed by using

·         Structure

·         Union

·         Class

·         Enumeration

INSERTION OPERATOR (<<)

Insertion operator (<<) is also called output operator or put –to operator .it is means reads data from variable and send it on to the std output device that is VDU( visual display unit ) it is used with cout object for displaying variable or text .it is same as of printf() function used in C language.

Ex.

Cout<< “welcome to C++”;

EXTRACTION OPERATOR (>>)

Extraction operator (>>) is also called input operator or get from std input device and store at the given location by variable name. It is used with Cin object for reading into variables. It extract or gets the content of variable or string from the keyboard ,and assigned to variable on its right. This works same as scanf() works in C language.

EX.

Cin>>Y;

Where Y is a variable.

 

Manipulators in C++

Manipulators are operators used in C++ for formatting output. It’s are a function specifically designed to be used in conjunctions with the insertion and extraction operators on stream objects. The main advantage of using manipulator function is that they facilitate that formatting of input and output stream.

To carry out the operations of these manipulator functions in a user program, the header file input and output manipulator <iomanip.h> must be included.

endl manipulator

endl is the feed operator in C++. It acts as a stream manipulator whose purpose is to feed the whole line and then point the cursor to the beginning of the next line. We can use /n instead of endl for the same purpose.

Ex

#include<iomanip.h>

#include<iostream.h>

Void main()

{

Cout<<”a”<<endl<<”b”<<endl;

Cout<<”a=”<<a<<endl;

Cout<<”b=”<<b<<endl;

}

Output:

a

b

a=100

b=50

setw() manipulator

The setw () stands for the set width. The setw () manipulator is used to specify the minimum number of character positions on the output field a variable will consume.

EX

#include<iostream.h>

#include<iomanip.h>

Void main(viod)

{

            Int a,b;

            a=500;

            b=800;

            cout<<setw(5 ) <<a<<setw(5) <<b<<endl;

            cout<<setw(6) <<a<<setw(6) <<b<<endl;

            cout<<setw(7) <<a<<setw(7) <<b<<endl;

            cout<<setw(8) <<a<<setw(8) <<b<<endl;

}

Output:

500     800

  500      800

    500       800

      500       800

Setfill()  manipulator

Setfill() manipulator function is used to specify a different character to fill the unused field width of the value. If a value does not entirely fill a field, then the character specified in the argument of the manipulator is used for filling the fields.

Ex

#include<iostream.h>

#include<iomanip.h>

Void main()

{

            Int a,b;

            a=100;

            b=200;

            cout<<setfill(‘*’);

            cout<<setw(5) <<a<<setw(5) <<b<<endl;

            cout<<setw(6) <<a<<setw(5) <<b<<endl;

}

Output:

**100**200

***100***300

Setprecision () manipulator

The setprecision() is used to control the number of digits of an output steam display of a floating point value.

 



 

COPYRIGHT ©2020

#SAP PRODUCTION HOUSE

#COMPUTICSPLUS


No comments:

Post a Comment

Bottom Ad [Post Page]