overview of the course 15-111 ananda gunawardena -- lecture – school of computer science – phone...
TRANSCRIPT
![Page 1: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/1.jpg)
Overview of the Course 15-111
Ananda Gunawardena -- Lecture– School of Computer Science– Phone : x81559– Office: WeH 5113– [email protected]
Teaching Assistants – Lab Help, Grading– Leal Vona ([email protected])– Ruth Lin ([email protected])
![Page 2: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/2.jpg)
15-111
Prerequisites– Prior Programming experience in C++ …– Loops, conditionals, arrays, basic I/O– File processing, Data types – Know how to write/run a program starting
from a problem statement Problem solving skills Time management skills
![Page 3: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/3.jpg)
How to be Successful in this course
Attend class Do the homework
– they are designed to help you digest the chapter Do the labs (programming assignments)
– they are designed to help you learn how to use the concepts covered in the chapter and discussed during lecture
– start the labs early, programming assignments ALWAYS take longer than you think they will
The material in each session builds on the material from the previous session
![Page 4: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/4.jpg)
Course Web Site
http://www.andrew.cmu.edu/~guna/15-111
All important information about the course is posted at this site… Check it for whats new
Course policies are posted here… Syllabus, Cheating Policy, and Lecture notes, Labs, Exam help
Contact information is posted here… Office Hours, TA’s Assignment information is posted here… Due Dates (where you will find
links to labs and homework All classwork is saved in… classwork I will save frequently asked questions in… FAQ’s Need to tell me something anonymously use… Anonymous link Submit Assignments electronically … submit Lots of useful resources in… Miscellaneous
![Page 5: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/5.jpg)
What we are going to study
overview of fundamental programming concepts using Java
Introduction to object-based programming techniques
Classes and Objects Inheritance OOP design
![Page 6: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/6.jpg)
What we are going to study…
data aggregates self-referential data structures
– linked lists– Stacks– queues– Trees– Graphs
analysis of algorithms Next course : 15-211 – Data Structures
![Page 7: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/7.jpg)
Problem Solving Process
Review– Algorithm– Top-down design– stepwise refinement– Pseudocode– Flow Chart
Phases of software development– Planning: figuring out the problem specs– Design: the algorithm, use pseudocode etc – Code: Translate the design into C++/Java syntax– Code review: “Spell-check” your code. Simulate the compiler looking for
syntax errors– Compile: With a thorough code review, compile time is small– Test/debug
![Page 8: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/8.jpg)
Problem Solving Process
Review:– Algorithm– Top-down design, stepwise refinement– Pseudocode– Flow Chart
Phases of software development– Planning: figuring out the problem specs– Design: the algorithm, use pseudocode etc – Code: Translate the design into C++/Java syntax– Code review: “Spell-check” your code. Simulate the compiler
looking for syntax errors– Compile: With a thorough code review, compile time is small– Test/debug
![Page 9: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/9.jpg)
System Costs: Hardware vs. Software*
100%
1950 2000
Software
Hardware
PercentSystemCost
Year
* courtesy R.Pattis
![Page 10: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/10.jpg)
Motivation for Design before Coding
Analogy: Think about how you write a paper– Problem Statement? Outline? Abstract? Fill in
details based on the outline? Refine sections/paragraphs? How do you proof your paper? Do you just type something and watch the spell-checker or do you print it out and read it for errors?
Your solution is only as good as your design Coding should be low priority compared to design If you take short cuts, you will end up spending a lot more
time on the program. Bottom Line: There is nothing mysterious about coding!!!
![Page 11: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/11.jpg)
OOP Versus Non-OOP
Procedural programming OOP
- Identify tasks/sub-tasks - Design the classes- Write procedures - Design the methods- Procedures act upon data - Objects communicate to solve to solve the problem the problem- Start with “verbs” - Start with “nouns”- Data is secondary - Data is primary
![Page 12: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/12.jpg)
Problem Solving - OO Design
Identify the objects Identify the operations Design the algorithm/decompose into smaller chunks E.g: Compute the amount of tuition to be paid Name the objects
– # credit hours– cost per credit hour– Other costs, such as student activity fee etc– Any discounts
Name the operations to be performed:– Addition, subtraction, multiplication
Algorithm
![Page 13: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/13.jpg)
Key Elements of OOP
Abstraction: Focus on the important, ignore the details– e.g. Driving a car
The interface of the car is what the driver sees on the outside, i.e. the dash board, the gas pedal and so on.
The implementation is a detail, e.g. what exactly happens when I step on the gas pedal.
Encapsulation: Information hiding– The details of an object are hidden. – Users are not allowed to make changes to the implementation.– If there is any change in the implementation, it does not affect
the users(clients) of the interface. – E.g. A Stack Class has as its interface: init, push, pop. The
implementation may be changed from an array to a linked list
![Page 14: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/14.jpg)
Key Elements of OOP
Inheritance– Building upon what is already defined– A class can inherit from another class much like a child
inherits from its parent
Polymorphism– Greek for “many shapes”– Same name for different things– Two forms in OOP
Overloading: Functions with the same name Over-riding: A child class redefining its parent’s functions
![Page 15: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/15.jpg)
OOP Terminology
Program = objects cooperating to solve a problem
Properties of an object:
State ==> data ==> nouns Operations ==> behavior ==> verbs Identity
![Page 16: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/16.jpg)
Object Examples
Example 1: An electronic mailbox
States: full or empty Operations: add, delete ... Identity: any 2 mailboxes will be different
e.g. hou and aj29 each have a mail box
Example 2: traffic signal
![Page 17: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/17.jpg)
Object Components
An object is composed of both data and Operations which can act upon the data
Data
Operations
In an object: Operations ==> member functions (methods) Data ==> data members
![Page 18: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/18.jpg)
Classes
Class:– A collection of related objects. – Instance of a class = object– Factory with blueprints/instructions to build gadgets– Objects: the gadgets the factory makes.
Example:– Class : checkingaccount– Objects: minnieCheckacct, mickeyCheckacct
![Page 19: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/19.jpg)
Example: OOP Design
Problem: write a program to simulate an ATM Data (nouns):
– Account name– Account balance– ...
Operations /behavior(verbs):– Deposit– Withdraw– Inquire balance– ...
![Page 20: Overview of the Course 15-111 Ananda Gunawardena -- Lecture – School of Computer Science – Phone : x81559 – Office: WeH 5113 – guna@cs.cmu.edu Teaching](https://reader036.vdocuments.mx/reader036/viewer/2022082405/56649eac5503460f94bb2aa3/html5/thumbnails/20.jpg)
Problem ( Elevator Control Problem)
Simulation of an elevator control system. 20 floors , 4 elevators1. Identify the data objects2. Identify the data operations3. Solve the problem
Any questions Email : [email protected]