topic introduction
TRANSCRIPT
-
8/8/2019 Topic Introduction
1/63
OO
PProfessor: Aishy AmerCOEN243 Topic 01
Introduction to
Programming Methodology I
IntroductionOverview of Computers
ComputerHardware
ComputerSoftware
Programming Languages
Processing a Program
Software Development Method
-
8/8/2019 Topic Introduction
2/63
OO
P
2
Introduction
OOP:
increasingly important both in academia and
industry
C++:
emerging as a language of choice
Because it combines
efficiency of C & the disciplined approachto software
design using interacting modules
-
8/8/2019 Topic Introduction
3/63
OO
P
3
Introduction
COEN243: Object-Oriented Programming (OOP) with C++
Modular, general, maintainable programs Modular: classes and functions
General: can be applied formany applications/situations
Maintainable: a code thatthe maintainerunderstand
Focus: well-designed programs
meth
odologies
an
d con
cepts
following software engineering principles
C++ : very complex language be ready to workforlong hours
-
8/8/2019 Topic Introduction
4/63
OO
P
4
Introduction
#include // Use the iostream library
using namespace std; // Use the standard library namespace
int main() // The mainroutine ofthe program
{
// *** Declaration/ Variables
float A,B,C,delta, root1,root2;
// *** Read input from user
cout > B >> C;
// *** Computation
delta = B*B - 4*A*C ;
root1 = -B/(2*A) + sqrt(delta)/(2*A);
root2 = -B/(2*A) - sqrt(delta)/(2*A);
// *** Outputresults
cout
-
8/8/2019 Topic Introduction
5/63
OO
P
5
Introduction
-
8/8/2019 Topic Introduction
6/63
OO
P
6
1.1 Overview of Computers
Computers/ Programs:
toolsto solve real-world problems
Programs are used to simulate the behaviorof
real-world systems
Simulation:
reproduction ofselected aspects ofthe system
behaviorthrough experimentations
-
8/8/2019 Topic Introduction
7/63
OO
P
7
Overview of Computers
Very Large Scale Integration (VLSI)technology made computers affordable,smalland available to the public
Programming facilitatesthe use of computers
Programming has changed overtime:
Every few years a new programming language
Computer:
A device forcounting orcomputing
Two components: Hardware & Software
-
8/8/2019 Topic Introduction
8/63
OO
P
8
1.2 ComputerHardware
Every computer is organized roughly into six
parts
CPU - central processing unit decisions are made
computations are performed
input/outputrequests are delegated
Main Memory
Stores information being processed by the CPU
-
8/8/2019 Topic Introduction
9/63
OO
P
9
ComputerHardware
Secondary Memory
Stores data and programs
Input devices Allows people to supply informationto computers
Output devices
Allows people to receive information from computers
Networkconnection Modems/ Ethernet interface
-
8/8/2019 Topic Introduction
10/63
OO
P
10
ComputerComponents
-
8/8/2019 Topic Introduction
11/63
OO
P
11
Main Memory
Itstores
programs
data
results
Types of memory RAM
ROM
-
8/8/2019 Topic Introduction
12/63
OO
P
12
Main Memory (2)-27.2
354
0.005
75.62
Address Content
0
1024
1
Memory:
an ordered sequence
ofstorage locationscalled memory cells
Every cell has a content
1023
RTV0001
108ADD1024
107
STR0005109
-
8/8/2019 Topic Introduction
13/63
OO
P
13
Main Memory (3) To access cell info:
each cell has a unique address
Content may ormay not be meaningful to ourprogram
A cell =
A g rouping ofsmallerunits called bytes
A byte =
Amount ofstorage required to store a single
character
Numberof bytes percell varies
-
8/8/2019 Topic Introduction
14/63
OO
P
14
Main Memory (4) A byte :
Composed ofsmallerunits ofstorage called bits
Binary:
a numbering system oftwo numbers 0 & 1
Bit = Binary digit:
Smallest element a computercan deal with
0 1 2 3 4 5 6 7
byte
a bit
-
8/8/2019 Topic Introduction
15/63
OO
P
15
Main Memory (5) Assume a byte is composed of 1, 2,3, or8 bits
If 1 bit: it cantake 2 combinations
0 or
1 If 2 bits: it cantake 4 combinations
00 01 10 11
If 3 bits: 8 combinations
000 001 010 111
Often a byte = 8 bits
2^8=256 combinations orvalues
-
8/8/2019 Topic Introduction
16/63
OO
P
16
Secondary Memory & Storage
Semi permanent data-storage capability
Tape orDisk Hard disk
CD ROM
Secondary memory has much more storagecapacity
-
8/8/2019 Topic Introduction
17/63
OO
P
17
CPU
Brains ofthe computer
Arithmetic calculations are performed using theArithmetic/Logical Unit orALU
Control unit decodes and executes instructions
Arithmetic operations are performed usingbinary numbersystem
-
8/8/2019 Topic Introduction
18/63
OO
P
18
CPU (2) Fundamental building blockis a switch
Switches are made from ultra-small transistors
Examples The Pentium processorcontains aboutthree
milliontransistors
The Pentium Pro has about 5.5 million
transistors
-
8/8/2019 Topic Introduction
19/63
OO
P
19
Input/ Output Devices
Accessoriesthat allow computerto perform
specific tasks
Receiving information forprocessing Returnthe results of processing
Store information
Common input and output devices Printer Joystick CD-ROM
Keyboard Monitor
-
8/8/2019 Topic Introduction
20/63
OO
P
20
ComputerNetworks
LAN - Local area network
Organizational
WAN - Wide area network
Internet
World Wide Web Introduced 1989
Developed by European Laboratory forParticle Physics
-
8/8/2019 Topic Introduction
21/63
OO
P
21
1.3 ComputerSoftware
Applicationsoftware
Programs designed to perform specific tasksthat
are transparentto the user System software
Programsthatsupportthe execution and
development of otherprograms
Two majortypes
Operating systems
Translationsystems
-
8/8/2019 Topic Introduction
22/63
OO
P
22
Application Software
Applicationsoftware has made using
computers indispensable and popular
Common applicationsoftware Word processors
Desktop publishing programs
Spreadsheets Presentation managers
Drawing programs
-
8/8/2019 Topic Introduction
23/63
OO
P
23
Operating System (OS) Controls and managesthe computing resources
Importantservices of an OS
File system
Commands formanipulation ofthe file system
Perform input and output on a variety of devices
Management ofthe running systems
Examples Unix , Linux
MSDOS , Windows
-
8/8/2019 Topic Introduction
24/63
-
8/8/2019 Topic Introduction
25/63
OO
P
25
Programming Languages (2) Machine Language
Native tongue ofthe computer
Binary 0s and 1sthatspecify whatto do 0010 0000 0000 0100
1000 0000 0000 0101
0011 0000 0000 0110
High- Level Languages
Resemble human language (C++, C, Pascal) cost = price + tax;
-
8/8/2019 Topic Introduction
26/63
OO
P
26
Programming Languages (3) Language Standard
Syntax (grammatical form) (rules) Portable
programs used without modification
Example:
if(tax >10)price= price * 3;else if(tax>5)price=price*2;
-
8/8/2019 Topic Introduction
27/63
OO
P
27
Programming Languages (4) Source Program: tax.cc
Program you write
Object Program: tax.o Program translated from yourprogram
Executable Program: tax
Program translated from the object program
-
8/8/2019 Topic Introduction
28/63
OO
P
28
Programming Languages (5) Programming paradigm:
design philosophy thathelpsto
thinkabout problems & formulate solutions
Examples:
imperative languages
structured languages
object-oriented languages
-
8/8/2019 Topic Introduction
29/63
OO
P
29
Imperative Programming
A computer:
a large memory store
A program: a sequence of commandsstored inthe store
Emphasis onstored data
Examples: Assembly, Basic
-
8/8/2019 Topic Introduction
30/63
-
8/8/2019 Topic Introduction
31/63
OO
P
31
Structured Programming (2) Algorithms are the basis forthe functions
Highly structured
Top-down design Step-wise refinement
Abstraction:
Separation ofthe behaviorof a thing from itsrepresentation orimplementation
-
8/8/2019 Topic Introduction
32/63
OO
P
32
Object Oriented Programming
(OOP) Real-world problemshave objects
Objects define the problem
OOP promotesthinking aboutsoftware in away that modelsthe real world
OOP supports good software engineering
-
8/8/2019 Topic Introduction
33/63
OO
P
33
OOP (2) Emphasis is on
the objects (data) and
h
owto ma
nipula
te
them
A program:
A networkof objects withtheirattributes
Attributes = data and operations
There isnot one programming language best for
every type of problems
-
8/8/2019 Topic Introduction
34/63
OO
P
34
Object Example
Real-world problem: Automated banking system
A BankAccount = a real object
Class BankAccount{
Data:
intnumber;
float balance;
Operations:deposit();
wihtdraw();
}
-
8/8/2019 Topic Introduction
35/63
OO
P
35
OOP - Classes
A class:
A definition ofsomething
A class is an entity that definesthe attributesof an object
Attributes include data and operations
(methods)
-
8/8/2019 Topic Introduction
36/63
OO
P
36
OOP Classes (2) Class:
an entity that definesthe attributes of an object
Object: An instance of a class
A bankAccount is a class
A particularbankaccount (yours) is an object
-
8/8/2019 Topic Introduction
37/63
OO
P
37
Classes Hierarchy
Assume you wantto define a new classsimilar
to a predefined class
Example: Bank-Account
Saving Account
International Account
-
8/8/2019 Topic Introduction
38/63
OO
P
38
Classes Hierarchy (2) The new class(sub class):
similarto the original class(superclass)
but with additional attributes Subclass inherits all attributes of a superclass
Classes are organized in a hierarchy
SuperClasses Sub Classes
-
8/8/2019 Topic Introduction
39/63
OO
P
39
Classes Hierarchy Example
All kinds of accounts SuperClass
float balance;
Savings account only Sub Class floatrate;
Checking accounts only AnotherSub Class
float fee;
-
8/8/2019 Topic Introduction
40/63
OO
P
40
OOP Class examples
classtime
{
private: hour, minute,second
public: setHour,setMinute, }
classstudent
{
private: name, address,ID, public: setName,setID,
}
-
8/8/2019 Topic Introduction
41/63
OO
P
41
1.5 Object Oriented Design
Abstraction
Extractthe relevant properties of an object while
ignoring inessential details
Encapsulation
breaking down an object into parts
hiding and protecting its essential information
supplying an interface to modify the information
in a controlled and useful manner
-
8/8/2019 Topic Introduction
42/63
OO
P
42
Object Oriented Design (2) Modularity
Dividing an object into smallerpieces ormodules
suchthatthe object is easierto understand and
manipulate
Hierarchy
Ranking orordering of objects based onsome
relationship betweenthem
-
8/8/2019 Topic Introduction
43/63
OO
P
43
Abstraction
Process of extracting only the relevant
properties of an object Extracted properties define a view ofthe
object
-
8/8/2019 Topic Introduction
44/63
OO
P
44
Abstraction (2) Cardealerviews a carfrom selling features
standpoint Price, warranty, color, etc.
Mechanic views a carfrom systems
maintenance standpoint Oil, oil filter,sparkplugs, etc.
-
8/8/2019 Topic Introduction
45/63
OO
P
45
Encapsulation
Breaking down an object into parts,
hiding and protecting its essential information and
supplying an interface to modify the informationin a controlled and useful manner
By hiding the information itsrepresentation
and content can be changed without affecting
otherparts ofthe system
-
8/8/2019 Topic Introduction
46/63
OO
P
46
Encapsulation (2) Example - carradio
Controlled by switches and knobs The details ofhow it works ishidden
-
8/8/2019 Topic Introduction
47/63
OO
P
47
Modularity
Dividing an objectso thatthe objectholds
useful information and it is easierto
unde
rsta
nd
Most complex systems are modular
Cooling System
Ignition System
Fuel System
-
8/8/2019 Topic Introduction
48/63
OO
P
48
Modularity (2) Example - Automobile can be decomposed
into subsystems
Cooling system Radiator
Thermostat
Waterpump
Ignitionsystem Battery
Starter
Sparkplugs
-
8/8/2019 Topic Introduction
49/63
OO
P
49
Hierarchy
Ranking orordering of objects
based onsome relationship betweenthem Hierarchies facilitate understanding complex
organizations and systems
Example a company hierarchy helps employees understand the
structure oftheircompany and theirpositions
-
8/8/2019 Topic Introduction
50/63
OO
P
50
1.6 Processing a High-Level
Language Program
Processing is a set of programs used to
develop software
A key component is a translator Types oftranslators
Compiler
Linker Examples
g++, Borland C++ , MS Visual C++
-
8/8/2019 Topic Introduction
51/63
OO
P
51
Processing a Program (2) Editorused to enterthe program
Source program (file.cpp) UNIXnedittext editor
Compilertranslatesthe source program
Displayssyntax errors (not descriptive) Linker/Loaderto combine object file with
otherobject files
Executable program
-
8/8/2019 Topic Introduction
52/63
OO
P
52
Processing a Program (3) Majoractivities
Editing
Compiling Linking with pre-compiled files
Object files
Library modules
Loading and executing
Viewing the behaviorofthe program
-
8/8/2019 Topic Introduction
53/63
OO
P
53
Process
Cycle
-
8/8/2019 Topic Introduction
54/63
OO
P
54
1.7 Software Development Method
Problem Analysis - (Correct Problem)Identify data objects
Goal to model properties Determine Input/ Output data
Constraints onthe problem
Design
Decompose into smallerproblems
Top-down design (divide and conquer) Develop Algorithm (Deskcheck)
-
8/8/2019 Topic Introduction
55/63
OO
P
55
Software Development Method (2) Implementation
Writing the algorithm
Testing Verify the program meetsrequirements
System and Unittest
Documentation Key part inthe development process
-
8/8/2019 Topic Introduction
56/63
-
8/8/2019 Topic Introduction
57/63
OO
P
57
Software Engineering Goals
Reliability
An unreliable life-critical system can be fatal
Understandability Future development becomes very difficult if
software ishard to understand
Cost Effectiveness
Costto develop and maintainshould not exceed
profit
-
8/8/2019 Topic Introduction
58/63
OO
P
58
Software Engineering Goals (2) Adaptability
System that is adaptive is easierto alterandexpand
Reusability
Improvesreliability and maintainability, and
reduces development costs
1 8 A l i th S ft
-
8/8/2019 Topic Introduction
59/63
OO
P
59
1.8 Applying the Software
Development Method
Case Study: Converting Milesto Kilometers
Problem Yoursummersurveying job requiresto study some
mapsthat give distances inkilometers and some that
use miles
You and yourco-workers preferto deal in metricmeasurements
Write a program that performsthe necessary
conversion
-
8/8/2019 Topic Introduction
60/63
A l i th S ft
-
8/8/2019 Topic Introduction
61/63
OO
P
61
Applying the Software
Development Method
Design
The nextstep isto formulate the algorithm thatsolvesthe problem
Begin by listing the three majorsteps, orsub problems,ofthe algorithm
Implementation
To implementthe solution, you must write the
algorithm as a C++ program Testing
How do you know the sample run is correct?
1 9 P f i l Ethi
-
8/8/2019 Topic Introduction
62/63
OO
P
62
1.9 Professional Ethics
for Programmers
Privacy and Misuse of Data
ComputerHacking Plagiarism and Software Piracy
Misuse of a ComputerResource
-
8/8/2019 Topic Introduction
63/63