Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

Exercise 5: Segments

Consider the problem of representing line segments in a plane. Each segment is represented as a pair of points: a starting point and an ending point. Define a constructor make-segment and selectors start-segment and end-segment that define the representation of segments in terms of points. Furthermore, a point can be represented as a pair of numbers: the x coordinate and the y coordinate. Accordingly, specify a constructor make-point and selectors x-point and y-point that define this representation. Finally, using your selectors and constructors, define a procedure midpoint-segment that takes a line segment as argument and returns its midpoint (the point whose coordinates are the average of the coordinates of the endpoints)

  1. There is an abstract data type that supports an invariant1:

    There is an abstract data type that supports an invariant1:

    If we construct point p from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

  2. There is an abstract data type that supports an invariant2:

    If we construct a line segment l from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

If we construct point p from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

  1. There is an abstract data type that supports an invariant2:

If we construct a line segment l from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

Exercise 5: Segments

Consider the problem of representing line segments in a plane. Each segment is represented as a pair of points: a starting point and an ending point. Define a constructor make-segment and selectors start-segment and end-segment that define the representation of segments in terms of points. Furthermore, a point can be represented as a pair of numbers: the x coordinate and the y coordinate. Accordingly, specify a constructor make-point and selectors x-point and y-point that define this representation. Finally, using your selectors and constructors, define a procedure midpoint-segment that takes a line segment as argument and returns its midpoint (the point whose coordinates are the average of the coordinates of the endpoints)

  1. There is an abstract data type that supports an invariant1:

If we construct point p from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

  1. There is an abstract data type that supports an invariant2:

If we construct a line segment l from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

Exercise 5: Segments

Consider the problem of representing line segments in a plane. Each segment is represented as a pair of points: a starting point and an ending point. Define a constructor make-segment and selectors start-segment and end-segment that define the representation of segments in terms of points. Furthermore, a point can be represented as a pair of numbers: the x coordinate and the y coordinate. Accordingly, specify a constructor make-point and selectors x-point and y-point that define this representation. Finally, using your selectors and constructors, define a procedure midpoint-segment that takes a line segment as argument and returns its midpoint (the point whose coordinates are the average of the coordinates of the endpoints)

  1. There is an abstract data type that supports an invariant1:

    If we construct point p from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

  2. There is an abstract data type that supports an invariant2:

    If we construct a line segment l from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

added 721 characters in body; edited title
Source Link
overexchange
  • 3.4k
  • 8
  • 35
  • 63

Representing Building Data abstraction for line segments in a plane using functional paradigm"objects"

I follow this definition of "object":An object is a value exporting a procedural interface to data or behavior. Objects use procedural abstraction for information hiding, not type abstraction. Object and and their types are often recursive. Objects provide a simple and powerful form of data abstraction. They can be understood as closures, first-class modules, records of functions, or processes. Objects can also be used for procedural abstraction. from this paper

Below is the given exercise:

It is taught in class that data abstractiondata abstraction is the methodology to create barrier between "how data values are used" and "how data values are represented". Also, an abstract data typeabstract data type is some collection of selectors and constructors, together with some behaviour conditions (invariants).

It is compound data that needs data processing which actually enables to think about data abstraction because the user would like to use this compound data as single unit.

Below code is building "data abstraction" and "ADT" for "line segments" using python objects

ConstructorIn the above code, constructor and selectors constitute ADT.

So, above implementation has set of "objects" that build "Data abstraction"

Representing line segments in a plane using functional paradigm

Below is the given exercise:

It is taught in class that data abstraction is the methodology to create barrier between "how data values are used" and "how data values are represented". Also, an abstract data type is some collection of selectors and constructors, together with some behaviour conditions (invariants).

It is compound data that needs data processing which actually enables to think about data abstraction because the user would like to use this compound data as single unit.

Constructor and selectors constitute ADT.

Building Data abstraction for line segments using "objects"

I follow this definition of "object":An object is a value exporting a procedural interface to data or behavior. Objects use procedural abstraction for information hiding, not type abstraction. Object and and their types are often recursive. Objects provide a simple and powerful form of data abstraction. They can be understood as closures, first-class modules, records of functions, or processes. Objects can also be used for procedural abstraction. from this paper

Below is the given exercise:

It is taught in class that data abstraction is the methodology to create barrier between "how data values are used" and "how data values are represented". Also, an abstract data type is some collection of selectors and constructors, together with some behaviour conditions (invariants).

It is compound data that needs data processing which actually enables to think about data abstraction because the user would like to use this compound data as single unit.

Below code is building "data abstraction" and "ADT" for "line segments" using python objects

In the above code, constructor and selectors constitute ADT.

So, above implementation has set of "objects" that build "Data abstraction"

deleted 149 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

It is taught in the class that Datadata abstraction is the methodology to create barrier between "how"how data values are used"used" and "how"how data values are represented"represented".

It is taught in the class that Abstract Data Type Also, an abstract data type is some collection of selectors and constructors, together with some behaviour conditions(invariants).

It is taught in the class that, It is compound data that needs data processing which actually enables to think about Datadata abstraction. Because because the user would like to use this compound data as single unit.

Based on which,

Below is the solution in functional paradigm:

Constructor ansand selectors constitute ADT.

In the above two implementations,:

  1. There is an abstract data type that supports an invariant1:

a) there is an abstract data type that supports anIf we construct point invariant1p: from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

If we construct point p from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

  1. There is an abstract data type that supports an invariant2:

b) there is an abstract data type that supports anIf we construct a line segment invariant2l: from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

If we construct a line segment l from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

Is my understanding correct on designing "Data abstraction"data abstraction and "ADT"ADT for line segments?

It is taught in the class that Data abstraction is the methodology to create barrier between "how data values are used" and "how data values are represented".

It is taught in the class that Abstract Data Type is some collection of selectors and constructors, together with some behaviour conditions(invariants).

It is taught in the class that, It is compound data that needs data processing which actually enables to think about Data abstraction. Because user would like to use this compound data as single unit.

Based on which,

Below is the solution in functional paradigm:

Constructor ans selectors constitute ADT. In the above two implementations,

a) there is an abstract data type that supports an invariant1:

If we construct point p from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

b) there is an abstract data type that supports an invariant2:

If we construct a line segment l from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

Is my understanding correct on designing "Data abstraction" and "ADT" for line segments?

It is taught in class that data abstraction is the methodology to create barrier between "how data values are used" and "how data values are represented". Also, an abstract data type is some collection of selectors and constructors, together with some behaviour conditions(invariants).

It is compound data that needs data processing which actually enables to think about data abstraction because the user would like to use this compound data as single unit.

Constructor and selectors constitute ADT.

In the above two implementations:

  1. There is an abstract data type that supports an invariant1:

If we construct point p from x-coordinate a and y-coordinate b, then x_coordinate(p), y_coordinate(p) must equal a, b

  1. There is an abstract data type that supports an invariant2:

If we construct a line segment l from point p1 and point p2, then start_segment(l)______end_segment(l) must equal p1______p2

Is my understanding correct on designing data abstraction and ADT for line segments?

added 528 characters in body
Source Link
overexchange
  • 3.4k
  • 8
  • 35
  • 63
Loading
edited tags
Link
Pimgd
  • 22.5k
  • 5
  • 68
  • 144
Loading
Post Reopened by rolfl
added 16 characters in body
Source Link
overexchange
  • 3.4k
  • 8
  • 35
  • 63
Loading
added 16 characters in body
Source Link
overexchange
  • 3.4k
  • 8
  • 35
  • 63
Loading
Post Closed as "Needs details or clarity" by rolfl
Source Link
overexchange
  • 3.4k
  • 8
  • 35
  • 63
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /