Friday, January 27, 2017

C++ Files and Streams

So far, we have been using the iostream standard library, which provides cin and cout methods for reading from standard input and writing to standard output respectively.
This tutorial will teach you how to read and write from a file. This requires another standard C++ library called fstream, which defines three new data types:

C++ Exception Handling

An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.
Exceptions provide a way to transfer control from one part of a program to another. C++ exception handling is built upon three keywords: try, catch, and throw.

C++ Dynamic Memory

A good understanding of how dynamic memory really works in C++ is essential to becoming a good C++ programmer. Memory in your C++ program is divided into two parts:
  • The stack: All variables declared inside the function will take up memory from the stack.
  • The heap: This is unused memory of the program and can be used to allocate the memory dynamically when program runs.

Namespaces in C++

Consider a situation, when we have two persons with the same name, Zara, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area if they live in different area or their mother or father name, etc.

C++ Templates

Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.
A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept.

C++ Preprocessor

The preprocessors are the directives, which give instruction to the compiler to preprocess the information before actual compilation starts.
All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not C++ statements, so they do not end in a semicolon (;).

C++ Signal Handling

Signals are the interrupts delivered to a process by the operating system which can terminate a program prematurely. You can generate interrupts by pressing Ctrl+C on a UNIX, LINUX, Mac OS X or Windows system.

C++ Multithreading

Multithreading is a specialized form of multitasking and a multitasking is the feature that allows your computer to run two or more programs concurrently. In general, there are two types of multitasking: process-based and thread-based.

C++ Web Programming

What is CGI?

  • The Common Gateway Interface, or CGI, is a set of standards that define how information is exchanged between the web server and a custom script.
  • The CGI specs are currently maintained by the NCSA and NCSA defines CGI is as follows:
  • The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers such as HTTP servers.
  • The current version is CGI/1.1 and CGI/1.2 is under progress.

C++ Questions and Answers

C++ Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations.

C++ Quick Guide

C++ is a statically typed, compiled, general-purpose, case-sensitive, free-form programming language that supports procedural, object-oriented, and generic programming.
C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features.

C++ Object Oriented

The prime purpose of C++ programming was to add object orientation to the C programming language, which is in itself one of the most powerful programming languages.
The core of the pure object-oriented programming is to create an object, in code, that has certain properties and methods.

C++ STL Tutorial

Hope you already understand the concept of C++ Template which we already have discussed in one of the chapters. The C++ STL (Standard Template Library) is a powerful set of C++ template classes to provides general-purpose templatized classes and functions that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, and stacks.

C++ Standard Library

The C++ Standard Library can be categorized into two parts:
  • The Standard Function Library: This library consists of general-purpose,stand-alone functions that are not part of any class. The function library is inherited from C.
  • The Object Oriented Class Library: This is a collection of classes and associated functions.

C++ Useful Resources

The following resources contain additional information on C++. Please use them to get more in-depth knowledge on this topic.

Discuss C++

C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This reference will take you through simple and practical approach while learning C++ Programming language.

Computer Programming - Overview

Introduction to Computer Program

Before getting into computer programming, let us first understand computer programs and what they do.
A computer program is a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.
The two important terms that we have used in the above definition are −

Computer Programming - Basics

We assume you are well aware of English Language, which is a well-known Human Interface Language. English has a predefined grammar, which needs to be followed to write English statements in a correct way. Likewise, most of the Human Interface Languages (Hindi, English, Spanish, French, etc.) are made of several elements like verbs, nouns, adjectives, adverbs, propositions, and conjunctions, etc.

Computer Programming - Environment

Though Environment Setup is not an element of any Programming Language, it is the first step to be followed before setting on to write a program.
When we say Environment Setup, it simply implies a base on top of which we can do our programming. Thus, we need to have the required software setup, i.e., installation on our PC which will be used to write computer programs, compile, and execute them.

Computer Programming - Basic Syntax

Let’s start with a little coding, which will really make you a computer programmer. We are going to write a single-line computer program to write Hello, World! on your screen. Let’s see how it can be written using different programming languages.

Computer Programming - Data Types

Let's discuss about a very simple but very important concept available in almost all the programming languages which is called data types. As its name indicates, a data type represents a type of the data which you can process using your computer program. It can be numeric, alphanumeric, decimal, etc.

Computer Programming - Variables

Variables are the names you give to computer memory locations which are used to store values in a computer program.
For example, assume you want to store two values 10 and 20 in your program and at a later stage, you want to use these two values. Let's see how you will do it. Here are the following three simple steps −

Computer Programming - Keywords

So far, we have covered two important concepts called variables and their data types. We discussed how to use int, long, and float to specify different data types. We also learnt how to name the variables to store different values.

Computer Programming - Operators

An operator in a programming language is a symbol that tells the compiler or interpreter to perform specific mathematical, relational or logical operation and produce final result. This chapter will explain the concept of operators and it will take you through the important arithmetic and relational operators available in C, Java, and Python.

Computer Programming - Decision

Decision making is critical to computer programming. There will be many situations when you will be given two or more options and you will have to select an option based on the given conditions. For example, we want to print a remark about a student based on his secured marks. Following is the situation −

Computer Programming - Loops

Let's consider a situation when you want to print Hello, World! five times. Here is a simple C program to do the same −
#include <stdio.h>

main() {

Computer Programming - Numbers

Every programming language provides support for manipulating different types of numbers such as simple whole integers and floating point numbers. C, Java, and Python categorize these numbers in several categories based on their nature.

Computer Programming - Characters

If it was easy to work with numbers in computer programming, it would be even easier to work with characters. Characters are simple alphabets like a, b, c, d...., A, B, C, D,....., but with an exception. In computer programming, any single digit number like 0, 1, 2,....and special characters like $, %, +, -.... etc., are also treated as characters and to assign them in a character type variable, you simply need to put them inside single quotes.

Computer Programming - Arrays

Consider a situation where we need to store five integer numbers. If we use programming's simple variable and data type concepts, then we need five variables of int data type and the program will be as follows −
#include <stdio.h>

Computer Programming - Strings

During our discussion about characters, we learnt that character data type deals with a single character and you can assign any character from your keyboard to a character type variable.

Computer Programming - Functions

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. You have already seen various functions like printf() and main().

Computer Programming - File I/O

Computer Files

A computer file is used to store data in digital format like plain text, image data, or any other content. Computer files can be organized inside different directories. Files are used to keep digital data, whereas directories are used to keep files.

Computer Programming - Summary

We appreciate your patience for going through this tutorial. We have tried to keep it concise but as this subject contains several topics, we have shown a few examples in detail.

Computer Programming - Quick Guide

Computer Programming - Overview

Introduction to Computer Program

Before getting into computer programming, let us first understand computer programs and what they do.
A computer program is a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.
The two important terms that we have used in the above definition are −

Computer Programming - Useful Resources

The following resources contain additional information on Computer Programming. Please use them to get more in-depth knowledge on this topic.

Discuss Computer Programming

Computer programming is the act of writing computer programs, which are a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.

COBOL - Overview

COBOL is a high-level language. One must understand the way COBOL works. Computers only understand machine code, a binary stream of 0s and 1s. COBOL code must be converted into machine code using a compiler.

COBOL - Environment Setup

Try it Option Online

We have set up the COBOL Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.

COBOL - Program Structure

A COBOL program structure consists of divisions as shown in the following image:
Program Structure A brief introduction of these divisions is given below:

COBOL - Basic Syntax

Character Set

'Characters' are lowest in the hierarchy and they cannot be divided further. The COBOL Character Set includes 78 characters which are shown below:

COBOL - Data Types

Data Division is used to define the variables used in a program. To describe data in COBOL, one must understand the following terms:
  • Data Name
  • Level Number
  • Picture Clause
  • Value Clause

COBOL - Basic Verbs

COBOL verbs are used in the procedure division for data processing. A statement always start with a COBOL verb. There are several COBOL verbs with different types of actions.

COBOL - Data Layout

COBOL layout is the description of use of each field and the values present in it. Following are the data description entries used in COBOL:
  • Redefines Clause
  • Renames Clause
  • Usage Clause
  • Copybooks

COBOL - Condition Statements

Conditional statements are used to change the execution flow depending on certain conditions specified by the programmer. Conditional statements will always evaluate to true or false. Conditions are used in IF, Evaluate and Perform statements. The different types of conditions are as follows:

COBOL - Loop Statements

There are some tasks that need to be done over and over again like reading each record of a file till its end. The loop statements used in COBOL are:
  • Perform Thru
  • Perform Until
  • Perform Times
  • Perform Varying

COBOL - String Handling

String handling statements in COBOL are used to do multiple functional operations on strings. Following are the string handling statements:
  • Inspect
  • String
  • Unstring

COBOL - Table Processing

Arrays in COBOL are known as tables. An array is a linear data structure and is collection of individual data items of same type. Data items of a table are internally sorted.

COBOL - File Handling

The concept of files in COBOL is different from that in C/C++. While learning the basics of 'File' in COBOL, the concepts of both languages should not be co-related. Simple text files cannot be used in COBOL, instead PS (Physical Sequential) and VSAM files are used. PS files will be discussed in this module.

COBOL - File Organization

File organization indicates how the records are organized in a file. There are different types of organizations for files so as to increase their efficiency of accessing the records. Following are the types of file organization schemes:

COBOL - File Access Mode

Till now, file organization schemes have been discussed. For each file organization scheme, different access modes can be used. Following are the types of file access modes:
  • Sequential Access
  • Random Access
  • Dynamic Access

COBOL - File Handling Verbs

File handling verbs are used to perform various operations on files. Following are the file handling verbs:
  • Open
  • Read
  • Write
  • Rewrite
  • Delete
  • Start
  • Close

COBOL - Subroutines

Cobol subroutine is a program that can be compiled independently but cannot be executed independently. There are two types of subroutines: internal subroutines like Perform statements and external subroutines like CALL verb.

COBOL - Internal Sort

Sorting of data in a file or merging of two or more files is a common necessity in almost all business-oriented applications. Sorting is used for arranging records either in ascending or descending order, so that sequential processing can be performed. There are two techniques which are used for sorting files in COBOL:

COBOL - Database Interface

As of now, we have learnt the use of files in COBOL. Now, we will discuss how a COBOL program interacts with DB2. It involves the following terms:
  • Embedded SQL
  • DB2 Application Programming
  • Host Variables
  • SQLCA
  • SQL Queries
  • Cursors

COBOL Interview Questions

Dear readers, these COBOL Interview Questions have been designed especially to get you acquainted with the nature of questions you may encounter during your interview for the subject of COBOL Programming Language. As per my experience, good interviewers hardly plan to ask any particular question during your interview.

COBOL Questions and Answers

COBOL Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations.

COBOL - Quick Guide

COBOL - Overview

Introduction to COBOL

COBOL is a high-level language. One must understand the way COBOL works. Computers only understand machine code, a binary stream of 0s and 1s. COBOL code must be converted into machine code using a compiler. Run the program source through a compiler.

COBOL - Useful Resources

The following resources contain additional information on COBOL. Please use them to get more in-depth knowledge on this topic.

Discuss COBOL

COBOL stands for Common Business Oriented Language.The US Department of Defense, in a conference, formed CODASYL (Conference on Data Systems Language) to develop a language for business data processing needs which is now known as COBOL.

Clojure - Overview

Clojure is a high level, dynamic functional programming language. Clojure is designed based on the LISP programming language and has compilers which makes it run on both Java and .Net runtime environment.
Before we talk about Clojure, let’s just have a quick description of LISP programming language.

Clojure - Environment

Try it Option Online

We have set up the Clojure Programming environment on-line, so that you can compile and execute all the available examples on line. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it on-line.

Clojure - Basic Syntax

In order to understand the basic syntax of Clojure, let’s first look at a simple Hello World program.

Hello World as a Complete Program

Write ‘Hello world’ in a complete Clojure program. Following is an example.

Clojure - REPL

REPL (read-eval-print loop) is a tool for experimenting with Clojure code. It allows you to interact with a running program and quickly try out if things work out as they should. It does this by presenting you with a prompt where you can enter the code. It then reads your input, evaluates it, prints the result, and loops, presenting you with a prompt again.

Clojure - Data Types

Clojure offers a wide variety of built-in data types.

Built-in Data Types

Following is a list of data types which are defined in Clojure.
  • Integers − Following are the representation of Integers available in Clojure.
    • Decimal Integers (Short, Long and Int) − These are used to represent whole numbers. For example, 1234.

Clojure - Variables

In Clojure, variables are defined by the ‘def’ keyword. It’s a bit different wherein the concept of variables has more to do with binding. In Clojure, a value is bound to a variable. One key thing to note in Clojure is that variables are immutable, which means that in order for the value of the variable to change, it needs to be destroyed and recreated again.

Clojure - Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
Clojure has the following types of operators −
  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Bitwise operators

Clojure - Loops

So far we have seen statements which are executed one after the other in a sequential manner. Additionally, statements are provided in Clojure to alter the flow of control in a program’s logic. They are then classified into flow of control statements which we will see in detail.

Clojure - Decision Making

Decision-making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Clojure - Functions

Clojure is known as a functional programming language, hence you would expect to see a lot of emphasis on how functions work in Clojure. This chapter covers what all can be done with functions in Clojure.

Clojure - Numbers

Numbers datatype in Clojure is derived from Java classes.
Clojure supports integer and floating point numbers.
  • An integer is a value that does not include a fraction.
  • A floating-point number is a decimal value that includes a decimal fraction.

Clojure - Recursion

We have seen the recur statement in an earlier topic and whereas the ‘for’ loop is somewhat like a loop, recur is a real loop in Clojure.

Clojure - File I/O

Clojure provides a number of helper methods when working with I/O. It offers easier classes to provide the following functionalities for files.
  • Reading files
  • Writing to files
  • Seeing whether a file is a file or directory

Clojure - Strings

A String literal is constructed in Clojure by enclosing the string text in quotations. Strings in Clojure need to be constructed using the double quotation marks such as “Hello World”.

Clojure - Lists

List is a structure used to store a collection of data items. In Clojure, the List implements the ISeq interface. Lists are created in Clojure by using the list function.

Clojure - Sets

Sets in Clojure are a set of unique values. Sets are created in Clojure with the help of the set command.

Example

Following is an example of the creation of sets in Clojure.
(ns clojure.examples.example
   (:gen-class))

Clojure - Vectors

A Vector is a collection of values indexed by contiguous integers. A vector is created by using the vector method in Clojure.

Clojure - Maps

A Map is a collection that maps keys to values. Two different map types are provided - hashed and sorted. HashMaps require keys that correctly support hashCode and equals. SortedMaps require keys that implement Comparable, or an instance of Comparator.

Clojure - Namespaces

Namespaces in Clojure are used to differentiate classes into separate logical spaces just like in Java. Consider the following statement.
(:require [clojure.set :as set])

Clojure - Exception Handling

Exception handling is required in any programming language to handle the runtime errors so that the normal flow of the application can be maintained. Exception usually disrupts the normal flow of the application, which is the reason why we need to use exception handling in our application.

Clojure - Sequences

Sequences are created with the help of the ‘seq’ command. Following is a simple example of a sequence creation.
(ns clojure.examples.example
   (:gen-class))

Clojure - Regular Expressions

A regular expression is a pattern that is used to find substrings in text. Regular expressions are used in a variety of programming languages and used a lot in LISP type programming languages.
Following is an example of a regular expression.

Clojure - Predicates

Predicates are functions that evaluate a condition and provide a value of either true or false. We have seen predicate functions in the examples of the chapter on numbers. We have seen functions like ‘even?’ which is used to test if a number is even or not, or ‘neg?’ which is used to test if a number is greater than zero or not.

Clojure - Destructuring

Destructuring is a functionality within Clojure, which allows one to extract values from a data structure, such as a vector and bind them to symbols without having to explicitly traverse the datastructure.
Let’s look at an example of what exactly Destructuring means and how does it happen.

Clojure - Date and Time

Since the Clojure framework is derived from Java classes, one can use the date-time classes available in Java in Clojure. The class date represents a specific instant in time, with millisecond precision.
Following are the methods available for the date-time class.

Clojure - Atoms

Atoms are a data type in Clojure that provide a way to manage shared, synchronous, independent state. An atom is just like any reference type in any other programming language. The primary use of an atom is to hold Clojure’s immutable datastructures. The value held by an atom is changed with the swap! method.

Clojure - Metadata

In Clojure, metadata is used to annotate the data in a collection or for the data stored in a symbol. This is normally used to annotate data about types to the underlying compiler, but can also be used for developers.

Clojure - StructMaps

StructMaps are used for creating structures in Clojure. For example, if you wanted to create a structure which comprised of an Employee Name and Employeeid, you can do that with StructMaps.
The following operations are possible in Clojure with regards to StructMaps.

Clojure - Agents

As pointed out many times, Clojure is a programming language wherein many of the data types are immutable, which means that the only way one can change the value of a variable is to create a new variable and assign the new value to it. However, Clojure does provide some elements, which can create an mutable state.

Clojure - Watchers

Watchers are functions added to variable types such as atoms and reference variables which get invoked when a value of the variable type changes. For example, if the calling program changes the value of an atom variable, and if a watcher function is attached to the atom variable, the function will be invoked as soon as the value of the atom is changed.

Clojure - Macros

In any language, Macros are used to generate inline code. Clojure is no exception and provides simple macro facilities for developers. Macros are used to write code-generation routines, which provide the developer a powerful way to tailor the language to the needs of the developer.

Clojure - Reference Values

Reference values are another way Clojure can work with the demand to have mutable variables. Clojure provides mutable data types such as atoms, agents, and reference types.
Following are the operations available for reference values.

Clojure - Databases

In order to use the database functionality, please ensure to first download the jdbc files from the following url − https://codeload.github.com/clojure/java.jdbc/zip/master
You will find a zip file which has the necessary drivers for Clojure to have the ability to connect to databases. Once the zip file is extracted, ensure to add the unzipped location to your classpath.

Clojure - Java Interface

As we already know, Clojure code runs on the Java virtual environment at the end. Thus it only makes sense that Clojure is able to utilize all of the functionalities from Java. In this chapter, let’s discuss the correlation between Clojure and Java.

Clojure - Concurrent Programming

In Clojure programming most data types are immutable, thus when it comes to concurrent programming, the code using these data types are pretty safe when the code runs on multiple processors. But many a times, there is a requirement to share data, and when it comes to shared data across multiple processors, it becomes necessary to ensure that the state of the data is maintained in terms of integrity when working with multiple processors. This is known as

Clojure - Applications

Clojure has some contributed libraries which have the enablement for creating Desktop and Web-based applications. Let’s discuss each one of them.

Clojure - Automated Testing

In this chapter, let’s discuss automated testing options provided by Clojure.

Testing for Client Applications

In order to use testing for Clojure framework, you have to use the dependencies located at https://github.com/slagyr/speclj#manual-installation

Clojure - Libraries

One thing which makes the Clojure library so powerful is the number of libraries available for the Clojure framework. We have already seen so many libraries used in our earlier examples for web testing, web development, developing swing-based applications, the jdbc library for connecting to MySQL databases. Following are just a couple of examples of few more libraries.

Clojure - Quick Guide

Clojure - Overview

Clojure is a high level, dynamic functional programming language. Clojure is designed based on the LISP programming language and has compilers which makes it run on both Java and .Net runtime environment.

Clojure - Useful Resources

The following resources contain additional information on Clojure. Please use them to get more in-depth knowledge on this.

Discuss Clojure

Clojure is a high level, dynamic functional programming language. It is designed, based on the LISP programming language, and has compilers that makes it possible to be run on both Java and .Net runtime environment. This tutorial is fairly comprehensive and covers various functions involved in Clojure. All the functions are explained using examples for easy understanding.