Académique Documents
Professionnel Documents
Culture Documents
Development
By:
Suryakant Kamble
1
What are we doing today?
Introduction of:
C Summary
Objects
Basic Terminology
C++
2
Beginning C Programming
Basic Computer Model
Input CPU Output
Memory
Instructions
+
Data
LOAD A
Assembly Languages ADD B
STORE C
C libaray
hello.c hello.obj
Hello, World
1. /* Hello, world program */
2. #include <stdio.h>
3.
4. int main()
5. {
6. printf("hello, ");
7. printf("world\n");
8. return 0;
9. }
Editing: Turbo C++,Borland Compiler.
Compiling: Alt + F9
Executing:Ctrl + F9
Basic Programming Concepts
Comment To explain what the program is for and why it is
the way it is.
Preprocessing Done before the program is compiled.
To include header files containing information about C libraries
Statement A line of code that tells computer to perform
some action. Always ended with a
semicolon(;).
Invoking functions
Function A module often consisting of a set of statements.
Two functions in the hello world program: main, printf
Escape Sequences
Escape Sequences are used to control printf to do
something other than printing characters.
9. printf("a+b=%f\n",a+b);
10. printf("a-b=%f\n",a-b);
11. printf("a*b=%f\n",a*b);
12. printf("a/b=%f\n",a/b);
13.}
Assignment
1. /* Arithmetic operators */
2. #include <stdio.h>
3.
4. int main()
5. {
6. int a,c;
7. int b=4;
8. a=3;
9. c=a+b;
10. printf(“Sum: %d + %d -> %d\n”,a,b,c);
11. a++;b--;
12. prinf(“Now a=%d and b=%d\n”,a,b);
13. return 0;
14.}
What is Object Oriented Programming?
16
What is an object?
Tangible Things as a car, printer, ...
Roles as employee, boss, ...
Incidents as flight, overflow, ...
Interactions as contract, sale, ...
Specifications as colour, shape, …
17
So, what are objects?
18
Why do we care about objects?
Modularity - large software projects can be split up
in smaller pieces.
Reusability - Programs can be assembled from pre-
written software components.
Extensibility - New software components can be
written or developed from existing ones.
19
Example: The Person class
#include<string>
#include<iostream>
class Person{ private
data
char name[20];
int yearOfBirth;
public: public
void displayDetails() { processes
cout << name << " born in "
<< yearOfBirth << endl;
}
//...
};
The two parts of an object
Object = Data + Methods
= +
21
Basic Terminology
Abstraction is the representation of the essential features of
an object. These are ‘encapsulated’ into an abstract data
type.
22
Basic Terminology:
Inheritance
A car is a vehicle
A dog is an animal
A teacher is a person
23
Basic Terminology:
Polymorphism
Polymorphism means “having many forms”.
It allows different objects to respond to the same
message in different ways, the response specific to the
type of the object.
E.g. the message displayDetails() of the Person class should give
different results when send to a Student object (e.g. the enrolment
number).
24
Basic Terminology:
Aggregation
Aggregation describes a “has a” relationship. One
object is a part of another object.
A car has wheels.
25
Basic Terminology:
Behaviour and Messages
The most important aspect of an object is its behaviour
(the things it can do).
A behaviour is initiated by sending a message to the
object (usually by calling a method).
26
The two steps of Object Oriented
Programming
27
Historical Notes
C++ owes most to C.
Other ancestors are Simula67
and Algol68. C++ 1987
First versions of C++ in 1980 under the name “C with
classes”. Since 1983 the name C++ is used.
1990: ANSI/ISO 9899 defines a standard for C
1998: ISO/IEC 14882 specifies the standard for C++
28
C++ and C
C is a subset of C++.
Advantages: Existing C libraries can be used, efficient
code can be generated.
But: C++ has the same caveats and problems as C (e.g.
pointer arithmetic,…).
C++ can be used both as a low level and as a high level
language.
29
C++ and Java
Java is a full object oriented language, all code has to go
into classes.
C++ - in contrast - is a hybrid language, capable both of
functional and object oriented programming.
30
Books
Teach Yourself C++ in 10 minutes,
J. Liberty, SAMS 1999.
C++ - How to program, Deitel & Deitel, Prentice Hall,
2001.
Object Oriented Programming with C++, David
Parson, Letts Educational, London 1997.
31
Websites
A C++ online tutorial:
http://www.cplusplus.com/doc/tutorial/
The C++ FAQ:
http://www.parashift.com/c++-faq-lite
The homepage of Bjarne Stroustrup, the inventor of C++:
http://www.research.att.com/~bs
ny m ore!
y, ma
32 An d man