Senin, 31 Oktober 2016

What is the difference between C and C++ programming languages

Let’s consider the following C++ program which prints “Hello World” on to the console or terminal window. We will look at various elements used in the program. 1 2 3 4 5 6 7 8 //C++ program to print “Hello World” #include <iostream> using namespace std; int main() { cout<<“Hello World”; return 0; } Output of the above code is: 1 Hello World   In the above program, iostream is the name of a header file which contains I/O functionality. In order to take input and print some output using our C++ program, we have to include that header file

The post What is the difference between C and C++ programming languages appeared first on Coding Security.


What is the difference between C and C++ programming languages
read more

What is formatted and unformatted data in C++

Data which is received by the program without any modifications and sent to the output device without any modifications is known as unformatted data. On the other hand, sometimes we may want to apply some modifications to the actual data that is being received or sent. For example, we might want to display an integer in hexadecimal format in the output, leave some whitespace when printing a number and adjustments in the decimal point. Such modified data in known as formatted data.   As an example for formatted data, if we want to display a decimal number in hexadecimal format,

The post What is formatted and unformatted data in C++ appeared first on Coding Security.


What is formatted and unformatted data in C++
read more

How to access object members in C++

After creating an object, we can access the data and functions using the dot operator as shown below: object-name.variable-name; (or) object-name.function-name(params-list);   Based on our student class example, we can access the get_details() function as shown below: std1.get_details(); std2.get_details();   The complete program which demonstrates creating class, creating objects, and accessing object members is as follows: 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 40 41 42 43 44

The post How to access object members in C++ appeared first on Coding Security.


How to access object members in C++
read more

Minggu, 30 Oktober 2016

Different types of constructors in Programming

A constructor can be classified into following types: Dummy constructor Default constructor Parameterized constructor Copy constructor Dynamic constructor   Dummy Constructor   When no constructors are declared explicitly in a C++ program, a dummy constructor is invoked which does nothing. So, data members of a class are not initialized and contains garbage values. Following program demonstrates a dummy constructor: 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 #include <iostream> using namespace std; class Student { private: string name; string regdno; int age;

The post Different types of constructors in Programming appeared first on Coding Security.


Different types of constructors in Programming
read more

How does sessions work in servlets

A session is a collection of HTTP requests, over a period of time, between a client and server. Maintaining the data within the session is known as session tracking. For example, maintaining the book details added to the cart in an online book shop application. Session tracking mechanisms include the following: URL rewriting (query strings) Hidden form fields Cookies HTTP session (Session objects)   URL Rewriting   In this method we keep track of the data by passing the data as a query string from one page to another page. A query string starts with ? symbol and is followed

The post How does sessions work in servlets appeared first on Coding Security.


How does sessions work in servlets
read more

How to perform event handling in javascript

The programming which allows computations based on the activities in a browser or by the activities performed by the user on the elements in a document is known as event-driven programming. An event is the specification (essentially an object created by the browser and JavaScript) of something significant has occurred. Examples of events are click, submit, keyup etc. In JavaScript all the event names are specified in lowercase. An event handler (essentially a function) is a set of statements (code) that handles the event. Below table lists most commonly used events and their associated tag attributes: Event Tag Attribute blur

The post How to perform event handling in javascript appeared first on Coding Security.


How to perform event handling in javascript
read more

Sabtu, 29 Oktober 2016

How to create and execute servlet manually

A servlet is a normal java class which follows these set of rules: Should be a public non-abstract class. Should be a subtype of servlet.Servlet interface or  HttpServlet  class. Should contain a zero or no argument constructor. The inherited methods from the Servlet interface should not be declared as final.   Following are the basic steps for creating and executing a servlet: Create a HTML page (optional) Create the Servlet file Create the web.xml (deployment descriptor) file Deploy the application   Creating a HTML Page   First thing we will do is create a HTML page called index.html with the

The post How to create and execute servlet manually appeared first on Coding Security.


How to create and execute servlet manually
read more

How to work with API of Java Servlet

Servlet API is a set of classes and interfaces that specify a contract between a servlet class and a servlet container. Some examples of servers that provide servlet containers are: Apache Tomcat, Oracle’s WebLogic, IBM’s Websphere, JBoss etc. All the API classes and interfaces are grouped into following packages: javax.servlet javax.servlet.http   javax.servlet Package   Provides a set of classes and interfaces that describe and defined the contract between the servlet class and the runtime environment provided by the servlet container. Following are the interfaces available in this package: Following are the classes available in this package: javax.servlet.Servlet Interface  

The post How to work with API of Java Servlet appeared first on Coding Security.


How to work with API of Java Servlet
read more

How to create nested classes in C++

C++ allows programmers to declare one class inside another class. Such classes are called nested classes. When a class B is declared inside class A, class B cannot access the members of class A. But class A can access the members of class B through an object of class B. Following are the properties of a nested class: A nested class is declared inside another class. The scope of inner class is restricted by the outer class. While declaring an object of inner class, the name of the inner class must be preceded by the outer class name and scope

The post How to create nested classes in C++ appeared first on Coding Security.


How to create nested classes in C++
read more

Jumat, 28 Oktober 2016

What is recursion in Programming

A function invoking itself is known as recursion. Recursion is an alternative to iteration. Recursion is very close to mathematical way of solving a given problem.   Advantages of recursion are, it is straight forward and easy. Disadvantage of recursion is, it occupies more memory on the stack when compared to iteration.   Note: Remember to write an exit condition while using recursion. If there is no exit condition, then the function will call itself infinitely.   Consider the following program which calculates the factorial of a number using recursion: 1 2 3 4 5 6 7 8 9 10

The post What is recursion in Programming appeared first on Coding Security.


What is recursion in Programming
read more

How to access the address of a variable in C programming using pointer

When an array is declared in a program, the compiler allocates a base address and sufficient amount of storage to contain all the elements of the array in contiguous (continuous) memory locations. The base address is the location of the first element (index 0) of the array. The compiler also defines the array name as a constant pointer to the first element. Suppose array x is declared as shown below: 1 int x = {1,2,3,4,5}; Suppose the array is allocated memory as shown below: The name x is defined as a constant pointer pointing to the first element, x and

The post How to access the address of a variable in C programming using pointer appeared first on Coding Security.


How to access the address of a variable in C programming using pointer
read more

Kamis, 27 Oktober 2016

How to handle multiple catch statements in c++

A try block can be associated with more than one catch block. Multiple catch statements can follow a try block to handle multiple exceptions. The first catch block that matches the exception type will execute and the control shifts to next statement after all the available catch blocks.   A try block should be followed by at least one catch block. If non catch block matches with the exception, then terminate() function will execute. Following program demonstrates handling multiple exceptions using multiple catch statements: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

The post How to handle multiple catch statements in c++ appeared first on Coding Security.


How to handle multiple catch statements in c++
read more

How to overload a unary operator in C++

When a friend function is used to overload an unary operator following points must be taken care of: The function will take one operand as a parameter. The operand will be an object of a class. The function can access the private members only though the object. The function may or may not return any value. The friend function will not have access to the this   Following program demonstrates overloading an unary operator using a friend function: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

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


How to overload a unary operator in C++
read more

How to allocate memory for classes and objects in C++

Class is not allocated any memory. This is partially true. The functions in a class are allocated memory which are shared by all the objects of a class. Only the data in a class is allocated memory when an object is created. Every object has its own memory for data (variables). For example consider the following Student class and its functions: 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 class Student { private: string name; string regdno; string

The post How to allocate memory for classes and objects in C++ appeared first on Coding Security.


How to allocate memory for classes and objects in C++
read more

Rabu, 26 Oktober 2016

How to organize a catalog in design patterns

Design patterns vary in their granularity and level of abstraction. As there are many design patterns, we can organize or classify patterns to learn them faster. Here we classify the patterns along two dimensions: one is purpose which reflects what a pattern does and the second one is scope which specifies whether the pattern applies to classes or objects. Along the purpose dimension, patterns are classified into three types: 1) Creational patterns 2) Structural patterns and 3) Behavioral patterns. The creational patterns focus on the process of object creation. The structural patterns concern is, the structure of classes and objects

The post How to organize a catalog in design patterns appeared first on Coding Security.


How to organize a catalog in design patterns
read more

How to redirect users using java servlets

In a web application it is common to redirect the user to a web page. For example on successful authentication of a user, he/she is redirected to user home page. Otherwise, redirected to login page again. We have to ways to redirect a user: one is using the sendRedirect() method available onresponse object and the second way is to use the forward() method available in RequestDispatcherinterface.   sendRedirect() is executed on client side, whereas forward() is executed on server side.sendRedirect() works only with HTTP, whereas forward() works with any protocol. sendRedirect()takes two request and one response to complete, where as

The post How to redirect users using java servlets appeared first on Coding Security.


How to redirect users using java servlets
read more

How to find unique element in the array(log (n) Runtime)

Exclusive or or Exclusive disjunction is a logical operation that outputs true only when inputs differ (one is true, the other is false). It is symbolized by the prefix operator J and by the infix operators XOR , EOR, EXOR,  ⊕,  and ≢. The negation of XOR is logical biconditional, which outputs true only when both inputs are the same. It gains the name “exclusive or” because the meaning of “or” is ambiguous when both operands are true; the exclusive or operator excludes that case. This is sometimes thought of as “one or the other but not both”. This could

The post How to find unique element in the array(log (n) Runtime) appeared first on Coding Security.


How to find unique element in the array(log (n) Runtime)
read more

Selasa, 25 Oktober 2016

How to initialize parameters in servlets in java

Most of the time, data (Ex: admin email, database username and password, user roles etc…) need to be provided in the production mode (client choice). Initialization parameters can reduce the complexity and maintenance. Initialization parameters are specified in the web.xml file as follows: 1 2 3 4 5 6 7 8 <servlet> <servlet-name>Name of servlet</servlet-name> <servlet-class>Servlet class</servlet-class> <init-param> <param-name>Mail</param-name> <param-value>admin@company.com</param-value> </init-param> </servlet>   Initialization parameters are stored as key value pairs. They are included in web.xml file inside init-param tags. The key is specified using theparam-name tags and value is specified using the param-value tags.   Servlet initialization parameters are

The post How to initialize parameters in servlets in java appeared first on Coding Security.


How to initialize parameters in servlets in java
read more

How to work with class diagrams in UML

To learn class diagrams, you must know about the concepts of classes,advanced classes, relationships and advanced relationships. Now, let’s start learning about class diagrams in UML: Class diagrams are most commonly found diagrams while modeling software systems. A class diagram consists of classes, collaborations and interfaces. A class diagram is used to model the static design view of the system. Common Properties                 The class diagram shares the common properties with the rest of the diagrams, a name and graphical elements that are a projection into the model. What distinguish the class diagram from the others are the contents of

The post How to work with class diagrams in UML appeared first on Coding Security.


How to work with class diagrams in UML
read more

How events and signals are configured in UML

Introduction In state machines (sequence of states), we use events to model the occurrence of a stimulus that can trigger an object to move from one state to another state. Events may include signals, calls, the passage of time or a change in state. In UML, each thing that happens is modeled as an event. An event is the specification of a significant occurrence that has a location in time and space. A signal, passing of time and change in state are asynchronous events. Calls are generally synchronous events, representing invocation of an operation. UML allows us to represent events

The post How events and signals are configured in UML appeared first on Coding Security.


How events and signals are configured in UML
read more

Senin, 24 Oktober 2016

How input and output methods work in javascript

Input and Output in JavaScript JavaScript models the HTML/XHTML document as the document object and the browser window which displays the HTML/XHTML document as the window object. The document object contains a method named write to output text and data on to the document as shown below: document.write(“Welcome to JavaScript”); To display multiple lines of text using the write method, include the HTML tag <br /> as a part of the string parameter as shown below: document.write(“Welcome<br />to<br />JavaScript”); The output of the above code on the document will be as shown below: Welcome to JavaScript Although the document object

The post How input and output methods work in javascript appeared first on Coding Security.


How input and output methods work in javascript
read more

What is written inside Head tag in HTML by developers

Now, let’s see what elements fit into the head section of a HTML document (web page). <title> Tag The <head> element of a HTML document contains various other elements. Among them the titletag (<title>) is used to assign a title to the HTML document (web page). For example, to display the title of the web page as Homepage, the title tags are used as follows: <title>Homepage</title>  The title of the web page is displayed on the titlebar of a browser. The title of a web page is also used in various other places like: it is used as the title

The post What is written inside Head tag in HTML by developers appeared first on Coding Security.


What is written inside Head tag in HTML by developers
read more

How to define a life cycle of a java servlet

Life cycle of a servlet contains the following stages: Instantiation Initialization Servicing Destruction   Following figure illustrates the life cycle of a servlet: Instantiation   In this stage the servlet container searches the web.xml file for servlet. If the servlet is found, it will create an object for the corresponding servlet class in the memory. Servlet container can search for the servlet file in the local disk (in server) or in a remote location.   Initialization   After instantiation of the servlet, the servlet container initializes the servlet object. Servlet container invokes the init(ServletConfig) method on the servlet object. This

The post How to define a life cycle of a java servlet appeared first on Coding Security.


How to define a life cycle of a java servlet
read more

Minggu, 23 Oktober 2016

How to display characters, lines and words in file using java

In computer programming, standard streams are preconnected input and output communication channels between a computer program and its environment when it begins execution. The three I/O connections are called standard input(stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connectedsystem console (input via keyboard, output via monitor), but standard streams abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection, e.g. via a pipeline. More generally, a child process will inherit the standard

The post How to display characters, lines and words in file using java appeared first on Coding Security.


How to display characters, lines and words in file using java
read more

A Brief demonstration struct and union in C programming

A struct in the C programming language (and many derivatives) is a complex data type declaration that defines a physically grouped list of variables to be placed under one name in a block of memory, allowing the different variables to be accessed via a single pointer, or the struct declared name which returns the same address. The struct can contain many other complex and simple data types in an association, so is a natural organizing type for records like the mixed data types in lists of directory entries reading a hard drive (file length, name, extension, physical (cylinder, disk, head

The post A Brief demonstration struct and union in C programming appeared first on Coding Security.


A Brief demonstration struct and union in C programming
read more

How to check validity of expression using recursive decent parser

Parsing or syntactic analysis is the process of analysing a string of symbols, either in natural language or in computer languages, conforming to the rules of a formal grammar. The term parsing comes from Latin pars (orationis), meaning part (of speech). The term has slightly different meanings in different branches of linguistics and computer science. Traditional sentence parsing is often performed as a method of understanding the exact meaning of a sentence or word, sometimes with the aid of devices such as sentence diagrams. It usually emphasizes the importance of grammatical divisions such as subject and predicate. Within computational linguistics

The post How to check validity of expression using recursive decent parser appeared first on Coding Security.


How to check validity of expression using recursive decent parser
read more

Sabtu, 22 Oktober 2016

How to handle errors and I/O operations in C programming

While writing programs which involve accessing files, certain errors might occur while performing I/O operations on a file. Some of the error situations include the following: Trying to read beyond the end-of-file mark. Device overflow. Trying to use a file that has not been opened. Trying to perform an operation on a file, when the file is being use by another application. Opening a file with invalid name. Attempting to write to write-protected file. If such errors are unchecked, it may lead to abnormal termination of the program or may lead to incorrect output. C library provides two functions namely

The post How to handle errors and I/O operations in C programming appeared first on Coding Security.


How to handle errors and I/O operations in C programming
read more

What is structure initialization and array of structures

Like any other data type, a structure variable can be initialized at compile time. An example of compile time initialization of the student structure is shown below: 1 2 3 4 5 6 7 8 9 struct student { char name; char rollno; int age; char grade; }; struct student student1 = {“teja”,”10A1”,26,’A’}; struct student student2 = {“raju”,”10A2”,24,’B’}; In the above example: teja, 10A1, 26 and A are assigned to student1’s name, rollno, age and grade. Whereas raju, 10A2, 24, B are assigned to student2’s name, rollno, age and grade. Note: Partial initialization of a structure variable is supported. For

The post What is structure initialization and array of structures appeared first on Coding Security.


What is structure initialization and array of structures
read more

How to print different patterns in Programming

The C Program to Print the Following Pattern Enter a value: 1 Enter n: 4 1 2*2 3*3*3 4*4*4*4 4*4*4*4 3*3*3 2*2 1 Code : #include "stdio.h" #include "conio.h" int main() { int val; int n; printf("Enter a value: "); scanf("%d", &amp;val); printf("Enter n: "); scanf("%d", &amp;n); for(int i = 1; i &lt;= n; i++) { for(int j = 1; j &lt;= i; j++) { if(j == i) printf("%d", val); else printf("%d*", val); } val++; printf("\n"); } val--; for(int i = 1; i &lt;= n; i++) { for(int j = n; j &gt;= i; j--) { if(j == i) printf("%d",

The post How to print different patterns in Programming appeared first on Coding Security.


How to print different patterns in Programming
read more

Jumat, 21 Oktober 2016

Here are the basics of Exception Handling

Handling synchronous exceptions is known as exception handling. Exception handling deals with detecting run-time exceptions and reporting it to the user for taking appropriate action. C++ provides try, catch, and throw elements for handling exceptions.   A try block contains code which might raise exceptions. Syntax of try block is as follows: 1 2 3 4 5 try { //Code ... }   A catch block contains code for handling exceptions that may raise in the try block. Syntax of catch block is as follows: 1 2 3 4 5 catch(Exception–type) { //Code to handle exception ... }   The

The post Here are the basics of Exception Handling appeared first on Coding Security.


Here are the basics of Exception Handling
read more

What are the Header Files and libraries in C++

A C++ program can contain several parts or sections as shown below: All sections except the main() function section are optional. Every C++ program must contain a main() function section. Classes in C++ are similar to structures in C. Classes in C++ can contain both variables and functions, where as it is not possible with structures in C. Functions can be defined inside and outside classes in C++.   Include Files Section A C++ program might include one or more header files using the #include directive. The syntax for including header files is given below:   #include<stdio.h> #include “stdio.h”

The post What are the Header Files and libraries in C++ appeared first on Coding Security.


What are the Header Files and libraries in C++
read more

How to access Members of an Object in C++

After creating an object, we can access the data and functions using the dot operator as shown below: object-name.variable-name; (or) object-name.function-name(params-list);   Based on our student class example, we can access the get_details() function as shown below: std1.get_details(); std2.get_details();   The complete program which demonstrates creating class, creating objects, and accessing object members is as follows: 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 40 41 42 43 44

The post How to access Members of an Object in C++ appeared first on Coding Security.


How to access Members of an Object in C++
read more

Kamis, 20 Oktober 2016

How to create and execute a servlet manually

Here we will learn how to create and execute a servlet manually i.e., without using any IDEs. For developing web applications using servlets you need a application server like Apache Tomcat, and a text editor like notepad. A servlet is a normal java class which follows these set of rules: Should be a public non-abstract class. Should be a subtype of servlet.Servlet interface or  HttpServlet  class. Should contain a zero or no argument constructor. The inherited methods from the Servlet interface should not be declared as final.   Following are the basic steps for creating and executing a servlet: Create

The post How to create and execute a servlet manually appeared first on Coding Security.


How to create and execute a servlet manually
read more

How to work with frames in HTML

Frames are popular in the olden days. There are used in almost all the web pages. The frameset structure provides an easy way to create multiple, separate scrolling areas in a user agent window and a flexible mechanism to modify the contents of a frame. However, there are some disadvantages of using frames. Due to this frames are deprecated. Although frames are supported in HTML 4.01, they are deprecated in HTML 5. Frames are replaced with the more powerful and flexible CSS formatting methods. Following are some of the disadvantages of frames: Frames are not search engine friendly. Frames are

The post How to work with frames in HTML appeared first on Coding Security.


How to work with frames in HTML
read more

How to work with methods in PHP

A function is a part of program which contains set of statements that can perform a desired task. A function can be defined with the function keyword followed by the function name and an optional set of parameters enclosed in parentheses. A function definition may not occur before a function call. It can be anywhere in the script. Although function definitions can be nested, it is not encouraged as they can make the script complex. Syntax for defining a function is given below: 1 2 3 4 5 function  function_name() {     //Body of the function      } The

The post How to work with methods in PHP appeared first on Coding Security.


How to work with methods in PHP
read more

Rabu, 19 Oktober 2016

How to work with swing operations in java

In this article we will look at some of the swing controls available in javax.swing package along with sample Java code for each control.   Labels The JLabel class is used to display a label i.e., static text. A JLabel object can be created using any one of the following constructors: JLabel(Icon icon) JLabel(String str) JLabel(String str, Icon icon, int align) In the above constructors icon is used to specify an image to be displayed as a label. Icon is a predefined interface which is implemented by the ImageIcon class. str is used to specify the text to be displayed in the label and align

The post How to work with swing operations in java appeared first on Coding Security.


How to work with swing operations in java
read more

How to perform synchronization in java

In this article we will learn about what is synchronization? why synchronization is needed? and how to synchronize threads in Java along with sample programs.   Why Synchronization is Needed? When two or more threads are accessing the same resource like a variable or a data structure, it may lead to inconsistent data or values. Such conditions that lead to inconsistency are known as race conditions.   As an example let’s consider a variable count whose value is 7 at present. Consider two operations: count = count + 1 which is executed by thread1 and another operation count = count – 1which is executed by

The post How to perform synchronization in java appeared first on Coding Security.


How to perform synchronization in java
read more

How to handle packages in java

In this article we will look at Java packages which are a way to create namespaces. We will learn how to create a package and how to access Java packages.   Package Definition A package is a group of related classes. A package is used to restrict access to a class and to create namespaces. If all reasonable class names are already used, then we can create a new package (new namespace) and reuse the class names again. For example a package mypackage1can contain a class named MyClass and another package mypackage2 can also contain a class named MyClass.   Defining or Creating a Package

The post How to handle packages in java appeared first on Coding Security.


How to handle packages in java
read more

Selasa, 18 Oktober 2016

How to create constant objects

When there is a need to create a read-only object, the object can be declared as a constant object using the const keyword. Syntax for creating a constant object is as follows:   ClassName const object_name(params-list);   Following are the characteristics of a constant object: Constant object can be initialized only through a constructor. Data members of a constant object cannot be modified by any member function. Constant object are read-only objects. Constant objects should be accessed only through constant member functions.   Following program demonstrates a constant object: 1 2 3 4 5 6 7 8 9 10 11

The post How to create constant objects appeared first on Coding Security.


How to create constant objects
read more

How to manipulate file using pointers

Every file will contain two pointers: a read pointer or also known as a get pointer and a write pointer also known as a put pointer. The read pointer or a get pointer is used to read data and the write pointer or put pointer is used to write data to a file. These pointers can be manipulated using the functions from stream classes. Those functions are as follows: The seekg() and seekp() functions specified above can be used to move the pointers in the file for random access. The syntax of these functions is as follows: seekg(int offset, reference_position)

The post How to manipulate file using pointers appeared first on Coding Security.


How to manipulate file using pointers
read more

How to throw exception of the class type

Instead of throwing exceptions of pre-defined types like int, float, char, etc., we can create classes and throw those class types as exceptions. Empty classes are particularly useful in exception handling. Following program demonstrates throwing class types as exceptions: 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 #include<iostream> using namespace std; class ZeroError {}; void sum() { int a, b; cout<<“Enter a and b values: “; cin>>a>>b; if(a==0 || b==0) throw ZeroError(); else cout<<“Sum is: “<<(a+b); } int main()

The post How to throw exception of the class type appeared first on Coding Security.


How to throw exception of the class type
read more

Senin, 17 Oktober 2016

What is the need for the design patterns

Design of object oriented software is hard: People who are familiar with object oriented software development are familiar with the fact that designing reusable object oriented software is very hard. So, what will make the development of reusable software easier? Experienced Vs novice designers: The experienced designers use their knowledge they had gained from their experience in designing object oriented software. The novice designers who have no experience in designing are left with numerous ways to develop the designs which may lead them to develop ineffective designs. The experienced designers have documented their experience as design patterns. These design patterns

The post What is the need for the design patterns appeared first on Coding Security.


What is the need for the design patterns
read more

What is abstract design pattern in design pattern

Intent: Abstract factory provides an interface to create a family of related objects, without explicitly specifying their concrete classes.   Also Known As: Kit.   Motivation: Modularization is a big issue in today’s programming. Programmers are trying to avoid the idea of adding more code to the existing classes to encapsulate more general information. Let’s consider an example of user interface toolkit which supports multiple look-and-feel standards such as Motif and Presentation Manager. Different look-and-feels define different appearances and behaviors for user interface widgets like scrollbars, buttons, radio buttons etc… To be portable across different look-and-feels standards, an application should

The post What is abstract design pattern in design pattern appeared first on Coding Security.


What is abstract design pattern in design pattern
read more

What is singleton pattern in design patterns

Intent: To create exactly one object of a class, and to provide global point of access to it.   Motivation: While developing applications, we will face frequent situations where there is a need to create exactly one instance of a class. For example, in a GUI application there is a requirement that there should be only one active instance of the application’s user interface. No other instance of the user interface of the application should be created by the user. Another example is the requirement to maintain only one print spooler. We need to allow the class to have exactly

The post What is singleton pattern in design patterns appeared first on Coding Security.


What is singleton pattern in design patterns
read more

Minggu, 16 Oktober 2016

What is the best catalog of design pattern

The catalog of GOF (Gang-of-Four) patterns contains 23 design patterns. They are listed below:   Abstract Factory: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.   Adapter: Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.   Bridge: Decouple (separate) the abstraction from its implementation so that the two can vary independently.   Builder: Separate (hide) the construction process from its representation so that the same construction process can create different representations.   Chain of Responsibility: Avoid coupling the sender of a request to its receiver by giving more

The post What is the best catalog of design pattern appeared first on Coding Security.


What is the best catalog of design pattern
read more

How to describe design patterns

The information in a design pattern’s documentation will be described as follows: Pattern name and classification: The pattern name specifies the essence of the pattern precisely. A good name is a key as it will become a part of our design vocabulary. Classification specifies the type of pattern.   Intent: A short statement that tells us what the pattern does and which design issue or problem the pattern addresses.   Also known as: Other well known names for the pattern, if any.   Motivation: A scenario that illustrates a design problem and how the class and object structures solve that

The post How to describe design patterns appeared first on Coding Security.


How to describe design patterns
read more

What is builder pattern in Design patterns

Intent: Separate the construction of a complex object from its representation so that the same construction process can create different representations.   Motivation: A RTF (Rich Text Format) reader application should be able to convert a RTF document to several formats like: plain text or TeX representation or into a text widget which allows users to directly interact. The problem here is, the number of possible conversions is open ended. So, it should be easy to add a new conversion without modifying the reader. A solution to this problem is, the RTFReader class uses a TextConverter object that converts RTF

The post What is builder pattern in Design patterns appeared first on Coding Security.


What is builder pattern in Design patterns
read more

Sabtu, 15 Oktober 2016

How to select best design pattern

As there are 23 patterns in the catalog it will be difficult to choose a design pattern. It might become hard to find the design pattern that solves our problem, especially if the catalog is new and unfamiliar to you. Below is a list of approaches we can use to choose the appropriate design pattern:   Consider how design patterns solve design problems: Considering how design patterns help you find appropriate objects, determine object granularity, specify object interfaces and several other ways in which design patterns solve the problems will let you choose the appropriate design pattern.   Scan intent

The post How to select best design pattern appeared first on Coding Security.


How to select best design pattern
read more

What is prototype pattern?

To specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.   Motivation: A prototype is a template of any object before the actual object is constructed. In java also, it holds the same meaning. Prototype design pattern is used in scenarios where application needs to create a number of instances of a class, which has almost same state or differs very little. In this design pattern, an instance of actual object (i.e. prototype) is created on starting, and thereafter whenever a new instance is required, this prototype is cloned to

The post What is prototype pattern? appeared first on Coding Security.


What is prototype pattern?
read more

How to design pattern using smalltalk in MVC

The Model/View/Controller set of classes are used to build user interfaces in Smalltalk-80. MVC consists of three kinds of objects. Model is the application object. View is the representation of the model and the Controller specifies how the user interface (View) reacts to the user input. Before MVC, these three objects (Model, View and Controller) used to be coupled together. MVC decouples model and view objects using the subscribe/notify protocol. Whenever the data in the model changes, it has to notify the associated views. In response, each view gets a chance to update itself. This allows add or create views

The post How to design pattern using smalltalk in MVC appeared first on Coding Security.


How to design pattern using smalltalk in MVC
read more

Jumat, 14 Oktober 2016

How to handle every mouse event in java

Event notification is a term used in conjunction with communications software for linking applications that generate smallmessages (the “events”) to applications that monitor the associated conditions and may take actions triggered by events. Event notification is an important feature in modern database systems (used to inform applications when conditions they are watching for have occurred), modern operating systems (used to inform applications when they should take some action, such as refreshing a window), and modern distributed systems, where the producer of an event might be on a different machine than the consumer, or consumers. Event notification platforms are normally designed

The post How to handle every mouse event in java appeared first on Coding Security.


How to handle every mouse event in java
read more

How to reverse an array in-place using pointers

A pointer is a value that designates the address (i.e., the location in memory), of some value. Pointers are variables that hold a memory location. There are four fundamental things you need to know about pointers: How to declare them (with the address operator ‘&‘: int *pointer = &variable;) How to assign to them (pointer = NULL;) How to reference the value to which the pointer points (known as dereferencing, by using the dereferencing operator ‘*‘: value = *pointer;) How they relate to arrays (the vast majority of arrays in C are simple lists, also called “1 dimensional arrays”). Pointers

The post How to reverse an array in-place using pointers appeared first on Coding Security.


How to reverse an array in-place using pointers
read more

How to use the union keyword in C programming

In computer science, a union is a value that may have any of several representations or formats; or it is a data structurethat consists of a variable that may hold such a value. Some programming languages support special data types, calledunion types, to describe such values and variables. In other words, a union type definition will specify which of a number of permitted primitive types may be stored in its instances, e.g., “float or long integer”. Contrast with a record (or structure), which could be defined to contain a float and an integer; in a union, there is only one

The post How to use the union keyword in C programming appeared first on Coding Security.


How to use the union keyword in C programming
read more

Kamis, 13 Oktober 2016

How to return objects in functions (C++ Programming)

We can not only pass objects as function arguments but can also return objects from functions. We can return an object in the following three ways: Returning by value which makes a duplicate copy of the local object. Returning by using a reference to the object. In this way the address of the object is passed implicitly to the calling function. Returning by using the ‘this pointer’ which explicitly sends the address of the object to the calling function.   Following program demonstrates the three ways of returning objects from a function: 1 2 3 4 5 6 7 8

The post How to return objects in functions (C++ Programming) appeared first on Coding Security.


How to return objects in functions (C++ Programming)
read more

How to work with control statements in C programming

In C, until so far, in all the programs, the control is flowing from one instruction to next instruction. Such flow of control from one instruction to next instruction is known as sequential flow of control. But, in most of the C programs, while writing the logic, the programmer might want to skip some instructions or repeat a set of instructions again and again. This is can be called as non-sequential flow of control. The statements in C, which allows the programmers to make such decisions, are known as decision making statements or control statements. In C, there are two

The post How to work with control statements in C programming appeared first on Coding Security.


How to work with control statements in C programming
read more

How to use delegation event model in java

In this article we will learn about using delegation event model i.e., how to implement event handling in Java programs.   Following are the basic steps in using delegation event model or for handling events in a Java program: Implement the appropriate listener interface. Register the listener with the source. Provide appropriate event handler to handle the event raised on the source.   Key Events Handling Following is a Java program which handles key events. In the program when the user types characters in the text field, they are displayed in a label below the text field. 1 2 3

The post How to use delegation event model in java appeared first on Coding Security.


How to use delegation event model in java
read more

Rabu, 12 Oktober 2016

How to create dynamic arrays and strings in c++

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

The post How to create dynamic arrays and strings in c++ appeared first on Coding Security.


How to create dynamic arrays and strings in c++
read more

What is explicit invocation in constructors

Explicit Invocation   Constructors and destructors can be invoked (called) explicitly from the main() function. A constructor can be invoked as shown below:   ClassName(params-list );   For example, constructor of Student class can be called as shown below:   Student( );   In case of a destructor, we need to write the class name along with the destructor name as follows:   object_name.ClassName::~ClassName( );   or   object_name.~ClassName( );   For example, destructor of Student class can be called as follows:   s1.~Student( );   A destructor can be called from a constructor as follows: 1 2 3 4

The post What is explicit invocation in constructors appeared first on Coding Security.


What is explicit invocation in constructors
read more

What are the advantages and disadvantages of inheritance

Advantages of inheritance are as follows: Inheritance promotes reusability. When a class inherits or derives another class, it can access all the functionality of inherited class. Reusability enhanced reliability. The base class code will be already tested and debugged. As the existing code is reused, it leads to less development and maintenance costs. Inheritance makes the sub classes follow a standard interface. Inheritance helps to reduce code redundancy and supports code extensibility. Inheritance facilitates creation of class libraries.   Disadvantages of inheritance are as follows: Inherited functions work slower than normal function as there is indirection. Improper use of inheritance

The post What are the advantages and disadvantages of inheritance appeared first on Coding Security.


What are the advantages and disadvantages of inheritance
read more

Selasa, 11 Oktober 2016

How to test your program in java using assert

Definition: An assertion is a condition that should be true during the program execution. They are generally used to detect errors (testing) during development of software. They have no use after the code is released to the users. They encourage defensive programming.   Creating and Using Assertions: Assertions can be created using the assert keyword. The general form of using assert keyword is as follows: assert condition; When the given condition becomes false, AssertionError is thrown by the Java run-time. The second form of assert is as follows: assert condition : expr; In the above syntax, expr can be any non-void value which will be passed on to the constructor of AssertionError and will be displayed as

The post How to test your program in java using assert appeared first on Coding Security.


How to test your program in java using assert
read more

How to use struct and arrays in c programming

We know that arrays can be used to represent a collection of elements of the same data type like int, float etc. They cannot be used to hold a collection of different types of elements. C supports a structured data type known as a structure, a way for packing data of different data types. Astructure is a convenient tool for handling a group of logically related data items. For example, it can be used to represent the details of a student or the details of a text book etc. Definition: A structure is a collection of heterogeneous data elements referred by the same

The post How to use struct and arrays in c programming appeared first on Coding Security.


How to use struct and arrays in c programming
read more

How to catch every exception in a program

While writing programs if the programmer doesn’t know what kind of exception the program might raise, the catch all block can be used. It is used to catch any kind of exception. Syntax of catch all block is as follows: 1 2 3 4 5 catch(...) { //Code to handle exception ... }     While writing multiple catch statements care should be taken such that a catch all block should be written as a last block in the catch block sequence. If it is written first in the sequence, other catch blocks will never be executed. Following program demonstrates

The post How to catch every exception in a program appeared first on Coding Security.


How to catch every exception in a program
read more

Senin, 10 Oktober 2016

A brief understanding of pointers in C

The computer’s memory is a sequential collection of storage cells. Each cell, commonly known as a byte, has a number called address associated with it. Typically, the addresses are numbered consecutively, starting from zero. The last address depends on the memory size. A computer system having 64k memory will have its last address as 65,535. Whenever we declare a variable in our programs, the system allocates somewhere in the memory, an appropriate location to hold the value of the variable. This location will have its own address number. Consider the following example: The above statement int var creates a location in the memory to

The post A brief understanding of pointers in C appeared first on Coding Security.


A brief understanding of pointers in C
read more

what are constant parameter member functions

Constant Member Functions Member functions in a class can be declared as constant if that member function has no necessity of modifying any data members. A member function can be declared as constant as follows: 1 2 3 4 return–type function–name(params–list) const { //body of function }   Following program demonstrates the use of constant member functions: 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 #include<iostream> using namespace std; class

The post what are constant parameter member functions appeared first on Coding Security.


what are constant parameter member functions
read more

How to throw exceptions of object type

Instead of throwing exceptions of pre-defined types like int, float, char, etc., we can create classes and throw those class types as exceptions. Empty classes are particularly useful in exception handling. Following program demonstrates throwing class types as exceptions: 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 #include<iostream> using namespace std; class ZeroError {}; void sum() { int a, b; cout<<“Enter a and b values: “; cin>>a>>b; if(a==0 || b==0) throw ZeroError(); else cout<<“Sum is: “<<(a+b); } int main() { try

The post How to throw exceptions of object type appeared first on Coding Security.


How to throw exceptions of object type
read more

Minggu, 09 Oktober 2016

How to work with exceptions and inheritance in c++

Exception Handling and Inheritance   In inheritance, while throwing exceptions of derived classes, care should be taken that catch blocks with base type should be written after the catch block with derived type. Otherwise, the catch block with base type catches the exceptions of derived class types too. Consider the following example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include<iostream> using namespace std; class Base {}; class Derived : public Base {}; int main() { try { throw Derived(); } catch(Base b) {

The post How to work with exceptions and inheritance in c++ appeared first on Coding Security.


How to work with exceptions and inheritance in c++
read more

What are different file modes in c++

Until now when using the constructor or open() function for reading or writing data to a file, we are passing only one argument i.e., the file name. We can also pass a second argument which specifies the file mode. The mode parameter specifies the mode in which the file has to be opened. We can specify one of the following modes available in ios file: A programmer can open a file in append mode by writing as follows: fstream object-name(“filename”, ios::app);   A programmer can combine multiple modes using the | symbol as follows: fstream object-name(“filename”, ios::out | ios::nocreate);   File Pointers and Manipulation

The post What are different file modes in c++ appeared first on Coding Security.


What are different file modes in c++
read more

How to read and write data in files in C++

After opening a connection to the file, reading and writing data to the file is an easy task. We can write data using the following syntax: opfile<<data;   In the above syntax, opfile is the object of ofstream and data is any variable holding data. We can read data from a file using the following syntax: ipfile>>data;   In the above syntax, ipfile is the object of ifstream and data is any variable into which the data is stored to process in the program.   Note: When a file is opened for writing data into it, if the specified file is not there, a new file with the same name is created and

The post How to read and write data in files in C++ appeared first on Coding Security.


How to read and write data in files in C++
read more

Sabtu, 08 Oktober 2016

How to throw exceptions in function definition in c++

A function can declare what type of exceptions it might throw. Syntax for declaring the exceptions that a function throws is as follows: 1 2 3 4 5 return–type function–name(params–list) throw(type1, type2, ...) { //Function body ... }   Following program demonstrates throwing exceptions in a function definition: 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 #include<iostream> using namespace std; void sum() throw(int) { int a, b; cout<<“Enter a and b values: “; cin>>a>>b; if(a==0 || b==0) throw 1;

The post How to throw exceptions in function definition in c++ appeared first on Coding Security.


How to throw exceptions in function definition in c++
read more

How to detect the end of the file in C++

Detecting End-of-File   While reading data from a file, if the file contains multiple rows, it is necessary to detect the end of file. This can be done using the eof() function of ios class. It returns 0 when there is data to be read and a non-zero value if there is no data. Following program demonstrates writing and reading multiple rows of data into the file: 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

The post How to detect the end of the file in C++ appeared first on Coding Security.


How to detect the end of the file in C++
read more

what are file handling classes in C++

Following figure illustrates the stream classes for working with files: fstreambase: The fstreambase is the base class for ifstream, ofstream, and fstream classes. Functions such are open() and close() are defined in this class.   fstream: It allows simultaneous input and output operations on filebuf. This class inherits istream andostream classes. Member functions of the base classes istream and ostream starts the input and output.   ifstream: This class inherits both fstreambase and istream classes. It can access member functions such as get(), getline(), seekg(), tellg(), and read(). It allows input operations and provides open() with the default input mode.   ofstream: This class inherits both fstreambase and ostream classes. It can access member functions such as put(), seekp(), write(), and tellp(). It allows output operations and provides the open() function with the default output mode.   filebuf: The filebuf is

The post what are file handling classes in C++ appeared first on Coding Security.


what are file handling classes in C++
read more

Jumat, 07 Oktober 2016

What are file pointer manipulations in C++

Every file will contain two pointers: a read pointer or also known as a get pointer and a write pointer also known as a put pointer. The read pointer or a get pointer is used to read data and the write pointer or put pointer is used to write data to a file. These pointers can be manipulated using the functions from stream classes. Those functions are as follows: The seekg() and seekp() functions specified above can be used to move the pointers in the file for random access. The syntax of these functions is as follows: seekg(int offset, reference_position)

The post What are file pointer manipulations in C++ appeared first on Coding Security.


What are file pointer manipulations in C++
read more

What is function prototype in programming languages

Function Prototype   A function prototype tells the compiler what is the function name, how many parameters a function accepts and the types of those parameters and the type of value that a function returns to its caller. General syntax of function prototype (declaration) is as follows: return-type  function-name(type, type, …, type);   In the above syntax, parameters are optional. When the function does not return any value, the return type must be specified as void.     Function Definition   The body or implementation of a function is known as function definition. A function definition always consists of a block

The post What is function prototype in programming languages appeared first on Coding Security.


What is function prototype in programming languages
read more

Kamis, 06 Oktober 2016

What is sequential and Random IO in C++

C++ allows data to be read or written from a file in sequential or random fashion. Reading data character by character or record by record is called sequential access. Reading data in any order is known as random access.   The fstream class provides functions like get(), read() for reading data and put(), write() for writing data to a file. The functions get() and put() are character-oriented functions. Syntax of these functions is as follows: get(char) put(char)   Following program demonstrates get() and put() functions: 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

The post What is sequential and Random IO in C++ appeared first on Coding Security.


What is sequential and Random IO in C++
read more

How to catch multiple exceptions in c++

A try block can be associated with more than one catch block. Multiple catch statements can follow a try block to handle multiple exceptions. The first catch block that matches the exception type will execute and the control shifts to next statement after all the available catch blocks.   A try block should be followed by at least one catch block. If non catch block matches with the exception, then terminate() function will execute. Following program demonstrates handling multiple exceptions using multiple catch statements: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

The post How to catch multiple exceptions in c++ appeared first on Coding Security.


How to catch multiple exceptions in c++
read more

How to overload special Operators in c++

Some of the special operators in C++ are: new – used to allocate memory dynamically delete – used to free memory dynamically ( ) and – subscript operators -> – member access operator   Let’s see how to overload them.   Overloading new and delete operators   C++ allows programmers to overload new and delete operators due to following reasons: To add more functionality when allocating or deallocating memory. To allow users to debug the program and keep track of memory allocation and deallocation in their programs.   Syntax for overloading new operator is as follows: void* operator new(size_t size);   Parameter size specifies the size of memory

The post How to overload special Operators in c++ appeared first on Coding Security.


How to overload special Operators in c++
read more

Rabu, 05 Oktober 2016

What are anonyomous objects in C++

Anonymous Objects   An object which has no name is known as an anonymous object. Syntax for creating an anonymous object is as follows:   ClassName(params-list);   An anonymous object can be created and used in any statement without using any name. It is automatically destroyed after the control moves on to the next statement. Following program demonstrates an anonymous object: 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 #include <iostream> using namespace std; class Student { private: string name; string regdno; int

The post What are anonyomous objects in C++ appeared first on Coding Security.


What are anonyomous objects in C++
read more

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

what are the Advantages and Disadvantages of Inheritance

Advantages of inheritance are as follows: Inheritance promotes reusability. When a class inherits or derives another class, it can access all the functionality of inherited class. Reusability enhanced reliability. The base class code will be already tested and debugged. As the existing code is reused, it leads to less development and maintenance costs. Inheritance makes the sub classes follow a standard interface. Inheritance helps to reduce code redundancy and supports code extensibility. Inheritance facilitates creation of class libraries.   Disadvantages of inheritance are as follows: Inherited functions work slower than normal function as there is indirection. Improper use of inheritance

The post what are the Advantages and Disadvantages of Inheritance appeared first on Coding Security.


what are the Advantages and Disadvantages of Inheritance
read more

Minggu, 02 Oktober 2016

How to allocate memory for objects and classes

Class is not allocated any memory. This is partially true. The functions in a class are allocated memory which are shared by all the objects of a class. Only the data in a class is allocated memory when an object is created. Every object has its own memory for data (variables). For example consider the following Student class and its functions: 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 class Student { private: string name; string regdno; string branch; int

The post How to allocate memory for objects and classes appeared first on Coding Security.


How to allocate memory for objects and classes
read more

what is the difference between local and nested class

Local Classes   A class which is declared inside a function is called a local class. A local class is accessible only within the function it is declared. Following guidelines should be followed while using local classes: Local classes can access global variables only along with scope resolution operator. Local classes can access static variables declared inside a function. Local classes cannot access auto variables declared inside a function. Local classes cannot have static variables. Member functions must be defined inside the class. Private members of the class cannot be accessed by the enclosing function if it is not declared

The post what is the difference between local and nested class appeared first on Coding Security.


what is the difference between local and nested class
read more

what are volatile objects and member functions

Volatile Objects and Member Functions   An object which can be modified by some unknown forces (like hardware) other than the program itself can be declared as volatile. Compiler doesn’t apply any optimizations for such volatile objects. Syntax for declaring an volatile object is as follows: volatile ClassName object-name;   A member function can be declared as volatile to make the access to member variables to be volatile. A volatile object can access only volatile functions. Syntax for creating a volatile function is as follows: return-type function-name(params-list) volatile;   Following program demonstrates both volatile objects and volatile programs: 1 2 3 4 5

The post what are volatile objects and member functions appeared first on Coding Security.


what are volatile objects and member functions
read more

Sabtu, 01 Oktober 2016

what is formatted and unformatted data in C++

Formatted and Unformatted Data   Data which is received by the program without any modifications and sent to the output device without any modifications is known as unformatted data. On the other hand, sometimes we may want to apply some modifications to the actual data that is being received or sent. For example, we might want to display an integer in hexadecimal format in the output, leave some whitespace when printing a number and adjustments in the decimal point. Such modified data in known as formatted data.   As an example for formatted data, if we want to display a

The post what is formatted and unformatted data in C++ appeared first on Coding Security.


what is formatted and unformatted data in C++
read more

What are stream classes in C++

Streams in C++   In C++, standard library maintains input and output as streams. A stream is a flow of data, measured in bytes, in sequence. If data is received from input devices, it is called a source stream and if the data is to be sent to output devices, it is called a destination stream.   The data in the source stream can be used as input to the program. Then it is called an input stream. The destination stream can be used by the program to send data to the output devices. Then it is called an output

The post What are stream classes in C++ appeared first on Coding Security.


What are stream classes in C++
read more

what are types of constructors in C++

Types of Constructors   A constructor can be classified into following types: Dummy constructor Default constructor Parameterized constructor Copy constructor Dynamic constructor   Dummy Constructor   When no constructors are declared explicitly in a C++ program, a dummy constructor is invoked which does nothing. So, data members of a class are not initialized and contains garbage values. Following program demonstrates a dummy constructor: 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 #include <iostream> using namespace std; class Student { private: string name;

The post what are types of constructors in C++ appeared first on Coding Security.


what are types of constructors in C++
read more