Objects OOP Quiz Stuff. CS1101S: DG Week 10. Wohoo, OOP! October 22, CS1101S: DG Week 10

Similar documents
JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

University of Massachusetts Lowell

Midterm Exam #2 Review. CS 2308 :: Spring 2016 Molly O'Neil

Today. Continue our very basic intro to JavaScript. Lambda calculus

Sample CS 142 Midterm Examination

JAVA MOCK TEST JAVA MOCK TEST II

1LIVE CHESS BOOK User Manual

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Performance Assessment Spring 2001

CSCU9T4: Managing Information

CSCI-1200 Data Structures Fall 2009 Lecture 25 Concurrency & Asynchronous Computing

OOP-8-DLList-1-HW.docx CSCI 2320 Initials Page 1

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued

LMS Instructions. To watch a video simply click on a category, then select the title you would like to train on and click play.

Principles of Object Oriented Programming. Lecture 4

EINDHOVEN UNIVERSITY OF TECHNOLOGY

Introduction to Programming

A Short Summary of Javali


I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Math Released Item Grade 5. Leftover Soup VH104537

2. You are required to enter a password of up to 100 characters. The characters must be lower ASCII, printing characters.

CS 1044 Program 6 Summer I dimension ??????

i) Natural numbers: Counting numbers, i.e, 1, 2, 3, 4,. are called natural numbers.

COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts

CS445 Week 9: Lecture

LABORATORY 1 REVISION

OHIO ASSESSMENTS FOR EDUCATORS (OAE) FIELD 010: COMPUTER INFORMATION SCIENCE

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras

COMP 105 Homework: Type Systems

Lesson 6: Manipulating Equations

(Refer Slide Time: 00:01:30)

LAB 12: ARRAYS (ONE DIMINSION)

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

Chapter 4C Homework Functions III Individual Assignment 30 Points Questions 6 Points Script 24 Points

Please indicate EDM in the subject box

Solutions for Transformations of Functions

CSC D84 Assignment 2 Game Trees and Mini-Max

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

MSO Exam November 7, 2016, 13:30 15:30, Educ-Gamma

Writing Practice Tool Guide

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

PREMOCK GCE EXAMINATIONS

2015 Paper E2.1: Digital Electronics II

CS1210 Lecture 28 Mar. 27, 2019

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

CS303 LOGIC DESIGN FINAL EXAM

Object-Oriented Programming

JavaScript: Sort of a Big Deal,

Object Oriented Programming

OOP- 5 Stacks Individual Assignment 35 Points

PCS1-Ch-3B-Basic-Loops-HW CSCI 1320 Initials P a g e 1

Hardware Description and Verification Lava Exam

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Example: Fibonacci Numbers

Week 5: Background. A few observations on learning new programming languages. What's wrong with this (actual) protest from 1966?

Common Misunderstandings from Exam 1 Material

Sai Nath University. Assignment For BCA 3 RD Sem.

BM214E Object Oriented Programming Lecture 11

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

9/19/2018 Programming Data Structures. Polymorphism And Abstract

Where The Objects Roam

Human Computer Interaction Lecture 16. User Support

Object Oriented Programming. Solved MCQs - Part 2

EC312 Chapter 4: Arrays and Strings

CMSC131. Objects: Designing Classes and Creating Instances

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

JavaScript: Objects, Methods, Prototypes

Object-role modelling (ORM)

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

CSI 32. Lecture Object-Oriented Paradigm. UML (Unified Modeling Language)

Exam Questions. Object-Oriented Design, IV1350. Maximum exam score is 100, grade limits are as follows. Score Grade 90 A 80 B 70 C 60 D 50 E

LMS Instructions. To watch a video simply click on a category, then select the title you would like to train on and click play.

Grade Level: 6-8 Sunshine State Standard: MA.A.1.3.3, MA.A.3.3.1, MA.B.1.3.2, MA.B.4.3.2, MA.C Time: 45 minutes

Be sure check the official clarification thread for corrections or updates to this document or to the distributed code.

Activity 7: Arrays. Content Learning Objectives. Process Skill Goals

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

CS164: Final Exam. Fall 2003

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

Lab - 8 Awk Programming

OO Techniques & UML Class Diagrams

Lab Manual. Object Oriented Analysis And Design. TE(Computer) VI semester

Spring Semester, Dr. Punch. Exam #2 (03/28), form 2 C

Object-Oriented Design

FACADE & ADAPTER CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 7 09/13/2011

CS 104 (Spring 2014) Final Exam 05/09/2014

CS 455 Midterm Exam 1 Fall 2015 [Bono] Thursday, Oct. 1, 2015

OBJECT ORIENTED PROGRAMMING

EXAMINATION INSTRUCTIONS

GO MOCK TEST GO MOCK TEST I

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

Java Concepts: Compatible With Java 5, 6 And 7 By Cay S. Horstmann

Transcription:

Wohoo,! October 22, 2016

Revision 1 Objects 2 3

What is an Object? Objects Revision Tables that map keys to values Efficient data structure than using lists Three notations: square bracket, dot-nation and literal Order of growth (runtime) for accessing and updating an entry? Θ(1)! Things to put in object entry! Functions: obj["a"] = function(x) { }; Strings: obj["b"] = "bbq"; Variables: obj["c"] = my_pair; What happens when we change the value of my_pair?

Problem One: Drawing! Revision Question Following the notation introduced in Lecture 9B, draw a graphical representation of the two objects my_object and my_other_object. For Your Reference var my_object = {}; my_object["a"] = 1; my_object["b"] = 2; my_object["my very long key"] = 2; var my_other_object = { d : 1, e : "a string", f : true, my_fun : function (x) {} };

Problem One: Solution Objects Revision my_object & my_other_object

Problem Two: Some Play Revision Question Familiarize yourself with the object notation, by assigning the variable theatre_play to an object with the attributes title, number_of_spectators, venue, and number_of_actors, using the three different syntactic variants: Square bracket notation, dot-notation and literal object creation. You can use as values the data from the last theatre play that you watched. Any theatre goers?

Problem Two: Solution Objects Revision Square bracket notation var theatre_play = {}; theatre_play["title"] = "a Play featuring an iphone power block and a mechanical pencil"; theatre_play["number_of_spectators"] = 266346; theatre_play["venue"] = "M8izj_mKa-8"; theatre_play["number_of_actors"] = 2;

Revision Problem Two: Solution (continued) Dot-notation var theatre_play = {}; theatre_play.title = "a Play featuring an iphone power block and a mechanical pencil"; theatre_play.number_of_spectators = 266346; theatre_play.venue = "M8izj_mKa-8"; theatre_play.number_of_actors = 2;

Revision Problem Two: Solution (continued) Literal var theatre_play = { title: "a Play featuring an iphone power block and a mechanical pencil", number_of_spectators: 266346, venue: "M8izj_mKa-8", number_of_actors: 2 };

Problem Three: More drawing! Revision Question Draw a graphical representation for x, y, z after evaluating the following programs. var x = pair(1, my_object); var y = {q: 4, p: theatre_play}; var z = my_object; z.play = pair(theatre_play, theatre_play);

Problem Three: Solution Revision Unified diagram!

Review What is Object Oriented Programming? System is organized around objects that receive messages An object encapsulates data (state) and operations (behaviour) Major Concepts Classes and instances Methods and message passing Inheritance Polymorphism

Review Problem One: DRAW AGAIN?!!? Question Draw the box-and-pointer diagrams of the objects Vessel, ContainerShip, my_boat, my_ship that result from evaluating the following program.

Problem One: Solution Objects Review Diagram :(

Problem Two: Buying Ships Review Question Construct these objects without using a single. and without using new. After evaluating your program, the following program should work as expected. Hint Dot-notation is out. What about literal and square bracket notation?

Problem Two: Solution Objects Review Literal Version var my_boat = { displacement: 20, proto : Vessel["prototype"] }; var my_ship = { displacement: 500, containers: list("c1", "c2"), proto : ContainerShip["prototype] };

Review Problem Two: Solution (continued) Square bracket Version var my_boat = {}; my_boat["displacement"] = 20; my_boat[" proto "] = Vessel["prototype"]; var my_ship = {}; my_boat["displacement"] = 500; my_boat["containers"] = list("c1", "c2"); my_boat[" proto "] = ContainerShip["prototype"];

Review Problem One (reset): Gorilla or Student? Question Now lets create a student object named Harambe. Since Harambe was a little sick on exam day, he didnt perform well and got an exam score of 45. After the creation of the student object, verify all the attribute values of Harambe and then make Harambe introduce himself. Why does it work? Solution var harambe = new Student("Harambe", 45); harambe.introduce_self(); Why? Consider where the variables are stored!

Problem Two: Gorilla with IQ Review Question After some time, the professor realized that he had made a mistake in the grading, and Harambes exam score was amended to 60. Update Harambes exam score to 60, and verify again all the attribute values of Harambe. Is there anything wrong? Solution Change score: harambe.exam_score = 60; Why? Check if we are assigning a value or an expression?

Review Problem Three: Recording System PRO Question To fix the problem above, lets add to the Student class a method called update_score, which updates the students module grade and mood based on a given score.

Problem Three: Solution Review Solution Student.prototype.update_score = function (new_score) { this.exam_score = new_score; this.module_grade = this.exam_score < 50? "C" : this.exam_score <= 75? "B" : "A"; this.mood = this.module_grade === "C"? "still happy because I can..." : "happy"; };

Problem Four: Introduction? Review Question We now want to change the students way of introducing himself/herself such that he/she also introduces himself/herself as a student. We try to achieve this by adding these lines: Student.introduce_self = function(){ display("hello, my name is " + this.name +" and my mood is " + this.mood); display("i am also a student!"); }; Try letting Harambe introduce himself again. Is there any difference? Why?

Problem Four: Solution Review Why? Differences between prototype and instance variables.

Problem Five: Irritating Objects Review Question Correct the above problem so that a student can introduce himself/herself as a student. Can Harambe now introduce himself correctly? Will it still work if we define introduce_self in Student.prototype? Why? Solution It will work. It is due to how a function call is processed by the interpreter (using proto )

Problem One Eh: Flip/Flop Question Define a function flip (with no parameters) that returns 1 the first time it is called, 0 the second time it is called, 1 the third time, 0 the fourth time, and so on. Answer function make_flip() { var state = 0; return function() { state = (state === 1)? 0 : 1; return state; }; } var flip = make_flip();

Problem One Bee: FlipFactory Question Define a class Flip that can be used to generate flip objects. That is, we should be able to write var flip = new Flip(); Define a constructor Flip and a method flip. The first time you invoke the method flip on a Flip object, it returns 1, the second time 0, the third time 1, and so on.

Problem One Bee: Solution Solution function Flip() { this.state = 0; } Flip.prototype.flip = function() { this.state = (this.state === 1)? 0 : 1; return this.state; };