12.01.2015 Views

C++ Programming Language - Princess Sumaya University for ...

C++ Programming Language - Princess Sumaya University for ...

C++ Programming Language - Princess Sumaya University for ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Object Oriented<br />

<strong>Programming</strong> <strong>Language</strong><br />

Dr. Arafat Awajan<br />

<strong>Princess</strong> <strong>Sumaya</strong> <strong>University</strong> <strong>for</strong> Technology<br />

awajan@psut.edu.jo<br />

cpp@psut.edu.jo<br />

Amman - Jordan


Chapter One<br />

Introduction To OOP<br />

1. 1. <strong>Programming</strong> Concepts<br />

1. 2. Unstructured <strong>Programming</strong><br />

1. 3. Structured (Procedural) <strong>Programming</strong><br />

1. 4. Modular <strong>Programming</strong><br />

1. 5. Object Oriented <strong>Programming</strong><br />

1. 6. History of <strong>C++</strong><br />

1. 7. <strong>Programming</strong> in <strong>C++</strong><br />

1. 8. <strong>C++</strong> features<br />

1. 9. Typical <strong>C++</strong> Environment<br />

Dr. Arafat Awajan - PSUT - 2004 2


Chapter One<br />

Introduction To <strong>C++</strong><br />

1. 10. First Program<br />

1. 11. Basic elements of the language<br />

1. 12. Standard Types<br />

1. 13. Variables<br />

1. 14. Constants<br />

1. 15. Operators<br />

1. 16. Examples and Exercises<br />

Dr. Arafat Awajan - PSUT - 2004 3


1. 1. <strong>Programming</strong> Concepts<br />

a. Solving Problem:<br />

What is a problem: data + questions<br />

Solving the problem means finding the answers<br />

b. Steps of Solving Problems<br />

Analyzing the problem: input and output description<br />

Developing a solution: an algorithm<br />

Writing a program: <strong>Programming</strong> <strong>Language</strong><br />

Environment<br />

Compiling: Errors AND warning<br />

Testing<br />

Maintaining<br />

Dr. Arafat Awajan - PSUT - 2004 4


1. 1. <strong>Programming</strong> Concepts<br />

c. Evolution of programming Techniques<br />

Unstructured programming: 1950s<br />

Structured <strong>Programming</strong>: 1970s<br />

Modular <strong>Programming</strong><br />

Object Oriented <strong>Programming</strong>: 1990s<br />

d. Software requirements<br />

Time and money<br />

Per<strong>for</strong>mance and efficiency<br />

test, reuse, maintenance,<br />

OOP<br />

Dr. Arafat Awajan - PSUT - 2004 5


1. 2. Unstructured programming<br />

a. During the 1950s<br />

b. Now: the beginners<br />

c. Features<br />

The program contains only one bloc(Main)<br />

The main program directly operates on global data.<br />

Program<br />

Main + Global Data<br />

Dr. Arafat Awajan - PSUT - 2004 6


1. 3. Structured programming<br />

(Procedural)<br />

a. Research during the 1960s<br />

b. Basic idea<br />

Top Down Design divide and conquer<br />

c. Aims<br />

programs that are clearer, easier to develop,to test<br />

and to modify<br />

d. A program is a set of procedures/Functions<br />

called when needed<br />

e. <strong>Language</strong>s:<br />

Pascal (1970), C (1971), ADA (1980)<br />

Dr. Arafat Awajan - PSUT - 2004 7


Main Program<br />

Procedure<br />

Dr. Arafat Awajan - PSUT - 2004 8


1. 4. Modular programming<br />

a. Basic idea<br />

B. Example<br />

Functions / procedures with the same functionality are<br />

grouped into separate modules.<br />

Each Module can have its own data.<br />

Program<br />

Module 1 Module 2<br />

Data<br />

Data<br />

Procedure1 Procedure1 Procedure2 ..<br />

Dr. Arafat Awajan - PSUT - 2004 9


1. 5. Object Oriented programming<br />

( O O P )<br />

a. Developed during 1980s<br />

b. Aims<br />

building software quickly, correctly, and economically,<br />

more understandable, better organized, easier to<br />

maintain, modify and debug<br />

c. Definition<br />

- Objects are Independent and Reusable software<br />

components<br />

- An object is a meaningful software unit that describes<br />

data and related functions<br />

- an object models things in the real worlds<br />

Dr. Arafat Awajan - PSUT - 2004 10


1. 5. Object Oriented programming<br />

( O O P )<br />

d. Focus on objects (things)<br />

treating data and the procedures that act upon the data<br />

as a single entity - object. (encapsulation)<br />

e. Fundamental Capabilities of OOP languages:<br />

Objects(data + functions)<br />

Classes (ADT)<br />

Inheritance<br />

Polymorphism (Poly == Many, Morph == Form)<br />

f. <strong>Language</strong>s<br />

Smalltalk, <strong>C++</strong>(1985), and JAVA(1995)<br />

Dr. Arafat Awajan - PSUT - 2004 11


1. 5. Object Oriented programming<br />

( O O P )<br />

g. Examples<br />

A car is a collection of attributes: type, engine, color, size,<br />

doors, year, and so <strong>for</strong>th.<br />

A car can be described as a collection of actions: move,<br />

speed up, stop, park, and so on.<br />

Car ----> class<br />

My_Car is an object of the class car.<br />

----> The Type of My_Car<br />

----> Move My_Car<br />

----> Stop My_Car<br />

Dr. Arafat Awajan - PSUT - 2004 12


1. 5. Object Oriented programming<br />

( O O P )<br />

h. Objects<br />

They are created from a class<br />

j. Classes:<br />

They contain functions to implement behaviors<br />

They contains data to implement attributes<br />

They are reusable<br />

A new class can be generated by an old one:<br />

Sport_Car From Car<br />

Dr. Arafat Awajan - PSUT - 2004 13


1. 6. History of <strong>C++</strong><br />

1967: Basic Combined programming <strong>Language</strong><br />

BCPL developed by Martin Richards<br />

1970: The language B developed by Ken Thompson<br />

at Bell Labs.<br />

B is used to create the Operating System UNIX<br />

1972: C was evolved from B by Denis Ritchie at Bell<br />

Labs.<br />

C is B + types + Structured programming<br />

features.<br />

Dr. Arafat Awajan - PSUT - 2004 14


1. 6. History of <strong>C++</strong><br />

1985: <strong>C++</strong> was developed by Bjarne Stroustrup at<br />

Bell labs.<br />

<strong>C++</strong> is an extension of C: Better C + OOP<br />

1989: ANSI/ISO C<br />

1990s:V<strong>C++</strong> developed by Microsoft<br />

( <strong>C++</strong> plus Visual language features …)<br />

1999: ANSI/ISO <strong>C++</strong><br />

Now: <strong>C++</strong> is the leading edge programming<br />

language<br />

Dr. Arafat Awajan - PSUT - 2004 15


C#<br />

V<strong>C++</strong><br />

<strong>C++</strong><br />

C<br />

Dr. Arafat Awajan - PSUT - 2004 16


1. 7. <strong>Programming</strong> in <strong>C++</strong><br />

a. Building <strong>C++</strong> programs<br />

A <strong>C++</strong> program built from pieces called classes and<br />

functions<br />

b. Using <strong>C++</strong> standard library<br />

Rich collection of existing classes and functions<br />

c. Using Third-Party libraries<br />

Example: MFC<br />

Microsoft Foundation Classes<br />

Dr. Arafat Awajan - PSUT - 2004 17


1. 7. <strong>Programming</strong> in <strong>C++</strong><br />

d. Good program features:<br />

Clarity (Style, elegance, structure)<br />

Per<strong>for</strong>mance ( time efficiency, space efficiency)<br />

Correctness ( testing results)<br />

Finiteness<br />

Data descriptions( Input data and output results)<br />

Dr. Arafat Awajan - PSUT - 2004 18


1. 8. <strong>C++</strong> Features<br />

a. Structured (procedural) language ( a better C)<br />

b. Object Oriented language<br />

c. Portable language (Hardware Independent)<br />

d. Rich language: Operators, libraries, ...<br />

e. Complex language<br />

f. Used <strong>for</strong> application programming and system<br />

programming<br />

g. Most popular OOPL<br />

Dr. Arafat Awajan - PSUT - 2004 19


1.8. <strong>C++</strong> Features<br />

Enhancements and improvements <strong>C++</strong> offers to C:<br />

a. Default function arguments<br />

b. Flexible placement of variable declarations<br />

c. The scope resolution operators<br />

global and local variables with the same name<br />

d. inline function<br />

e. Enumeration<br />

f. Function overloading<br />

Dr. Arafat Awajan - PSUT - 2004 20


1. 9. Typical Environment of <strong>C++</strong><br />

a. Developing <strong>C++</strong> programs:<br />

Edit (text file with the extensions *.ccp)<br />

Preprocess<br />

Compile (object file)<br />

Link (executable file)<br />

Load<br />

Execute<br />

b. Examples of environment<br />

Borland Turbo <strong>C++</strong><br />

Visual <strong>C++</strong><br />

Unix<br />

Dr. Arafat Awajan - PSUT - 2004 21


1. 10. First Programs<br />

a. Example 1<br />

// this is my first program<br />

// It prints a line of text<br />

#include <br />

int main()<br />

{<br />

}<br />

cout


1. 10. First Programs<br />

c. Example 2<br />

// there are multiple ways to print text<br />

#include <br />

int main() {<br />

cout


1. 11. Basic elements of the language<br />

a. Characters<br />

b. Words<br />

Letters: a ... z, and A … Z<br />

Digits: 0 … 9<br />

Special characters<br />

What is a word<br />

Reserved words<br />

User Defined Words(Identifiers)<br />

Rules <strong>for</strong> building UDWs.<br />

c. statements<br />

Statement: set of C-tokens that instructs the computer<br />

to per<strong>for</strong>m some task.<br />

A statement must be ended by ;<br />

Dr. Arafat Awajan - PSUT - 2004 24


1. 11. Basic elements of the language<br />

d. Blocs of statements<br />

A set of statements (0, 1, 2, …) delimited by the two<br />

characters { and }.<br />

e. Functions<br />

Code that solves a subproblem<br />

A function consists of two parts: Header and Body<br />

The function main is an example.<br />

f. Classes<br />

Data and functions: description and relationships<br />

g. Programs<br />

classes and functions, one of them must be named main.<br />

h. Projects<br />

Dr. Arafat Awajan - PSUT - 2004 25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!