Rectangle class uses association to link with Point - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Rectangle class uses association to link with Point

Description:

Set up a class called Point which contains two. Members x and y which represent a point on the ... (const Rectangle& toCopy) p1 = new Point(toCopy.p1- getx ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 9
Provided by: johnb152
Category:

less

Transcript and Presenter's Notes

Title: Rectangle class uses association to link with Point


1
Rectangle class uses association to link with
Point
Rectangle
Point
2
Two methods of resolving
  • Pointers to members
  • Member variables

3
Tutorial Exercise
Set up a class called Point which contains two
Members x and y which represent a point on
the Screen. Write functions to return the values
associated with x and y. Now write a class
called Rectangle which contains two Points. The
Points represent the top left screen position and
the bottom Right screen position for the
rectangle. Write functions to return the values
associated with the points In the rectangle. You
will obviously need to provide suitable Constructo
rs. Experiment with the pointer and non pointer
members solutions
4
Non Pointer Solution for Rectangle
Class Rectangle Point p1 Point
p2 public Rectangle(int x, int y, int p, int
q) Point getp1() Point getp2()
5
Constructors
Rectangle(int x, int y, int p, int q) p1(x,y),
p2(p,q) Rectangle() or none
6
Using Pointer member variables
Class Rectangle Point p1 Point
p2 public Rectangle(int x, int y, int p, int
q) Point getp1() Point getp2()
7
Constructors
Rectangle(Point a, Point b) p1 a p2
b Rectangle(int x, int y, int p, int q) p1
new Point(x,y) p2 new Point(p,q)
8
Copy constructor
Rectangle(const Rectangle toCopy) p1 new
Point(toCopy.p1-gtgetx(), toCopy.p1-gtgety()
p2 . Rectangle() if (p1
! 0) delete p1 if ( p2 ! 0) delete p2
Write a Comment
User Comments (0)
About PowerShow.com