Part 1 Introduction

Download Report

Transcript Part 1 Introduction

CSCE 110
PROGRAMMING FUNDAMENTALS
WITH
C++
Prof. Amr Goneid
AUC
Part 1. Introduction
Prof. amr Goneid, AUC
1
1. Introduction
 Software for Problem Solving
 Software Production Process
 Top-Down Design
 Modules
 Structured Software & Program Design
 Some Guidelines for Design
 Example
 C++ Program & Module Structures
 Object Oriented Programming
Prof. amr Goneid, AUC
2
Software for Problem Solving
 Use of S/W
Problem
Domain
S/W
TO
Decide, Learn,
View & Interact,
Play, …….
Prof. amr Goneid, AUC
3
Software Production Process
 Stages of S/W Production
Specify
Requirements
Solution
Strategy
Problem
Definition
Maintenance
Upgrade
Prof. amr Goneid, AUC
S/W
Production
S/W
Testing
4
Software Production
S/W
Design
Implementation
(Programs)
Debugging
Performance Analysis / Benchmarks
Prof. amr Goneid, AUC
5
Top-Down Design
 Divide and Conquer Strategy.
 Given problem X (Level 0). Divide it
into sub-problems X1, X2, …, Xn
(Level 1) such that solving X1, then
X2, then … solves X completely.
 Repeat for each sub-problem until we
reach basic or trivial implementation
level.
Prof. amr Goneid, AUC
6
Top-Down Design
Level
0
1
2
X
X1
X2
X21
X3
Xn
X22
.
.
Prof. amr Goneid, AUC
7
Modules
In C++
Sub-Problem
Xi
Main Problem
X
Module Xi
Implemented as
Main Program
X
Implemented as
Prof. amr Goneid, AUC
8
Structured Software Design
 Design Steps
Main &
Subs
Functional
Specs
Data
Specs
Algorithm
Specs
Pseudocode
Prof. amr Goneid, AUC
9
Structured Program Design
Main Program and Modules
X1 Module
X2 Module
Main Program
X1 Data
X2 Data
Main
Data
Actions
(Algorithms)
Actions
(Algorithms)
Prof. amr Goneid, AUC
Main
Manager
10
Some Guidelines for Design
 Transparency of Purpose
 Correctness
 Completeness
 Ease of Use
 Efficiency
 Writability
 Maintainability
Prof. amr Goneid, AUC
11
Example of a Design
Document
 Problem Definition:
n projects are to be prioritized according to
cost (least cost first). Problem size is n
 Requirement Specification:
- Input(s): n, and list of costs in random
order.
- Output(s): List of costs in ascending
order.
Prof. amr Goneid, AUC
12
Example(continued)

Solution Strategy:
1. Input random List of costs
2. Sort List in ascending order of cost.
3. Print sorted List.
 S/W Design:

Structured (Top-Down) Design:
Yields a main module and a sorting
module
Prof. amr Goneid, AUC
13
Example(continued)
 S/W Design (continued):
 Functional

Specification:
Main Module:
– Input list and its size n
– Call Sorting module to sort list
– Output sorted list

Sorting Module:
– Receives list and its size n
– Returns sorted list
Prof. amr Goneid, AUC
14
Example(continued)
 S/W Design (continued):
 Data
Specification:
The cost is an integer number.
MAX = 100 to represent maximum list size
An Array (a) of size MAX to store list.
 Algorithm Specification:
Sorting module uses the algorithm of
Selection Sort.
Prof. amr Goneid, AUC
15
Example(continued)

S/W Design (continued):

Main Module:
1.
2.
3.
4.
5.
Input n.
Check that n does not exceed MAX.
Input random list into array (a). Items will
occupy locations a0 ….. an-1
Call sorting module.
Output sorted list (a).
Prof. amr Goneid, AUC
16
Example(continued)

S/W Design (continued):

Sorting module (Selection Sort):
Repeat for list items k from 0 to n-2
1.
2.
3.
Consider the sub-array from k to n-1
Find location of the smallest element in
that sub-array
Exchange that element with that at (k)
Prof. amr Goneid, AUC
17
Example(continued)
 Implementation Stage:
As a C++ Program
Prof. amr Goneid, AUC
18
C++ Program Structure
Compiler Directives
Used Modules (Functions) Prototypes
Main Function Header
{
Main Data Declarations
Main Function Actions
}
Used Modules (Functions) are Defined Here
Prof. amr Goneid, AUC
19
C++ Module (Function)
Structure
Module (Function) Header
{
Local Data Declarations
Module Actions
(Executable Statements)
}
Prof. amr Goneid, AUC
20
Object Oriented Programming
 Abstraction:
Data Model of a physical object or process
 Methods:
Operations (Algorithms) performed on data of an
object
 Class:
Entity defining attributes of an object (data and
methods)
 Object:
An actual instance of a class
Prof. amr Goneid, AUC
21