overview of the course 15-111 ananda gunawardena -- lecture – school of computer science – phone...

Post on 31-Dec-2015

225 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Overview of the Course 15-111

Ananda Gunawardena -- Lecture– School of Computer Science– Phone : x81559– Office: WeH 5113– guna@cs.cmu.edu

Teaching Assistants – Lab Help, Grading– Leal Vona (lvona@andrew.cmu.edu)– Ruth Lin (rlin@cs.cmu.edu)

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

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

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

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

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

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

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

System Costs: Hardware vs. Software*

100%

1950 2000

Software

Hardware

PercentSystemCost

Year

* courtesy R.Pattis

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!!!

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

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

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

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

OOP Terminology

Program = objects cooperating to solve a problem

Properties of an object:

State ==> data ==> nouns Operations ==> behavior ==> verbs Identity

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

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

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

Example: OOP Design

Problem: write a program to simulate an ATM Data (nouns):

– Account name– Account balance– ...

Operations /behavior(verbs):– Deposit– Withdraw– Inquire balance– ...

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 : guna@cs.cmu.edu

top related