Title: ECE 231 Intermediate Programming and Engineering Problem Solving
1ECE 231Intermediate Programming andEngineering
Problem Solving
2Major Differences C vs. C
- Procedure-Oriented Programming (POP)
- Procedures/functions/subroutines
- Top-down design (divide and conquer)
- Object-Oriented Programming(OOP)
- Abstract Data Type (ADT), Class (more closer to
real world), data-hiding, polymorphism and
inheritance - Bottom-up design
3Contrasting Program Design
- Procedure-Oriented Object-Oriented
Data Operations
Control
Class
4Before Object Orientation
Real world concepts
Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkv
jfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk
saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvj
fvkfjvkfjk
Object-orientation helps to remedy this mismatch
Poor correspondence
getCustomerName() initialize() doTransacion() getD
ocument()
billCustomer() recordTransaction() initiateTransa
ction()
Software Design Entities
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
5Object Orientation
Real world concepts
Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkv
jfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk
saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvj
fvkfjvkfjk
Direct correspondence
Account getDetails()
Transaction execute()
Customer getFirstName()
Software design entities
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
Graphics reproduced with permission from Corel.
6Major Differences C vs. C
- Easy to maintain, excellent reusability and
reliability for large projects of millions of
lines of code - Abstract Data Types (ADTs), Classes, Data hiding
could impede code efficiency
- Unmaintainable for large projects
- Good choice for code that has to be fast while
still being reasonably readable and portable, eg.
device drivers
7Syntax Differences C vs. C
- include ltiostreamgt
- Data type typecast is different e.g
- int i 2
- float f float (i)Format type(variable)
- Dynamic memory allocation in C by new and
delete.
- includeltstidio.hgt
- int i 2
- float f (float) iFormat (type)variable
- in C by calloc() and malloc()
8Syntax Differences C vs. C
- main() must have a return type in C
- Function prototyping (declaration) is compulsive
in C. - Boundary checking for array in C .
- main() may not have a return type in C
- Function prototyping (declaration) is optional in
C. - No boundary checking for array
9Syntax Differences C vs. C
- the input/output operation is done in C through
cout and cin objects - In C we use namespace name std (Appendix C30)
- in c it is done through printf() and scanf()
functions - in C it is not needed
10C Features C with Classes
- Inheritance (a child class can inherit
- features of parent class)
- Polymorphism (Ability to take many
- forms)
- Encapsulation (Binding of methods and
- data together)
- Abstraction (Hiding the Implementation
- from the user)
11Review Appendix C