computer programming. introduction to c++ history merges notions from smalltalk and notions from c...

15
COMPUTER PROGRAMMING

Upload: marjory-reynolds

Post on 24-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

COMPUTER PROGRAMMING

Page 2: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

Introduction to C++ History

• Merges notions from Smalltalk and notions from C• The class concept was borrowed from Simular67• Developed by Bjarne Stroustrup at Bell Labs• Bell Lab's internal standard language for system programming• Keeps C's original executing speed while enabling object-oriented

programming (OOP).

Page 3: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

History of C and C++

• C evolved from two other programming languages, BCPL and B

• ANSI and C• The “American National Standards Institute “Established

worldwide standards for C programming• 1980: “C with Classes”

Improve program structure.

Maintain run-time efficiency.• 1985: C++ 1.0• 1995: Draft standard.

Page 4: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

History of C and C++

• Provides capabilities for object-oriented programming.• What is Objects?• Objects are reusable software components that model

things in the real world”• Object-oriented programs are easy to understand, correct

and modify

Page 5: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

C versus C++• Claimed advantages:

1. Faster development time (code reuse)

2. Creating/using new data types is easier

3. Memory management: easier more transparent

4. Stricter syntax & type checking => less bugs

5. Data hiding easier to implement

6. OO concepts in C++

Page 6: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

Types of programming

• Procedural Programming.• Modular Programming.• Object-Oriented Programming.

Page 7: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

Procedural Programming

• The original programming paradigm is

“Decide which procedures you want;

use the best algorithms you can find”• The focus is on the processing - the algorithm needed to

perform the desired computation.• Languages support this paradigm by providing facilities for

passing arguments to functions and returning values from functions.

Page 8: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

Procedural Programming

• The literature related to this way of thinking is filled with discussion of ways to pass arguments, ways to distinguish different kinds of arguments, different kinds of functions, etc.

Page 9: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

Modular Programming

• The emphasis in the design of programs has shifted from the design of procedures and toward the organization of data.

“Decide which modules you want; partition

the program so that data is hidden in modules”• A module is a set of related procedures with data they

manipulate.• This paradigm is also known as data-hiding principles

Page 10: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

Object-Oriented Programming

Objects:• Reusable software components that model real world

items.• Meaningful software units

- Date objects, time objects, pay check objects,

invoice objects, audio objects, video objects,

file objects, record objects, etc.

- Any noun can be represented as an object.• It is claimed that this is more understandable, better

organized and easier to maintain than procedural programming.

Page 11: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

C++ OOP Features

• C++ is a hybrid language (can program in procedural or OO fashion or both)

• Concepts for Object Orientation:• Encapsulation (Data-hiding)• Inheritance• Polymorphism• Ability to be dynamic (concept of objects)

Page 12: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

A Typical C++ Environment

• Phases of C++ Programs:

1- Edit

2- Preprocess

3- Compile

4- Link

5- Load

6- Execute

Loader

PrimaryMemory

Program is created inthe editor and storedon disk.

Preprocessor programprocesses the code.

Loader puts programin memory.

CPU takes eachinstruction andexecutes it, possiblystoring new datavalues as the programexecutes.

CompilerCompiler createsobject code and storesit on disk.

Linker links the objectcode with the libraries,creates a.out andstores it on disk

Editor

Preprocessor

Linker

 CPU

PrimaryMemory

.

.

.

.

.

.

.

.

.

.

.

.

Disk

Disk

Disk

Disk

Disk

Page 13: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

C++ INPUT AND OUTPUT• C++ programs make use of a library called iostream

(input / output stream library).• Input/output

• cin• Standard input stream• An input stream gets data bytes from some input

device and routes them to a program.• Normally keyboard

Page 14: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

C++ INPUT AND OUTPUT• Cout

• Standard output stream• An output stream is something that takes character

data and gets them to an output device.• Normally computer screen

• cerr• Standard error stream• Display error messages

Page 15: COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed

First program

// my first program in C++

#include <iostream>

using namespace std;

int main ()

{

cout << "Hello World!";

Return o;

}

Hello World!