Kamis, 06 April 2017

What are the different ways to copy objects in c++

Frequently while programming there will be need to create a copy of an existing object. This can be done in three ways:   Shallow Copy   In this method the copy (object) only copies the addresses (for dynamic memory) of the source object’s members. This is similar with the semantics of static data members. A same copy is shared among several objects. Similarly, in shallow copy method, both the source and copied objects share the same memory location.   Deep Copy   In this method the copied object maintains a copy of the value of each source object’s data members.

The post What are the different ways to copy objects in c++ appeared first on Coding Security.


What are the different ways to copy objects in c++
read more

Rabu, 05 April 2017

How to create a constructors with Default Arguments

A constructor like a member function can have default arguments. The default arguments should be declared at the end of the parameters list. Following program demonstrates a constructor with default arguments: 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 32 33 34 35 36 37 38 39 #include <iostream> using namespace std; class Student { private: string name; string regdno; int age; string branch; int *marks; public: Student(string branch, int n = 4) //Constructor { marks =

The post How to create a constructors with Default Arguments appeared first on Coding Security.


How to create a constructors with Default Arguments
read more

How to use namespaces in C++ Programming

It is common in large programs or projects to create multiple files and declare variables, functions, classes, etc. with same names which results in collisions of names. In order to eliminate collisions, C++ introduced the concept of namespaces which is a logical space for creating names.   A namespace can be created using the keyword namespace and its syntax is as follows: 1 2 3 4 5 6 7 namespace  name { //declarations ... ... ... }   Essentially a namespace creates a scope of for all the elements inside it. Syntax for accessing an element outside the namespace is as

The post How to use namespaces in C++ Programming appeared first on Coding Security.


How to use namespaces in C++ Programming
read more

What are the standard pre-defined library functions in C Programming

A function is said to be a predefined function or library function, if they are already declared and defined by another developer. These predefined functions will be available in the library header files. So, if we want to use a predefined function, we have to include the respective header file in our program. For example, if we want to use printf function in our program, we have to include the stdio.h header file, as the function printf has been declared inside it. Some of the header files in C are: Some of the predefined functions available in ctype.h header file

The post What are the standard pre-defined library functions in C Programming appeared first on Coding Security.


What are the standard pre-defined library functions in C Programming
read more

Selasa, 04 April 2017

How do you overload a unary operator in programming

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 –() { x

The post How do you overload a unary operator in programming appeared first on Coding Security.


How do you overload a unary operator in programming
read more

How abstract keyword is used in programming

Creating abstract methods Sometimes while creating hierarchies, a method inside a super class might not be suitable to have any kind of implementation. Such methods can be declared as abstract using the abstract keyword. Syntax for creating an abstract method is as follows: abstract return-type method-name(parameters-list); As candidate example for abstract method let’s consider the Shape class from our previous article: 1 2 3 4 5 6 7 class Shape { void area() { System.out.println(“Area of shape”); } } In the above example there is really no need to give implementation for the area() method. Area of shape doesn’t mean anything without telling

The post How abstract keyword is used in programming appeared first on Coding Security.


How abstract keyword is used in programming
read more

Senin, 03 April 2017

An introduction to CSS Box Model

Every HTML element have an imaginary border around its content. The internal space between the content and the border of the element is known as padding and the external space between the border and another adjacent element is known as margin. This is known as the Box Model which is illustrated in the below figure:   Padding: Padding of an element can be specified using the shorthand property padding as shown below: p { padding: 10px; }  Above CSS rule specifies a padding of 10 pixels on all sides of the element. To specify padding only on individual sides we

The post An introduction to CSS Box Model appeared first on Coding Security.


An introduction to CSS Box Model
read more