To make class polygon a pure virtual base class, choose the function or function
ID: 3713725 • Letter: T
Question
To make class polygon a pure virtual base class, choose the function or functions that must be overridden by all inherited classes. Adjust polygon.h to become a pure virtual base class. Define polygon.cpp to implement the functions defined in polygon.h.
polygon.h is defined as follows:
class polygon{
private:
int sides;
public:
polygon(int sides); //Constructor - default sides to 3
polygon(const polygon*); //Copy constructor
void setSides(int sides); //setter for private attribute
int getSides() const; //Getter for private attribute
//Other functions
double calcArea(); //calculates the area of a polygon
double calcPerimeter(); //calculates the perimeter of a polygon
void printDimensions(); //displays the dimensions of a polygon along with its area and perimeter
}
Explanation / Answer
polygon.h
#ifndef POLYGON_H
#define POLYGON_H
class polygon{
private:
int sides;
public:
polygon(int sides); //Constructor - default sides to 3
polygon(const polygon*); //Copy constructor
void setSides(int sides); //setter for private attribute
int getSides() const; //Getter for private attribute
//Other functions
virtual double calcArea()=0; //calculates the area of a polygon
virtual double calcPerimeter()=0; //calculates the perimeter of a polygon
virtual void printDimensions()=0; //displays the dimensions of a polygon along with its area and perimeter
};
#endif
polygon.cpp
#include <iostream>
#include "polygon.h"
using namespace std;
polygon::polygon(int sides) //Constructor - default sides to 3
{
this->sides = sides;
}
polygon::polygon(const polygon *p)//Copy constructor
{
this->sides = p->sides;
}
void polygon::setSides(int sides) //setter for private attribute
{
this->sides = sides;
}
int polygon::getSides() const //Getter for private attribute
{
return sides;
}
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.