Diameter 1 float GetSize const void SetSize float Diameter void Draw private

Diameter 1 float getsize const void setsize float

This preview shows page 19 - 28 out of 41 pages.

Diameter = 1); float GetSize() const ; void SetSize( float Diameter); void Draw(); private : float m_Diameter; };
Image of page 19
class CircleShape { public: CircleShape(SimpleWindow &W, float x, float y, const color &Color, float Diameter); void Draw(); color GetColor() const; void GetPosition(float &x, float &y) const; float GetSize() const; SimpleWindow& GetWindow() const; void SetColor(const color &Color); void SetPosition(float x, float y); void SetSize(float Diameter); private: SimpleWindow &Window; float XCenter; float YCenter; color Color; float Diameter; }; No Inheritance
Image of page 20
TriangleShape::Draw() void TriangleShape::Draw() { const float Pi = 3.1415; const Position Center = GetPosition(); const float SLength = GetSideLength(); // Compute c, distance from center of triangle // to the top vertex, and a, the distance from // the center to the base of the triangle float c = SLength / (2.0 * cos(30 * Pi / 180.0)); float a = tan(30 * Pi / 180.0) * .5 * SLength;
Image of page 21
TriangleShape::Draw() // Create an array containing the positions of // the vertices of the triangle vector<Position> TrianglePoints(3); TrianglePoints[0] = Center + Position(0, -c), TrianglePoints[1] = Center + Position(-0.5*SLength, a); TrianglePoints[2] = Center + Position( 0.5*SLength, a); // Draw the triangle GetWindow().RenderPolygon(TrianglePoints, 3, GetColor(), HasBorder()); }
Image of page 22
Using Shapes #include "rect.h" #include "ellipse.h" #include "triangle.h" SimpleWindow Window("TestShapes", 17, 7, Position(4, 4)); int ApiMain() { Window.Open(); TriangleShape T(Window, Position(3.5, 3.5), Red, 3.0); T.Draw(); RectangleShape R(Window, Position(8.5, 3.5), Yellow, 3.0, 2.0); R.Draw(); EllipseShape E(Window, Position(13.5, 3.5), Green, 3.0, 2.0); E.Draw(); return 0; }
Image of page 23
Fun with Shapes
Image of page 24
Inheritance and Member Access class SomeClass { public : void MemberFunction(); int MyPublicData; protected : int MyProtectedData; private : int MyPrivateData; }; void SomeClass::MemberFunction() { MyPublicData = 1; // access allowed MyProtectedData = 2; // access allowed MyPrivateData = 3; // access allowed } void NonMemberFunction() { SomeClass C; C.MyPublicData = 1; // access allowed C.MyProtectedData = 2; // illegal C.MyPrivateData = 3; // illegal }
Image of page 25
Inheritance and Member Access class BaseClass { public : int MyPublicData; protected : int MyProtectedData; private : int MyPrivateData; }; class DerivedClass : public BaseClass { public : void DerivedClassFunction(); // ... }; void DerivedClass::DerivedClassFunction() { MyPublicData = 1; // access allowed MyProtectedData = 2; // access allowed MyPrivateData = 3; // illegal }
Image of page 26
Controlling Inheritance Public inheritance class DerivedClass : public BaseClass { public : // ...
Image of page 27
Image of page 28

You've reached the end of your free preview.

Want to read all 41 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes