Sunday, December 15, 2013

ERRORS

No one is perfect, everyone commits some errors in one form or the other. Programming errors often remain undetected until an attempt for compiling or executing the program is made. Since errors prevent the program form being compiled or executed successfully, one should remove them before compiling and executing. 
Error is an  illegal operation performed by the user which results in abnormal working of the program. The common type of errors that can occur as:

  1. Syntax Error: These are those errors that occur when you violate the rules of writing C++ syntax. All these errors are detected by the compiler so it is also known as compiler errors. Some of the common compile time errors are missing semicolons at the end of statements, reference to an undeclared variables, wrong number or type of arguments passed to a function, etc. The errors are as follows:       a) The spelling of cout is written as cou.                                                                                             b) The cout statement statement does not ends with a semicolon.                                                         c) The program does not end with a closing brace ( } ).
  2. RUN TIME ERRORS: These errors occurs during program execution after successful compilation. Some common run time errors are division by zero (Divide Error), null pointer assignment, stack overflow, etc. These errors are difficult to find as the compiler does not point to the line at which this error occurs. The error message is displayed only after the execution with a wrong output.
  3. LINKER ERRORS: These errors normally occur when after compilation we link the different object files with main's object file using Ctrl+F9 key (Run). Some common linker errors are writing maid() instead of main(), any user-defined function is called but not defined, any standard built-in function (sqrt,cos, etc.) is called but its defination which is stored in library file which is not present. The linker must find the defination of the function called otherwise it will not create an executable file. To correct these errors return back to the program using F6 key.
  4. LOGICAL ERRORS (SEMANTIC ERRORS): Errors like semantic and execution errors are easier to find because they can just be located by generation of error messages on compilation or execution of a program but some programs do not provide desired output when certain input values are supplied to it. Such errors which provide incorrect output but appears to be error free are called logical errors.  These errors are often difficult to detect. The technique of finding and correcting this type of errors is called logical debugging. The Hit and Trial Method is one of the best method of finding logical errors.

DEMONSTRATION TOUR

There are many C++ compilers like Borland C++ (BC++), Turbo C++ (TC++), C front, GNU C++, Zortech C++ (ZTC++) and many more available for executing C++ programs. Among these TC++ and BC++ are the two most widely used C++ compilers. These provide ideal platforms for learning and developing C++ programs. In general, both BC++ and TC++ work in the same way except that some additional features like a debugger(TD), Turbo Assembler(TSAM), a profiler(TROF) are supported by
BC++ which are beyond the scope of current user. Most of the general class of user follow TC++. The TC++ provides  a powerful environment called IDE (Integrated Development Environment) with a built-in Editor and menu bar for writing and executing programs.

Turbo C++ compiler contains the directories such as BIN, INCLUDE, BGI, LIB, CLASSICLIB, DOC, etc.
BIN                   - contains the compiler and tools
INCLUDE        - contains the header files
BGI                   - contains the graphics file
LIB                   - contains the library files
CLASS LIB      - contains library files about classes
DOC                 - contains the documentation

Execution a program wirtten in any high level language like C++ involves the following steps:

  1. Developing the source program code.
  2. Selecting the appropriate file name in which you like to save the program. This saved file is known as source code file.
  3. After creating the source code file, compile the program. After compilation, the program changes to a object file if there are no errors. If any errors exist they need to be debugged.
  4. Now, link the object code and other library codes that are required for execution. On linking correctly, an executable code is formed and if any linker error occurs, it should be corrected and recompiled again.
  5. Now, run the program to obtain the desired result.
  6. If the answer is correct then stop otherwise there are some logical errors in the program. So to remove those errors geto step 3 and repeat the steps again.

STRUCTURE OF C++ PROGRAM

Parts of C++ program:

  1. DOCUMENTATION SECTION: It includes the comments that improves the readability of the program. It is and non executable statement that helps to read and understand a program. A comment is a message that exists only for the programmer and is ignored by the compiler.                                   TWO TYPES OF COMMENTS:                                                                                                           1. SINGLE LENE COMMENT: It starts with double slash (//) symbol and terminates at the end of        current line. For example: // calculate sum of two numbers.                                                        2. Multiline Comment: C++ programmer can also use C comment style that begin with /* and end with */. For example: /* calculate sum of two numbers.*/                                                         RULES FOR WRITING COMMENTS:                                                                                          a) Multiline comments cannot be nested.                                                                                                /* calculate /* sum of */ two numbers */                                                                                        b) A single line comment cannot be nested within the multiline comment.                                                  /* calculate sum and // product of two numbers. */                                                                         c) Any number of comments can be given at any place in the program but a programmer                         should avoid writing unnecessary comments.                                                                                    d) You cannot use comments within the looping and decision making statements.                                      for(i=0;i<n// i less than n or equal to n;i++)                                                                                     e) Comments should never include special characters such as form feed and backspace.
  2. PREPROCESSOR DIRECTIVE SECTION: It includes various preprocessor directives. All the preprocessor directives starts with a hash sigh (#). A preprocessor directive is a message to the compiler and it is handled by a part of the compiler known as a Proprocessor. The preprocessor directives are processed by the preprocessor before that program is actually compiled. The main function of the preprocessor is to include other files in the source file, specifying symbolic constants etc. Some of the most common proprocessor directives are:                                                               a) #include directive: It tells the preprocessor to include the contents of specified file in the sourcefile      in place of the directive before compilation.                                                                                                #include<iostream.h>                                                                                                                Here, the #include directive tells the preprocessor to include the contents of iostream.h file into          the source file. The iostream.h is a header file that contains the declaration of all the standard              Input/Output functions of      C++. The compiler will generate errors if this file is not included in            the source code.                                                                                                                       b) #define directive: The symbolic constants can be specified using #define. The symbolic constants        allows the programmer to define a name for constant and use that name throughout the program.          For example: #define PI 3.14159. It replaces every occurence of symbolic constant PI with a             value 3.14159 before the program is compiled.
  3. CLASS SECTION: It describes information about user-defined classes present in the program. A class is a collection of data (variable) and functions that operate on that data. A class declaration or defination include variable declaration, function declaration or the defination (code) of the function. The defination of the function may be also defined outside the class declaration i.e. in the class function defination. The function defination provides information to the compiler regarding the name of the function, required arguments and return type of the function. The function defination is that part of the function where the code of the function is defined.
  4. MAIN PROGRAM SECTION: The execution of the program always starts from this part of the program. It includes local declaration  part and executable part. The local declaration part include the declaration of variable that can only be accessed within main(). The executable part consists of statements that are executed in a given order.                                                                                            int main()                                                                                                                                            {                                                                                                                                                                     //local declaration part                                                                                                                       //executable part                                                                                                                     }  
  5. SUBPROGRAM SECTION: It includes various user-defined functions. These user defined functions are nor the part of any class.

Saturday, December 14, 2013

CHARACTERISTICS OF C++ LANGUAGE


  • C++ has a rich collection of standard class libraries, inbuilt functions and datatypes which helps in creating large and complex programs very easily.
  • C++ is an extension of C with Object Oriented (OO) features, It provides upward compatibility with C language as almost all the valid C programs are valid C++ programs.
  • The program written in C++ is well suited for modelling real world problems as close as possible to the users perspective.
  • In C++, complex data types called Abstract Data Types (ADTs) can be created using classes. 
  • C++ allows the programmer to redefine the meaning of existing operators such as +,-,>. Forexample: the '+' operator can be used for adding two numbers as well as to concatenate two strings.
  • C++ programs can easily be extended as it is very easy to add new features into the existing program.
  • New programs can be developed in lesser time as the existing code can be reused.
  • C++ provides a namespace control mechanism for restricting the scope of classes, functions and global objects.

FOUNDER OF C++ LANGUAGE



BJANRE STROUSTRUP




WHAT IS C++?

C++ is a successful and most widely used Object Oriented Programming Language. It is an extension of C language that not only adds Object Oriented concepts but also readdress some of the weaknesses of C language. The Object Oriented features in C++ helps the programmer to build large and complex programs with greater efficiency, extensibility and ease of maintenance. It allows a programmer to follow a structured and disciplined approach for making complex computer programs.
C++ is a strongly typed language developed by Bjarne Stroustrup in 1983 at Bell Laboratories. C++ is a hybrid language as it is possible to write programs in C++ in either C language style, Object Oriented style or both. It can be used for developing any kind of applications like interactive computer graphics, expert systems, simulation, databases, artificial intelligence, system program application and for making compilers. 
C++ is a universal language. It can be used to write programs for MS-Windows, Linux, Macintosh, Unix, etc.