Beruflich Dokumente
Kultur Dokumente
Functional Programming
Scheme, ML
Functions are first-class objects
Logic Programming
Prolog
Declarative Programming
Imperative Programming
C, Java, Pascal
Focuses on change of state
Main Program
Global Data
Function1
Function2
Function3
Local Data
Local Data
Local Data
Advantages
Its relative simplicity, and ease of implementation of compilers
and interpreters
The ability to re-use the same code at different places in the
program without copying it.
An easier way to keep track of program flow.
The ability to be strongly modular or structured.
Disadvantages
Needs only less memory.
Data is exposed to whole program, so no security for
data.
Difficult to relate with real world objects.
Difficult to create new data types reduces
extensibility.
Importance is given to the operation on data rather
than the data.
Main Program
Global Data
Function1
Local
Data
Module 1
Function2
Function3
Function4
Function5
Local Data
Local Data
Local Data
Local Data
Module 2
Module 3
Disadvantages
Repletion of code in several places within a single program.
This long code in turn makes it difficult to effectively locate
and fix errors in the program.
lacks information hiding.
Clash of variables when different parts of the program
overwrite the same variable.
Classes
Objects
Data Abstraction
Encapsulation
Inheritance
Polymorphism
Message passing
Extensibility
Persistence
Constructors
Delegation
Generality
Multiple Inheritance
Object-Oriented Programming
An object is anything that can be represented by data in
a computers memory and manipulated by a computer
program.
Numbers
Object-Oriented Programming
An object is anything that can be represented by data in
a computers memory and manipulated by a computer
program.
Text
Object-Oriented Programming
An object is anything that can be represented by data in
a computers memory and manipulated by a computer
program.
Pictures
Object-Oriented Programming
An object is anything that can be represented by data in
a computers memory and manipulated by a computer
program.
Sound
Object-Oriented Programming
An object is anything that can be represented by data in
a computers memory and manipulated by a computer
program.
Video
Object-Oriented Programming
An object is anything that can be represented by data.
Object-Oriented Programming
To a computer, an object is
simply something that can be
represented by data in the
programs.
Object-Oriented Programming
The data that represent the
object are organized into a set
of properties.
The values stored in an
objects properties at any one
time form the state
of an object.
Name:
PA 3794
Owner:
US Airlines
Location: 39 52 06 N 75 13 52 W
Heading:
271
Altitude:
19 m
AirSpeed: 0
Make:
Boeing
Model:
737
Weight:
32,820 kg
public:
char name[20];
int age;
char sex;
listen();
speak();
talk();
Attributes
Message
Passing
Member
Functions
Data Hiding
Forms of Inheritance
A
B
(a) Single Inheritance
A
B
C
D
(b) Multipath Inheritance
41
Keywords
Identifiers
Constants
Strings
Operators
Procedural language.
Data is not secured.
Low level language
Top down approach
Function driven
No Function overloading
No Namespace feature
C++
C++
Keywords
Identifiers
Constants
Strings
Operators
Keywords
Identifiers
Constants
Strings
Operators
C++ Data
Types
User-defined type
Built-in
type
structure
union
class
enumeration
Integral
type
int
Derived type
array
function
pointer
reference
Floating
type
Void
char
float
double
Type
Bytes
Range
char
-128 to 127
signed: -128 to 127
unsigned: 0 to 255
short int
-31768 to 32767
signed: -32768 to 32767
unsigned: 0 to 65535
int
-32768 to 32767
signed: -31768 to 32767
unsigned: 0 to 65535
long int
-2147483648 to 2147483647
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
float
3.4E-38 to 3.4E+38
double
1.7E-308 to 1.7E+308
long double
10
3.4E-4932 to 1.1E+4932
Arrays
Values of similar type stored in continuous memory locations.
int a[10]; char string[3]=xyz;
Functions
Set of statements to perform specific tasks
Pointers
Special variables to store the memory location of other
variables.
Used in referencing memory.
Concept of constant pointer introduced in c++.
Keywords
Identifiers
Constants
Strings
Operators
123
12.34
037
0x2
C++
A
Lab
//decimal integer
//floating point integer
//octal integer
//Hexa decimal
//string constant
//character constant
//wide-character constant
Using enum
enum{x,y,z};
enum{x=200,y=300,z=400};
enum{off,on};
Keywords
Identifiers
Constants
Strings
Operators
Keywords
Identifiers
Constants
Strings
Operators
Constant expressions
Integral expressions
Float expressions
Pointer expressions
Relational expressions
Logical expressions
Bitwise expressions
The if statement
Simple if statement
if(expression)
{
statement 1;
}
statement 2;
statement 3;
if..else statement
if(expression)
{
statement 1;
}
else
{
statement 2;
}
statement 3;
do
{
statement1;
}
while(condition);
statement2;
while(condition)
{
statement1;
}
statement2;
for (intialization;condition;increment)
{
statement1;
}
statement2;
Function declaration
return-type function-name (argument-list);
void show();
float volume(int x,float y,float z);
Function definition
return-type function-name(argument-list)
{
statement1;
statement2;
}
Function call
function-name(argument-list);
volume(a,b,c);
int main()
{
return(0);
}
Parameter Passing
Pass by value
Pass by reference
Reference variable
Pointers
swap(m,n);
swap(&m,&n);
Parameter passing
Return by reference
add(5,10);//uses prototype 1
add(15,10.0);//uses prototype 4
add(12.5,7.5); //uses prototype 3
add(5,10,15); //uses prototype 2
add(0.75,5); //uses prototype5
Structures Revisited
Limitations
C doesnt allow it to be treated like built-in data types.
struct complex{float x; float y;};
struct complex c1,c2,c3;
c3=c1+c2;//Illegal in C
Class declaration:
class class_name
{
private:
variable declarations;//class
function declarations;//members
public:
variable declarations;//class
function declarations;//members
};//Terminates with a semicolon