Lec6 Programming Structure
Lec6 Programming Structure
Programming Fundamental
By
Arooba Akhtar
1
Programming Languages
• A set of words, symbols, and codes used to write programs.
• A programming language is a set of rules that provides a way
of telling a computer what operations to perform.
• describe computation in a machine-readable and human-
readable form.
• The grammatical rules are called syntax.
• Syntax : spelling and grammar of a programming language
2
Types of Programming Languages
3
Low Level Language: Machine Language
• Instructions written in binary form i.e. 0 or 1.
4
Assembly Language
• One step higher than machine language.
• Because symbols, English like words are used instead
of binary code.
• Easy to write and modify programs as compared to
machine language.
• Mostly used for writing system software.
• Also called Second Generation Language.
5
High Level Language
• Close to human language.
6
1. Procedural Language
• Also called third generation languages.
• Program is defined.
• Execute in same sequence as they are written.
• Example: FoRmula Translation (FORTRAN), BASIC
(Beginner All Purpose Symbolic Instruction Code),
etc
7
• FORTRAN - FoRmula Translation
• Used for engineering and scientific use
• BASIC - Beginner All Purpose Symbolic Instruction Code
• Used for education purpose
• COBOL – Common Business Oriented Language
• Used for business applications
• Lengthily program but easy to read and write and
maintain as compared to FORTRAN and BASIC
• PASCAL
• For both scientific and business applications
8
• C
• is a general-purpose, practical, commanding computer
programming language developed in 1972 by Dennis M.
Ritchie at the Bell Telephone Laboratories to develop the UNIX
operating system.
9
2. Non-Procedural Language
• Also called fourth generation languages.
• Used in Databases and report generation
• Reduce errors in program
• SQL (Structured Query Language)
• Database query language.
• RPG (Report Program Generation)
• Use to generate business report
10
3. Object oriented Language
11
3. Object oriented Language
• C++
• Bjarne Stroustrup from Bell Lab developed C++ in 1980
• C++ is subset of C.
• Technique OOP
• Java
• Is a hih-level language.
• It was developed in 1980 at Bell Laboratories.
• s
12
Language Translators
Compiler:
• Is a program that converts the instruction of HLL into
machine language as a whole.
• Program written in HLL is called source program while
machine code is called object program
• Also checks syntax errors in program
13
Language Translators
• Interpreter:
• Translates one line at a time and executes it and so on
• Advantage of interpreter over compiler is that it founds
error immediately
• Drawback is it is not efficient because it doesn’t produce
object program
14
Basic Structure of a Program
• Documentation :
• Consists of comments, some description of the program,
programmer name and any other useful points that can be
referenced later
• Link
• Provides instruction to the compiler to link function from
the library function
• main() function
• Declaration part:
• all the variables are declared
• Execution part:
• begins with the curly brackets and ends with the curly close
bracket.
• Sub Program Section
15
• All the user-defined functions are defined
Basic Structure of a Program
• Preprocessor Directive: is an instruction given to compiler before
the execution of actual program.
• It is also called compiler directive.
• The preprocessor directives are proceeded by a program called
preprocessor.
• It is the part of C/C++ compiler.
• The preprocessor directives start with hash symbol #.
16
Basic Structure of a Program
• Include preprocessor: directive used to include header files in the
program. The syntax of using this preprocessor directive is:
C++
#include<iostream>
using namespace std;
int main()
{
block of statements;
return 0;
}
17
Basic Structure of a C++ Program
• # include <iostream> [preprocessor directives]
• tells compiler to include this iostream file in the program
• input output file contains the definitions of common input output
functions
• Header files are collection of standard library functions to perform
different tasks
• int main ()
• main() is name and int is its return type
• cin>>: input
• cout<<: output e.g Hello! World
19
Basic Structure of a C++ Program
• cout Syntax
cout<<“user defined message";
• cin Syntax
cin>> input from user ;
Example:
cout<<“Enter a number”;
cin>>num;
20
Basic Structure of a C++ Program
#include <iostream>
using namespace std;
int main()
{
int a;
cout<<"enter a value“<<endl;
cin>>a;
cout<<“value of a is : ”<<a;
return 0;
21