Rabu, 05 Oktober 2016

What is Object Composition in C++

Object Composition   In real-world programs an object is made up of several parts. For example a car is made up of several parts (objects) like engine, wheel, door etc. This kind of whole part relationship is known as composition which is also known as has-a relationship. Composition allows us to create separate class for each task. Following are the advantages or benefits of composition: Each class can be simple and straightforward. A class can focus on performing one specific task. Classes will be easier to write, debug, understand, and usable by other people. Lowers the overall complexity of the

The post What is Object Composition in C++ appeared first on Coding Security.


What is Object Composition in C++
read more

What is istream Class in C++

istream Class Functions   The istream class is derived from ios class. The istream class contains the following functions:   Formatted Console I/O   C++ provides various console I/O functions for formatted input and output. The three ways to display formatted input and output are:   ios class functions and flags Standard manipulators User-defined manipulators   ios Class   The ios class is the base class for all input and output classes in C++. Following are some of the functions available in ios class: The width() function can be used in two ways as shown below:   int width() : Returns the current width setting.   int width(int) : Sets the specified width

The post What is istream Class in C++ appeared first on Coding Security.


What is istream Class in C++
read more

Selasa, 04 Oktober 2016

Different ways of passing data to methods in C++

In C++ we have three ways for passing arguments to a function. They are: pass-by-value, pass-by-reference, and pass-by-address.   Pass-by-value Generally used way to pass arguments is pass-by-value. In this method, the arguments passed in the function call are copied to formal parameters in the function definition. So, any changes made to the formal parameters are not reflected on the actual parameters. Consider the following swap function which demonstrates pass-by-value: 1 2 3 4 5 6 void swap(int x, int y) { int temp = x; x = y; y = temp; }   Let’s assume that in the main() function we are writing the

The post Different ways of passing data to methods in C++ appeared first on Coding Security.


Different ways of passing data to methods in C++
read more

How to work with bit Field classes in C++

Bit Fields in Classes   A field or member inside a class which allows programmers to save memory are known as bit fields. As we know a integer variable occupies 32 bits (on a 32-bit machine). If we only want to store two values like 0 and 1, only one bit is sufficient. Remaining 31-bits are wasted. In order to reduce such wastage of memory, we can use bit fields. Syntax of a bit field is as follows: type-specifier declarator: width;   In the above syntax declarator is an identifier (bit-field name), type-specifier is the data type of the declarator and width is the size of

The post How to work with bit Field classes in C++ appeared first on Coding Security.


How to work with bit Field classes in C++
read more

How to overload unary operator in c++

Overloading Unary Operators Operators which work on a single operand are known as unary operators. Examples are: increment operator(++), decrement operator(–), unary minus operator(-), logical not operator(!) etc. Using a member function to overload an unary operator Following program demonstrates overloading unary minus operator using a member function: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include <iostream> using namespace std; class Number { private: int x; public: Number(int x) { this->x = x; } void operator

The post How to overload unary operator in c++ appeared first on Coding Security.


How to overload unary operator in c++
read more

Senin, 03 Oktober 2016

How to work with dynamic arrays and strings in C++

Dynamic Arrays Consider you are writing a program to store student records which are bound to increase over time. There is now way to assume the size of the array before hand. In such cases static arrays are a bad choice. Instead, use dynamic arrays.   Dynamic arrays can be created in C++ programs using vector class which is available in the header file vector. Since vector uses template syntax and they are not at discussed, let’s look at a program which demonstrates creating and using a vector: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

The post How to work with dynamic arrays and strings in C++ appeared first on Coding Security.


How to work with dynamic arrays and strings in C++
read more

what are manipulators in C++

  Manipulators   Manipulators are helper functions which can be used for formatting input and output data. The iosclass and iomanip.h header file has several pre-defined manipulators.   Below table lists out several pre-defined manipulators. The manipulators hex, oct, dec, ws, endl, and flush are defined in iostream.h. The manipulators setbase(), width(), fill(), etc., that require an argument are defined in iomanip.h. The width() function can be used in two ways as shown below:   int width() : Returns the current width setting.   int width(int) : Sets the specified width and returns the previous width setting.   The precision() function can be used in two ways as shown below:   int precision() : Returns the

The post what are manipulators in C++ appeared first on Coding Security.


what are manipulators in C++
read more