Programming and Graphics

(Kiana) #1

6.7 Circles and squares 165


The circles are defined by their center and radius, and the squares are defined
by their center and side length. In both cases, thexandycoordinates of the
center are hosted by a two-slot vector namedcenter[2].


The circle class definition is:


#include <iostream>
using namespace std;

//--- CIRCLE CLASS DEFINITION

class circle
{
public:
circle(double, double, double);
void print() const;
private:
double center[2], rad;
};

The square class definition is:


//--- SQUARE CLASS DEFINITION

class square
{
public:
square(double, double, double);
void print() const;
private:
double center[2], side;
};

The circle class implementation is:


//--- CIRCLE CLASS IMPLEMENTATION

circle::circle(double centerx, double centery, double radius)
{
center[0] = centerx;
center[1] = centery;
rad = radius;
}

void circle::print() const
{
cout << center[0] <<""<<center[1] <<""<<rad<<endl;
}
Free download pdf