Sunday, November 25, 2012

COMPUTER PROGRAMMING C++ BASIC

Computer Programming

 It means to develop or write computer programs to perform different types of activities in a computer system using computer languages.
 Programming can be classified into two types: systems programming and   (application) programming. 
 System programming is handled by computer engineers or system programmers to develop system programs such as operating systems, language translators, etc. 
(Application) programming is handled by ordinary computer programmers to develop application software such as payroll system, stock control system, etc. 
Computability
 The possibility of programming a task by a machine is called computability. 
Complexity
 Complexity is the measuring term of quantity of resources used for many alternative algorithms.  Knowledge of complexity helps to find the best algorithm.   Average cases and worst cases can also be identified.
Correctness
 A program should produce the required result for all possible inputs and it is called correctness.
Structured programming 
Programming that produces programs with clean flow, clear design, and a degree of modularity (or hierarchical structure) is called structured programming. 
 The three basic constructs in structured programming are sequence (ordered set of statements), selection (conditional branch), and iteration (repetition).
  There is no GOTO statement to jump to any place in the program.
Modular programming
 An approach to programming in which the program is broken into several independently compiled modules is called modular programming.  
It facilitates group programming efforts.
 Modular programming is a precursor (ancestor) of object oriented programming.
Object-oriented programming (OOP)
 It is a programming paradigm in which a program is viewed as a collection of discrete objects that are self contained collection of data structures and routines that interacts with other objects.
Top-down programming
 An approach to programming that implements a program in top-down fashion is referred to as top- down programming. 
Typically this is done by writing a main body which calls to several major routines (implemented as stubs).
 Each routine is then coded, calling other, lower-level routines (also done initially as stubs).
  Here, stub is a placeholder for a routine to be written later.
Bottom-up programming
 It is a programming technique in which lower-level functions are developed and tested first.
  higher-level functions are then built using the lower- level functions.
Programming Language 
It is any artificial language that can be used to define a sequence of instructions that can ultimately be processed and executed by the computer.  
 A program called, language translator, translates statements written in one programming language into their machine language.
Levels/Generations of Languages
 Languages are generally divided into five levels/generations.
1. Machine language 
2. Assembly language 
3. High-level languages 
4. Very high-level languages 
5. And Natural languages 
Machine language
 * Programs that are written in 1’s and 0’s are in the actual machine language.
 * Machine code consists of binary coded instructions and data intermixed.
 * All programs in other languages must be translated into machine language before  their execution.
* Each type of computer has its own unique machine language.
 * Machine language is very difficult to write programs and to detect and correct program errors.
* A thorough knowledge of computer hardware is required for machine language programming.
 * Here, programmers cannot concentrate on data processing problems, because more attention should be paid for the architecture of the computer system.  
* Machine language programs are not portable among different types of computers.
* However, machine language programs can be executed much faster and maximum usage of resources (e.g. memory) can be obtained.
Assembly language
* It is the direct symbolic representation of a machine language.
* Assembly languages include IBM BAL(Basic Assembly Language for IBM) and VAX Macro (For Digital Equipment Corporation, Macro 11,  Macro 32,  Macro 64 ).
* Assembly languages use English-like mnemonic codes to represent the operations:  A for add, C for compare, MP for multiply,  STO for storing information in memory, and so on.
* Assembly language specifies registers with meaningful codes, such as AX, BX, etc., instead of binary numbers. 
* Furthermore, it permits the use of names,  perhaps RATE or TOTAL for memory locations, instead of the actual binary memory address.
* As with machine language, each type of computer has its own unique assembly language.
 * Therefore, both machine and assembly languages are considered as machine oriented or low-level computer languages. 
*Assembly language is easy to write programs and to detect and correct program errors compared to machine language programs. 
* As source program should be translated into machine language, more time is required for execution.
* The part of the machine language or assembly language instructions that specifies the operation or function to be carried out is called opcode.

High-level languages
* To overcome problems of low-level languages, high- level languages were developed. 
* As standard words of those languages are closer to human language (English).
 * It is much easier to write programs and to detect and correct errors. 
* As high-level languages are machine independent, programs are portable, less hardware knowledge is required, and more attention can be paid for data processing requirements.
 *Here, a lesser number of instructions are required.
* Due to the compilation process more time is needed to execute the program.
 *Here, computer resources cannot be used fully.
  * FORTRAN (Formula translator), ALGOL (Algorithmic Language), COBOL (Common business oriented language), RPG (Report program generator), BASIC (Beginners all purpose symbolic instruction code), Pascal, C, C++, Java, and Visual Basic, are some of the examples for high-level language. 
*For any given high-level language, there are usually a number of translators available, each of which translates a program in that language to the machine language for a specific type of computer
Very high-level languages
* Very high-level languages are often known as 4GLs (fourth-generation languages).
 * Languages belonging to the first three generations are procedural languages, consisting of instructions that describe the step-by-step procedure to solve the problem.
 *4GLs are non procedural languages, in which the programmer specifies the desired results, and the language develops the solution.
* Query languages, such as SQL (Structured query language), are variations on 4GLs and are used to retrieve information from databases.
Natural language
*The natural language (sometimes considered to be 5GLs) translates human instructions into codes the computer can execute.
 * If it does not understand the user’s request, it politely asks for further explanation.
* For example, INTELLECT, a natural language, would use a statement like, “What are the average exam scores in C++?”.
Comparison among different levels of programming languages
Language Translators
*All the source programs should be converted into their machine language before the execution process.
* Language translators are used for this process. 
*There are three types of language translators: Assemblers, Compilers, and Interpreters. 
Assembler
* It is a language translator which translates source programs written in assembly language into their object programs. 
Compiler
* It translates/compiles the entire program written in a high-level language into its object program considering the program as a single unit.
* After the compilation process the source program is no more required as the object program is available.
 *A compiler is able to look at the whole of a program and to work out the best way of translating.
 * This is some times called optimization and is one of the reasons why a compiler can produce efficient code.
 * Once all errors have been corrected, the program will run faster.
 * However errors are more difficult to find during compilation because they are not reported until the end of the process and a single error can generate additional error messages making it harder to locate the error. 
* When the program is in testing mode, there is no benefit to have a stored executable program since this will have to be rebuilt each time.
Interpreter
* It is a language translator which converts high-level language statements into equivalent machine language statements one at a time as the program is executed.
 *It does not generate an object program as a separate unit.
* Here, each statement is checked for syntax,  then converted into machine code, and then executed.
* The presence of the source program is required for the execution of the program and it should be interpreted each time.
  * Here, In the case of repetition, some program statements may be translated many times.
 * Executing an interpreted program is slower than executing a compiled program since each statement has to be converted to binary each time even if it has been converted previously. 
* With an interpreted language there is always the danger that a syntax error may exist in a section of code that has not been tested. 
* However, there is no lengthy compile and link cycle.
* If the program encounters an error, the interpretations stops and an error message is displayed so the user can correct it.
 * Therefore, interpreters are comfortable for beginners because small programs can be written and tested very quickly. 
Integrated development environment (IDE)
* Most current languages come in a comprehensive package called an integrated development environment (IDE) that includes language aware editor, project build capability (compiler and linker), debugger, and other programming tools. 
* Other programming tools include diagramming packages, code generators,  libraries of reusable objects and program code, and prototyping tools. 
Some Commonly Used High-Level Languages
*FORTRAN (Formula translator) was developed by IBM and introduced in 1954. It was the first high-level language. It is very good at representing complex mathematical formulas.  
*ALGOL (Algorithmic Language) was the first structured procedural programming language developed in late 1950s.  
* COBOL (Common business oriented language) is a verbose (wordy), English-like compiled programming language developed between 1959 and 1961 and still in widespread use, especially in business applications typically run on mainframes. It is very good for processing large, complex data files and for producing well-formatted business reports.  
* RPG (Report program generator) was developed by IBM in 1965 to allow rapid creation of reports from data stored in the computer files.  
* BASIC (Beginners all purpose symbolic instruction code) was originally developed by Dartmouth College professors John Kemeny and Thomas Kurtz in 1965 to teach programming to their students.
* Pascal was designed between 1967 and 1971 by Niklaus Wirth. It is a compiled, structured language built upon ALGOL, simplifies syntax while adding data types and structures such as sub ranges, enumerated data types, files, records, and sets.  
* C was created in 1972. One of the C’s primary advantages is its portability. There are C compilers for almost every combination of computer and operating system available today. 
* C++ is an object-oriented version of C, developed in the early 1980s.
* Java is a network-friendly object-oriented programming language derived from C++ that permits a piece of software to run directly on many different platforms.
 * Java programs are not compiled directly into machine language, but into an intermediate language called bytecode.
* This bytecode is then executed by a universal platform, called the JVM (Java Virtual Machine), which sits atop a computers regular platform. 
* The JVM interprets (translates) compiled Java code into instructions that the platform underneath can understand.
* Java provides high level of security to the user and the network.
* Java uses Unicode coding system, which allows displaying all character sets in a uniform manner.
* Web pages can include Java mini programs, called applets, which run on a Java platform included in the user’s Web browser. 
* Visual Basic (VB) was introduced by Microsoft in 1987 as its first visual development tool. 
*It allows the programmer to easily create complex user interfaces containing standard Windows features, such as buttons, dialog boxes, scroll bars, and menus.
 * VB enables the user to control program execution.
 * This type of program is referred to as being event-driven. 
*The ability to create user-friendly event-driven programs with attractive Windows-like interfaces quickly has resulted in VB becoming one of the most popular programming languages.
  * VB can also be thoroughly integrated with Microsoft Office to customize programs.
* Perl (Practical Extraction and Report Language) is an interpreted language, based on C and several UNIX utilities.
 * Perl has powerful string handling features for extracting information from text files. 
* Perl can assemble a string and send it to the shell as a command; hence, it is often used for system administration tasks. 
* A program in Perl is known as a script.
Classification of Currently Available Languages according to The Programming Style 
1 Procedural/Imperative Languages:   These consist of explicit instructions that describe the step-by-step procedure to solve the problem.   These are formed from collection of basic commands (assignments, input, output, etc) and control structures (selection, iteration, etc.).   E.g.: C, Pascal, FORTRAN, Assembly, etc.
 2 Non procedural languages:   These are a programming languages that do not follow the procedural paradigm (pattern) of executing statements, subroutine calls, and control structures sequentially but instead describes a set of facts and relationships and then is queried for specific results.
 3 Functional Languages:   These are based on lambda-calculus, which concerns the application of functions to their arguments.   Functional Language programs consist of collections of function definitions and their applications.   E.g.: LISP (LISt Processing), etc.
4 Logic Programming Languages:   Here, programs consists of collections of statements within a particular logic, such as predicate logic.   E.g.: Prolog (Programming logic), etc.
 5 Object Oriented Language:   Here, programs consist of objects that interact with each other.   E.g.: SIMULA (Simulation Language), Smalltalk, Eiffel, etc..   The object-oriented language that currently dominates the market is C++.   It supports both object-oriented programming and non-object-oriented programming. 
Java, the language threatening C++ dominance, is a pure object-oriented language; that is, it is impossible to write a non-object-oriented program.   The latest version of Java is J2EE (Java2 Enterprise Edition).   A relatively new language, C# (“cee-sharp”) is Microsoft’s answer to Java.   It has most of the same advantages over C++ as does Java, but it is designed to work within Microsoft’s .NET environment. 
The .NET environment is designed for building, deploying (organizing), and running Web-based applications.   Many people referred to prior versions of Visual Basic as ‘object-oriented’, because VB programs used ‘objects’ such as command buttons, scroll bars, and others. However, it wasn’t until the current version, VB.NET, that Visual Basic supported the concepts of inheritance and polymorphism, thus meeting the criteria for a true object-oriented language.
6 Declarative Language:   These are collections of declarations.   Many functional and Logic languages are also declarative.   Here, you describe a pattern to be matched without writing the code to match the pattern.  
 7 Scripting Languages:   Scripting languages are designed to perform special or limited tasks, sometimes associated with a particular application or function.   E.g.: Perl (Practical extraction report language), etc. 
 8 Parallel Languages:   These are collections of processes that communicate with each other.   E.g.: C*, Ada, etc.. 

Stages of Computer Programming 
1         Analyzing and defining the problem
 *In some organizations, programmers receive asset of specifications from system analysts. 
* In others, the programmers meet directly with users to analyze the problem and determine the user’s needs.
* In either case, the task of problem definition involves determining the input and output.  
             *  Finally, you produce a written agreement that specifies, in detail, the input data, the required output, and the processing required converting the input into the output.  
  2  Program design  (or planning the solution)
 * The next step is to design an algorithm, a detailed, step-by-step solution to the problem.
* An algorithm must have some characteristics:
* must be precise (unambiguous); 
*must be effective;
* must have a finite number of instructions; 
* execution must always terminate. 
* There are number of design tools that a programmer can use to develop the algorithm: 
*flowchart
* pseudo code
* decision trees
 *decision tables
 *structure diagrams  .   
* After completing the algorithm design, the programmer should perform a process, called desk- checking or dry-run, to verify that it produces the desired result.
 *This involves sitting down with a pencil and paper and ‘playing computer’ by carrying out each step of the algorithm in the indicated sequence.  
   Program coding 
* Program coding means conversion of the algorithm into a set of instructions written in a computer programming language. 
* This program is keyed into the computer by using a text editor, a program that is similar to a word processor. 
Program testing and debugging
 * The following diagram illustrates the steps in preparing a program for execution.
*During these steps computer programs should be checked for program errors.
*The original program written in a computer programming language is called as source program.
 * Initially, this source program is translated into its machine language form (called object program) by the language translator (compiler).
 *If the source program violates the grammatical rules of that programming language, it cannot be converted into its machine language and these types of errors can be described as syntax errors, compile time errors, or diagnostic errors.
* As data cannot be processed without some utility programs, object programs should be linked with them to produce an executable program (load module).
 * This job is done by another system program called a linkage editor (linker).
* When required utility programs are not available or when utility programs cannot be linked with the object program properly, an executable program cannot be produced. These errors are described as link errors
* When the executable program cannot be executed, such errors can be described as run-time errors or execution-time errors.
* When an executable program is executed and if it produces undesirable results it is due to some errors in the program logic or algorithm.
 * Such errors are described as logical errors. 
* Programmers call these errors  to as bugs, and the process of locating and correcting them is referred to as debugging the program.
* If syntax, link or run-time errors are available computer can detect those errors, but the logical error should be detected by computer programmers.
  * During program testing, different types of test data (both valid and invalid) should be used as input data.


 Program implementation
* If program testing provides satisfactory results, the executable program can be used to handle data processing activities of the organization in the real environment.
* This is called program implementation.
  Program maintenance and update
* Program maintenance means to make simple corrective actions in order to run the computer program to meet data processing requirements of the organization. 
* Generally software maintenance agreements can be signed  with outsourcing or in-house maintenance personnel can be used for program maintenance.
 *Program updating means making structured changes to the existing programs or introducing a new set of programs to meet new data processing requirements of the organization.
Program documentation
* Program documentation means to keep or record information related to all the activities of the computer programming. 
*Although documentation appears as the last step in the programming process, it is actually performed throughout the entire process.
 * Documentation consists of materials generated during each step.
*E.g.: problem analysis report, algorithm, program listing, test reports, maintenance and update information, user manuals and training materials.
The Characteristics of a Good Computer Program
1. Reliability: The program should provide correct results at all times and should be free from errors.  
2. Maintainability: The existing program should be able to change or modify to meet new requirements.  
3. Portability: The program should be able to transfer to a different computer system.  
4. Readability: The program must be readable and understandable with the help of documentation.  
5. Performance: The program should handle the task more quickly and efficiently.  
6. Storage saving: The program should be written with the least number of instructions. 

No comments: