Overview of Computers Computer Hardware Computer Software Programming Languages Processing A Program Software Development Method

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 63

Introduction to

O
O Programming Methodology I
P
Professor: Aishy Amer
COEN243 Topic 01

 Introduction
Overview of Computers

 Computer Hardware

 Computer Software

 Programming Languages

 Processing a Program

 Software Development Method


O Introduction
O
P
 OOP:

– increasingly important both in academia and


industry

 C++:

– emerging as a language of choice


– Because it combines
• efficiency of C & the disciplined approach to software
design using interacting modules
2
O Introduction
O
P
 COEN243:
– Object-Oriented Programming (OOP) with C++
– Modular, general, maintainable programs
• Modular: classes and functions
• General: can be applied for many applications/situations
• Maintainable: a code that the maintainer understand
 Focus:
– well-designed programs
– methodologies and concepts
– following software engineering principles

 C++ : very complex language


– be ready to work for long hours
3
O Introduction
O
P
#include <iostream> // Use the iostream library
using namespace std; // Use the standard library namespace
int main() // The main routine of the program
{
// *** Declaration/ Variables
float A,B,C,delta, root1, root2;

// *** Read input from user


cout << "Enter your Quad. Eq.: enter 3 real values for a,b,c."<<endl;
cin>> A >> 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);
// *** Output results
cout << "root1 is: " << root1 << endl;
cout << "root2 is: " << root2 << endl;
return 0;
}

4
O Introduction
O
P

5
O 1.1 Overview of Computers
O
P
 Computers / Programs:
– tools to solve real-world problems
 Programs are used to simulate the behavior of
real-world systems
 Simulation:

– reproduction of selected aspects of the system


behavior through experimentations

6
O Overview of Computers
O
P
 Very Large Scale Integration (VLSI)
technology made computers affordable, small
and available to the public
 Programming facilitates the use of computers
 Programming has changed over time:
– Every few years a new programming language
 Computer:
– “A device for counting or computing”
– Two components: Hardware & Software

7
O 1.2 Computer Hardware
O
P
 Every computer is organized roughly into six
parts
– CPU - central processing unit
• decisions are made
• computations are performed
• input/output requests are delegated
– Main Memory
• Stores information being processed by the CPU

8
O Computer Hardware
O
P
– Secondary Memory
• Stores data and programs
– Input devices
• Allows people to supply information to computers
– Output devices
• Allows people to receive information from computers
– Network connection
• Modems / Ethernet interface

9
O Computer Components
O
P

10
O Main Memory
O
P

 It stores
– programs
– data
– results
 Types of memory
– RAM
– ROM

11
O Main Memory (2)
O
P Address Content

0 -27.2
Memory:
1 354
an ordered sequence
of storage locations 107 RTV0001
called memory cells 108
ADD1024
109
STR0005
Every cell has a content

1023 0.005
1024 75.62
12
O Main Memory (3)
O
P
 To access cell info:
– each cell has a unique address
 Content may or may not be meaningful to our
program
 A cell =

– A grouping of smaller units called bytes


 A byte =

– Amount of storage required to store a single


character
 Number of bytes per cell varies
13
O Main Memory (4)
O
P
A byte :
– Composed of smaller units of storage called bits

01234567 a bit

byte
 Binary:
– a numbering system of two numbers 0 & 1
 Bit = Binary digit:
– Smallest element a computer can deal with

14
O Main Memory (5)
O
P
 Assume a byte is composed of 1, 2,3, or 8 bits
 If 1 bit: it can take 2 combinations

– 0 or 1
 If 2 bits: it can take 4 combinations
– 00 01 10 11
 If 3 bits: 8 combinations
– 000 001 010 … 111
 Often a byte = 8 bits
– 2^8=256 combinations or values

15
O Secondary Memory & Storage
O
P

 Semi permanent data-storage capability


– Tape or Disk
– Hard disk
– CD ROM
 Secondary memory has much more storage
capacity

16
O CPU
O
P

 “Brains” of the computer


– Arithmetic calculations are performed using the
Arithmetic/Logical Unit or ALU
– Control unit decodes and executes instructions
 Arithmetic operations are performed using
binary number system

17
O CPU (2)
O
P
 Fundamental building block is a switch
– Switches are made from ultra-small transistors
 Examples

– The Pentium ® processor contains about three


million transistors
– The Pentium Pro ® has about 5.5 million
transistors

18
O Input / Output Devices
O
P
 Accessories that allow computer to perform
specific tasks
– Receiving information for processing
– Return the results of processing
– Store information
 Common input and output devices
– Printer Joystick CD-ROM
– Keyboard Monitor

19
O Computer Networks
O
P

 LAN - Local area network


– Organizational
 WAN - Wide area network
– Internet
– World Wide Web
• Introduced 1989
• Developed by European Laboratory for Particle Physics

20
O 1.3 Computer Software
O
P
 Application software
– Programs designed to perform specific tasks that
are transparent to the user
 System software
– Programs that support the execution and
development of other programs
– Two major types
• Operating systems
• Translation systems

21
O Application Software
O
P
 Application software has made using
computers indispensable and popular
 Common application software

– Word processors
– Desktop publishing programs
– Spreadsheets
– Presentation managers
– Drawing programs

22
O Operating System (OS)
O
P
 Controls and manages the computing resources
 Important services of an OS

– File system
– Commands for manipulation of the file system
– Perform input and output on a variety of devices
– Management of the running systems
 Examples
– Unix ®, Linux ®
– MSDOS ®, Windows ®

23
O 1.4 Programming Languages
O
P
 Every few years:
– a new programming language
 Programming language:
– evolved to help programmer
– To ease the transition from the design to
implementation
 First language:
– Very dependent on the machine architecture

24
O Programming Languages (2)
O
P
 Machine Language
– “Native tongue” of the computer
– Binary 0s and 1s that specify what to 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;

25
O Programming Languages (3)
O
P
 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;

26
O Programming Languages (4)
O
P
 Source Program: tax.cc
– Program you write
 Object Program: tax.o
– Program translated from your program
 Executable Program: tax
– Program translated from the object program

27
O Programming Languages (5)
O
P
 Programming paradigm:
– design philosophy that helps to
• think about problems &
• formulate solutions
 Examples:

– imperative languages
– structured languages
– object-oriented languages

28
O Imperative Programming
O
P
A computer:
– a large memory store
A program:
– a sequence of commands stored in the store
 Emphasis on stored data
 Examples: Assembly, Basic

29
O Structured Programming
O
P
A program:
– a set of procedures (or functions) on
a set of data values stored in the memory
 Emphasis on functions
 Function:

– performs a sub task of the program


– Abstraction of a behavior

30
O Structured Programming (2)
O
P
 Algorithms are the basis for the functions
– Highly structured
– Top-down design
– Step-wise refinement
 Abstraction:

– Separation of the behavior of a ‘thing’ from its


representation or implementation

31
O Object Oriented Programming
O (OOP)
P
 Real-world problems have objects
– Objects define the problem
 OOP promotes thinking about software in a
way that models the real world
 OOP supports good software engineering

32
O OOP (2)
O
P
 Emphasis is on
– the objects (data) and
– how to manipulate them
A program:
– A network of objects with their attributes
– Attributes = data and operations

There is not one programming language best for


every type of problems
33
O Object Example
O
P
 Real-world problem:
– Automated banking system
 A Bank Account = a real object
 Class BankAccount
{
Data:
int number;
float balance;
Operations:
deposit();
wihtdraw();
}

34
O OOP - Classes
O
P
A class:
– A definition of something
A class is an entity that defines the attributes
of an object
 Attributes include data and operations

(methods)

35
O OOP – Classes (2)
O
P
 Class:

– an entity that defines the attributes of an object


 Object:

– An instance of a class
A bank Account is a class
 A particular bank account (yours) is an object

36
O Classes Hierarchy
O
P
 Assume you want to define a new class
similar to a predefined class
 Example:

– Bank-Account
• Saving Account
 International Account

37
O Classes Hierarchy (2)
O
P
 The new class (sub class):
– similar to the original class (super class)
– but with additional attributes
 Subclass inherits all attributes of a super class
 Classes are organized in a hierarchy

– Super Classes
– Sub Classes

38
O Classes Hierarchy Example
O
P
 All kinds of accounts – Super Class
– float balance;
 Savings account only – Sub Class
– float rate;
 Checking accounts only – Another Sub Class
– float fee;

39
O OOP – Class examples
O
P
 class time
{
private: hour, minute, second
public: setHour, setMinute, …
}
 class student

{
private: name, address, ID, …
public: setName, setID, …
}

40
O 1.5 Object Oriented Design
O
P
 Abstraction

– Extract the 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

41
O Object Oriented Design (2)
O
P
 Modularity

– Dividing an object into smaller pieces or modules


such that the object is easier to understand and
manipulate
 Hierarchy

– Ranking or ordering of objects based on some


relationship between them

42
O Abstraction
O
P

 Process of extracting only the relevant


properties of an object
 Extracted properties define a view of the

object

43
O Abstraction (2)
O
P

 Car dealer views a car from selling features


standpoint
– Price, warranty, color, etc.
 Mechanic views a car from systems
maintenance standpoint
– Oil, oil filter, spark plugs, etc.

44
O Encapsulation
O
P
 Breaking down an object into parts,
– hiding and protecting its essential information and
– supplying an interface to modify the information
in a controlled and useful manner
 By hiding the information its representation
and content can be changed without affecting
other parts of the system

45
O Encapsulation (2)
O
P

 Example - car radio


– Controlled by switches and knobs
– The details of how it works is hidden

46
O Modularity
O
P
 Dividing an object so that the object holds
useful information and it is easier to
understand
 Most complex systems are modular

– Cooling System
– Ignition System
– Fuel System

47
O Modularity (2)
O
P
 Example - Automobile can be decomposed
into subsystems
– Cooling system
• Radiator
• Thermostat
• Water pump
– Ignition system
• Battery
• Starter
• Spark plugs
48
O Hierarchy
O
P

 Ranking or ordering of objects


– based on some relationship between them
 Hierarchies facilitate understanding complex
organizations and systems
– Example
• a company hierarchy helps employees understand the
structure of their company and their positions

49
O 1.6 Processing a High-Level
O Language Program
P
 Processing is a set of programs used to
develop software
 A key component is a translator

 Types of translators

– Compiler
– Linker
 Examples

– g++, Borland C++ ®, MS Visual C++ ®

50
O Processing a Program (2)
O
P
 Editor used to enter the program
– Source program (file.cpp)
– UNIX nedit text editor
 Compiler translates the source program
– Displays syntax errors (not descriptive)
 Linker/Loader to combine object file with
other object files
– Executable program

51
O Processing a Program (3)
O
P
 Major activities
– Editing
– Compiling
– Linking with pre-compiled files
• Object files
• Library modules
– Loading and executing
– Viewing the behavior of the program

52
O
O
P
Process
Cycle

53
O 1.7 Software Development Method
O
P
 Problem Analysis - (Correct Problem)
– Identify data objects
– Goal to model properties
– Determine Input / Output data
– Constraints on the problem
 Design

– Decompose into smaller problems


– Top-down design (divide and conquer)
– Develop Algorithm (Desk check)
54
O Software Development Method (2)
O
P
 Implementation

– Writing the algorithm


 Testing

– Verify the program meets requirements


– System and Unit test
 Documentation

– Key part in the development process

55
O Software Development Method (3)
O
P

 Software engineering
– Area of computer science concerned with building
large software systems
 Challenge

– Tremendous advances in hardware have not been


accompanied by comparable advances in software

56
O Software Engineering Goals
O
P
 Reliability

– An unreliable life-critical system can be fatal


 Understandability

– Future development becomes very difficult if


software is hard to understand
 Cost Effectiveness
– Cost to develop and maintain should not exceed
profit

57
O Software Engineering Goals (2)
O
P

 Adaptability

– System that is adaptive is easier to alter and


expand
 Reusability

– Improves reliability and maintainability, and


reduces development costs

58
O 1.8 Applying the Software
O Development Method
P

 Case Study: Converting Miles to Kilometers


– Problem  
• Your summer surveying job requires to study some
maps that give distances in kilometers and some that
use miles
• You and your co-workers prefer to deal in metric
measurements
• Write a program that performs the necessary
conversion

59
O Applying the Software
O
P Development Method

– Analysis  
• The first step in solving this problem is to determine
what you are asked to do
• You must convert from one system of measurement to
another, but are you supposed to convert from
kilometers to miles, or vice versa?
• The problem states that you prefer to deal in metric
measurements, so you must convert distance
measurements in miles to kilometers

60
O Applying the Software
O
P Development Method

– Design  
• The next step is to formulate the algorithm that solves
the problem
• Begin by listing the three major steps, or sub problems,
of the algorithm
– Implementation  
• To implement the solution, you must write the
algorithm as a C++ program
– Testing  
• How do you know the sample run is correct?

61
O 1.9 Professional Ethics
O for Programmers
P

 Privacy and Misuse of Data


 Computer Hacking

 Plagiarism and Software Piracy

 Misuse of a Computer Resource

62
O Ethics and Professionalism
O
P
 Ethics:
– Disciplined dealing with moral duty
– Moral Principles or Practice
– System of right behavior
 Professionalism:

– The conduct, aims or qualities that characterize a


professional person

63

You might also like