Chapter 3: Objects

Chapter Goals

Constructing Objects

Constructing Objects (Syntax 3.1)

Syntax 3.1 : Object Construction

Class_name(construction parameters);
Example:
Time(19, 0, 0);
Purpose: Construct a new object for use in an expression.

Constructing Objects (Syntax 3.2)

Syntax 3.2 : Object Variable Definition

Class_name variable_name(construction parameters);
Example:
Time homework_due(19, 0 0);
Purpose: Define a new object variable and supply parameter values for initialization.

Constructing Objects (Time class)

Constructing Objects (Object Construction)

Using Objects

Using Objects (time1.cpp)

Using Objects

Using Objects (time2.cpp)

Real-Life Objects

Real-Life Objects (employee.cpp)

Displaying Graphical Shapes

Graphics Structures (Points)

Graphics Structures (Circles)

Graphics Structures (Lines)

Graphics Structures (Messages)

Graphics Structures (move())

Graphics Structures (square.cpp)

Graphics Structures (square.cpp (Output))

Graphics Structures (Summary)

Name
Purpose
Point(x, y) Constructs a point at location (x, y)
p.get_x() Returns the x-coordinate of a point p
p.get_y() Returns the y-coordinate of a point p
p.move(dx, dy) Moves point by by (dx, dy)
Name
Purpose
Circle(p, r) Constructs a circle with center p and radius r
c.get_center() Returns the center point of a circle c
c.get_radius() Returns the radius of a circle c.
c.move(dx, dy) Moves circle c by (dx, dy)
Name
Purpose
Line(p, q) Constructs a line joining points p and q
l.get_start() Returns the starting point of line l
l.get_end() Returns the end point of line l
l.move(dx, dy) Moves line l by (dx, dy)
Name
Purpose
Message(p, s) Constructs a message with starting point p and text string s
Message(p, x) Constructs a message with starting point p and label equal to the number x
m.get_start() Returns the starting point of message m.
m.get_text() Gets the text string message m
m.move(dx, dy) Moves message m by (dx, dy)

Choosing a Coordinate System

Getting Input from the Graphics Window