csci 1101a
play

CSCI-1101A Object-Oriented Programming (OOP) Mohammad T . Irfan - PDF document

12/11/14 CSCI-1101A Object-Oriented Programming (OOP) Mohammad T . Irfan Reading: Ch 16 (Guzdial) Optional: Ch 8 (Guttag) OOP u A different style of programming from functional decomposition u Focuses on objects u Why


  1. 12/11/14 ¡ CSCI-1101A Object-Oriented Programming (OOP) Mohammad T . Irfan Reading: Ch 16 (Guzdial) Optional: Ch 8 (Guttag) OOP u A different style of programming from functional decomposition u Focuses on “objects” u Why OOP? 1 ¡

  2. 12/11/14 ¡ Flappy Bird http://youtu.be/YHH2101OFfI 2 ¡

  3. 12/11/14 ¡ Objects vs. Classes u Objects are the “things” (nouns) that we see/perceive/model u Properties/attributes (nouns) – instance variables u Behavior/actions (verbs) – methods u Classes u Factory for creating objects u Template or blueprint for creating objects Turtle Objects Demo 3 ¡

  4. 12/11/14 ¡ Codes def turtleDemo(): zoo = World() bob = Turtle(zoo) bob.setColor(blue) ann = Turtle(zoo) ann.setColor(red) bob.forward() ann.turnRight() ann.forward(200) bob.turnLeft() bob.backward(-150) bob.forward() Key points u Two objects of the same class have different properties/attributes u Two turtles with different colors, position, etc. u But they share the same behavior u forward(), turn(), etc. 4 ¡

  5. 12/11/14 ¡ Writing our own class Hannaford Inventory u Hannaford’s inventory consists many items. Each item has a name, barcode, price, and quantity (in stock). Hannaford can change the price of an item anytime. The quantity is also changed when Hannaford sells an item or restocks it. 5 ¡

  6. 12/11/14 ¡ Item class >= Item class (continued) 6 ¡

  7. 12/11/14 ¡ main() function outside of the Item class Problems u Bank account u A bank account has a name and a balance, among other information. The balance gets changed when the account holder withdraws or deposits money. u Slide show u Each slide in a slide show has a picture and some music. Each slide also has a show functionality, which shows the picture and plays the music. u Smart turtle u Special type of turtle that can show tricks u Inherits the Turtle class 7 ¡

  8. 12/11/14 ¡ Announcement u Reminder Exam 5 on Tuesday, Dec 9 u Topics u Recursion (see the slides on recursion) u Watch the video lectures u OOP (up to today’s class) u Practice the codes from the slides and the textbook (Guzdial) u Additional practice (optional): Guttag’s book Class Participation HW 6 Work in groups of 2 students Due: Thursday u Create another class named Inventory that keeps a list of Item objects. The list is initially empty, but objects of the Item class can be added to it. The Inventory class will have certain functionalities like finding the lowest price item and finding the minimum stock item. 8 ¡

  9. 12/11/14 ¡ A card game u This card game is called “all or nothing.” This is a human vs. computer game. The game starts with a deck of cards, which has 52 cards in it. Each card has one of four possible suits and one of 13 possible ranks. u This is how the game is played. The dealer shuffles the deck of cards. Neither 1. the computer nor the human can see any of the cards. The computer picks a card from the deck 2. randomly. The human can choose any of the 51 remaining 3. cards from the deck (without seeing, of course). Whoever has the better suit wins. If both suits 4. are the same, the player with the better rank wins. Questions u What classes would you design? u What would be their instance variables and methods? u How would you simulate playing the game? 9 ¡

  10. 12/11/14 ¡ 10 ¡

  11. 12/11/14 ¡ Inheritance “Is-A” relationship u Bowdoin College MealPlan 11 ¡

  12. 12/11/14 ¡ Modeling one week’s meal plan u Generic meal plan – point/cash based u Special meal plans u Res 19 plan Key point: u Res 14 plan Res 19 plan is a special type of meal plan u Res 10 plan u Examples u Rob lives off-campus and uses the generic plan. He is charged on a per meal basis. u Jon enrolls into the Res 19 plan. Additional meals in a week will be charged according to the generic meal plan. 12 ¡

  13. 12/11/14 ¡ Demo Another Problem: Create smart turtles u A smart turtle is a turtle that has a high IQ level. It can show tricks like this: 13 ¡

  14. 12/11/14 ¡ SmartTurtle class Demo 14 ¡

  15. 12/11/14 ¡ Final exam u Thursday, 12/18 at 9am in Searls 223 classroom u Topics u The basics of Python (Guttag’s Ch 2, 3, Section 4.1) u Text and files (Chapter 10, class + lab) u Recursion (Chapter 15.4, class + lab, Optional: Guttag’s Section 4.3– see pdf) u Object-oriented programming (Chapter 16, Optional: Guttag’s Ch 8– see pdf) u [Nothing on picture/sound] For Data Structures u Head start u Learn the syntax (grammars) of C and C++ u Python to C++ transition guide: http://personal.denison.edu/~krone/cs173/files/ PythontoC++.pdf u C/C++ Tutorial: Practice codes from http://www.cprogramming.com/tutorial/c- tutorial.html u C++ compiler u Netbeans (among a host of other options) u https://netbeans.org/features/cpp/index.html 15 ¡

  16. 12/11/14 ¡ Outlook u NY Times: May 2, 2014 16 ¡

  17. 12/11/14 ¡ Thank You! 17 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend