Programming Languages: Types and Uses
1. Introduction
C Programming is a computer language that is structured and disciplined approach to program design. It’s a good systems programming language. This is faster than java, more predictable performance and it has low level operations and it has a lot scope for bugs.
This C programming has no Boolean type . It is used by using int false is zero and true is non-zero
A simple C program
int main()Text surrounded by /* and */ is ignored by computer and it is used to describe the program
#include<stdio.h> Preprocessor directive tells the computer to load contents of a certain file
<stdio.h> allows standard input/output operations
C++ programs contain one or more functions, exactly one of which must be main and Parenthesis is used to indicate a function . int means that main “returns” an integer value and braces indicate a block.The bodies of all functions must be contained in braces .
printf( “Welcome to C!n” );
Instructs computer to perform an action specifically and prints string of characters within quotes.Entire line is called a statement. All statements must end with a semicolon.””- means escape character. Indicates that printf should do something out of the ordinary.”n” is the newline character
return 0; A way to exit a function.
return 0, in this case, means that the program terminated normally .
Right brace } Indicates end of main has been reached.
Linker When a function is called, linker locates it in the library and Inserts it into object program. If function name misspelled, linker will spot error because it cannot find function in library.
Calculator
This is use very frequently in everyday life by almost everyone .
In this calculator we can only perform operations like addition (+), subtraction (-), division (%), multiplication(*), only integer valued functions. We get accurate values too .
2. Scientific Calculator
This calculator can perform all the operations that normal calculator can do and it can also perform the operations like
Trigonometry: Sine, Cosine, Tangent, Inverse^-1 Angles: DEG, DMS, Time
Memories: M, K1, K2 Programs: LRN, COMP, HLT, (x)
3. C-Programming
3.1 What is c- programming ?
A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks . The term programming language usually refers to high-level languages, such as BASIC, C, C++, COBOL, FORTRAN, Java, and Pascal. Each language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions. Regardless of what language you use, you eventually need to convert your program into machine language so that the computer can understand it. There are two ways to do this: compile the program , interpret the program .
3.2 Programming process
3.2.1 Analyze the Problem
A programmer must know what information will go into the software, how it will process the information, and what will result. All software must work with three concepts to be successful:
Input: Information that comes from an external source and enters the software an. Input can come from typing on a keyboard, from records in a database, or from clicking on image with the mouse
Processing: Manages information according to a piece of software’s logic. Processing is what the software does to the input it receives. This can be anything from adding a few numbers together to mapping the earth’s climate.
Output: The information software produces after it has processed input. Output can appear on a computer screen, in a printout, or in records in a database.
3.2.2 Develop an Algorithm
Algorithms are the steps needed to solve a problem using pseudocode or flowcharts. After creating an algorithm, programmers will check it. A logic error is a mistake in the way an algorithm solves a problem. Programmers check their algorithms by inputting test data and checking the logic by hand or with a calculator.
3.2.3. Document the Program: pseudocode
Pseudocode uses English statements to create an outline of the necessary steps for a piece of software to operate. Programmers call these steps an algorithm. An algorithm is a set of specific steps that solves a problem or carries out a task. While there is no set of rules for writing pseudocode, it usually follows rules such as: Using simple English, Putting one command on a line, Placing any important words in bold, Starting from the top and work toward the bottom, Separating processes with spaces to form modules.
3.2.4 Write Code for the Program
Code is when a programmer translates an algorithm into a programming language.
3.2.5 Run the Program
Programmers also use program flowcharts to plot the software’s algorithm. A program flowchart is a graphical depiction of the detailed steps that software will perform. Unlike pseudocode, which has less structure, in flowcharts programmers must use symbols.
3.2.6 Testing the programs
Debugging – the process of finding errors in software code.
Bugs – are a common name for software errors. When programmers debug code, they look for syntax, run-time, and logic errors.
Syntax errors – mistakes in a software code’s grammar. If you are supposed to use a semi-colon (;) and you use a colon (:) instead, you have made a syntax error.
Run-time errors – mistakes that occur when a programmer runs the software code .
Logic errors – mistake made in the way an algorithm solves a problem.
4. Types of programming
4.1 Object-oriented programming
Object-oriented programming (OOP) is any programming language that uses objects to code software. An object instance is an exact copy of an object in OOP. An event-driven language responds to actions users perform on the program.
It’s an event when you click on a button, use a pull-down menu, or scroll down a window. In an event-driven language, each event triggers the program to action.
An OOP program models the world of active objects. An object may have its own “memory,” which may contain other objects. An object has a set of methods that can process messages of certain types.
A method can change the object’s state, send messages to other objects, and create new objects. An object belongs to a particular class, and the functionality of each object is determined by its class. A programmer creates an OOP application by defining classes.
4.2 The Main OOP Concepts
Inheritance: a subclass extends a superclass; the objects of a subclass inherit features of the superclass and can redefine them or add new features.
Event-driven programs: the program simulates asynchronous handling of events; methods are called automatically in response to events.
OOP Benefits
Facilitates team development and Easier to reuse software components and write reusable software. Easier GUI (Graphical User Interface) and multimedia programming .
4.3 Web-programming
Hyper Text Markup Language (HTML) is the basic language for web programming.
JavaScript – a scripting language that allows you to add interactivity and other features to a Web page.
Java Applets – A small piece of software that enables applications to run on a Web page.
Dynamic HTML – combines cascading style sheets, JavaScript, etc., to bring high interactivity to Web sites.
VBScript – an interpreted scripting language based on Visual Basic. It is similar to JavaScript but only Microsoft’s Internet Explorer Web browser can use it.
Software Development Tools
Editor: programmer writes source code for te program.
Compiler: translates the source into object code (instructions specific to a particular CPU).
Linker: converts one or several object modules into an executable program.
Debugger: stepping through the program “in slow motion,” helps find logical mistakes (“bugs”).
5. Array
Group of consecutive memory locations and Same name and type To refer to an element, specifying Array name and Position number
Format: arrayname[position number]
First element at position 0 and n element array named c: c[0], c[1]…c[n-1]
Array elements are like normal variables
c[0] = 3;
printf( “%d”, c[0] );
Perform operations in subscript. If x = 3,
c[5-2] == c[3] == c[x]
When declaring arrays, specify: Name, Type of array, Number of elements
arrayType arrayName[ numberOfElements ]; int c[ 10 ]; float myArray[ 3284 ];
Declaring multiple arrays of same type and Format similar to regular variables
int b[ 100 ], x[ 27 ];
Examples Using Arrays
Initializers int n[5] = {1, 2, 3, 4, 5 };
If not enough initializers r there, rightmost elements become 0 and If too many are there then it’s a syntax error.
int n[5] = {0}
All elements is 0
C arrays have no bounds checking and
If size is omitted, initializers determine it int n[] = { 1, 2, 3, 4, 5 };
5 initializers, therefore 5 this iselement array
Character arrays
String “hello” is really a static array of characters and Character arrays can be initialized using string literals
char string1[] = “first”;
null character ‘