This preview shows page 1-2-3-4-5-6-7-51-52-53-54-55-56-57-58-102-103-104-105-106-107-108 out of 108 pages.
61A Lecture 8Wednesday, September 14Sunday, September 11, 2011Data Abstraction2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude•An abstract data type lets us manipulate compound objects as units2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude•An abstract data type lets us manipulate compound objects as units•Isolate two parts of any program that uses data:2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude•An abstract data type lets us manipulate compound objects as units•Isolate two parts of any program that uses data:How data are represented (as parts)2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude•An abstract data type lets us manipulate compound objects as units•Isolate two parts of any program that uses data:How data are represented (as parts)How data are manipulated (as units)2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude•An abstract data type lets us manipulate compound objects as units•Isolate two parts of any program that uses data:How data are represented (as parts)How data are manipulated (as units)•Data abstraction: A methodology by which functions enforce an abstraction barrier between representation and use2Sunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude•An abstract data type lets us manipulate compound objects as units•Isolate two parts of any program that uses data:How data are represented (as parts)How data are manipulated (as units)•Data abstraction: A methodology by which functions enforce an abstraction barrier between representation and use2All ProgrammersSunday, September 11, 2011Data Abstraction•Compound objects combine primitive objects together•A date: a year, a month, and a day•A geographic position: latitude and longitude•An abstract data type lets us manipulate compound objects as units•Isolate two parts of any program that uses data:How data are represented (as parts)How data are manipulated (as units)•Data abstraction: A methodology by which functions enforce an abstraction barrier between representation and use2All ProgrammersGreat ProgrammersSunday, September 11, 2011Rational Numbers3Sunday, September 11, 2011Rational Numbers3numeratordenominatorSunday, September 11, 2011Rational NumbersExact representation of fractions3numeratordenominatorSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integers3numeratordenominatorSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integersAs soon as division occurs, the exact representation is lost!3numeratordenominatorSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integersAs soon as division occurs, the exact representation is lost!Assume we can compose and decompose rational numbers:3numeratordenominatorSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integersAs soon as division occurs, the exact representation is lost!Assume we can compose and decompose rational numbers:3numeratordenominator•make_rat(n, d) returns a rational number xSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integersAs soon as division occurs, the exact representation is lost!Assume we can compose and decompose rational numbers:3numeratordenominator•make_rat(n, d) returns a rational number xConstructorSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integersAs soon as division occurs, the exact representation is lost!Assume we can compose and decompose rational numbers:3numeratordenominator•make_rat(n, d) returns a rational number x•numer(x) returns the numerator of xConstructorSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integersAs soon as division occurs, the exact representation is lost!Assume we can compose and decompose rational numbers:3numeratordenominator•make_rat(n, d) returns a rational number x•numer(x) returns the numerator of x•denom(x) returns the denominator of xConstructorSunday, September 11, 2011Rational NumbersExact representation of fractionsA pair of integersAs soon as division occurs, the exact representation is lost!Assume we can compose and decompose rational numbers:3numeratordenominator•make_rat(n, d) returns a rational number x•numer(x) returns the numerator of x•denom(x) returns the denominator of xConstructorSelectorsSunday, September 11, 2011Rational Number Arithmetic4Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*910=Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*910=nxdxnydy*Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*910=nxdxnydy*nx*nydx*dy=Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*910=3235+nxdxnydy*nx*nydx*dy=Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*910=3235+2110=nxdxnydy*nx*nydx*dy=Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*910=3235+2110=nxdxnydy*nx*nydx*dy=nxdxnydy+Example:General Form:Sunday, September 11, 2011Rational Number Arithmetic43235*910=3235+2110=nxdxnydy*nx*nydx*dy=nxdxnydy+nx*dy
View Full Document