Help with Polygon set errors, Much appreciated!!!! :)

I'm receiving the following compiler errors:

Undefined symbols for architecture x86_64:
"Polygon::numPolygons", referenced from:
Polygon::Polygon() in polygon-b5c78f.o
Polygon::Polygon(int, int) in polygon-b5c78f.o
"Polygon::totalPerimeter", referenced from:
Polygon::calculatePerimeter() in polygon-b5c78f.o
"Polygon::totalArea", referenced from:
Polygon::calculateArea() in polygon-b5c78f.o
ld: symbol(s) not found for architecture x86_64

Header file:

#ifndef POLYGON_H
#define POLYGON_H

#include <iostream>
using namespace std;

class Polygon{
public:
Polygon();
Polygon(int, int);
Polygon(int, int, int, int, int, int);
~Polygon();


void input();
void inputLength();
void inputWidth();

void display();


bool setLength(int);
bool setWidth(int);


static int getNumPolygons();
int getLength();
int getWidth();
int getArea();
int getPerimeter();
int getMIN();
int getMAX();


void calculateArea();
void calculatePerimeter();


void DrawPolygon();

private:
static const int MAX_POLYGONS = 25;
static int numPolygons, totalArea, totalPerimeter;
const int MAX, MIN;
static const int DEFAULT_MIN = 10;
static const int DEFAULT_MAX = 100;
int length, width, perimeter, area;

};
#endif

Cpp & Driver files:

#include "Polygon.h"


Polygon::Polygon():MIN(DEFAULT_MIN), MAX(DEFAULT_MAX) {
numPolygons = area = perimeter = length = width = 0;
}

Polygon::Polygon( int min, int max ): MIN(min), MAX(max) {
width = 0;
length = 0;
perimeter = 0;
area = 0;
numPolygons = 0;
}

Polygon::Polygon(int min, int max, int l, int w, int p, int a):MIN(min), MAX(max){

length = l;
width = w;
perimeter = p;
area = a;
}


Polygon::~Polygon(){
cout << "destructor";
}

void Polygon::input(){
inputLength();
inputWidth();
calculateArea();
calculatePerimeter();
}

void Polygon::display(){

cout << "Length: " << getLength() << endl;
cout << "Width: " << getWidth() << endl;
cout << "Area: " << getArea() << endl;
cout << "Perimeter: " << getPerimeter() << endl;
cout << "Min: " << getMIN() << endl;
cout << "Max: " << getMAX() << endl;

}



bool Polygon::setLength(int l){
bool confirm = false;
if(l >= MIN && l <= MAX){
length = l;
confirm = true;
}

return(confirm);
}

bool Polygon::setWidth(int w){
bool confirm = false;
if (w >= MIN && w <= MAX){
width = w;
confirm = true;
}

return (confirm);
}




void Polygon::inputLength(){
int l;
do{
cout << "Please input the length of the polygon." <<endl;
cin >> l;
}while(!setLength(l));
}

void Polygon::inputWidth(){
int w;
do{
cout << "Please input the width of the polygon." <<endl;
cin >> w;
}while(!setWidth(w));
}


void Polygon::calculateArea(){
area = length*width;
totalArea = totalArea + area;
}
void Polygon::calculatePerimeter(){
perimeter = (2*width) + (2*length);
totalPerimeter = totalPerimeter + perimeter;
}

//int Polygon::getNumPolygons(){
// return (numPolygons);
//}
int Polygon::getLength(){
return (length);
}
int Polygon::getWidth(){
return (width);
}
int Polygon::getArea(){
return(area);
}
int Polygon::getPerimeter(){
return (perimeter);
}
int Polygon::getMIN(){
return (MIN);
}
int Polygon::getMAX(){
return (MAX);
}

void Polygon::DrawPolygon(){

for(int i = 0; i <= length; i++){

for(int j = 0; j <= width; j++){

if (i > 0 || i < length || j > 0 || j < width){

cout << " " << endl;
}

else{
cout << "*" << endl;
}
}
cout << endl;
}
}


int main(){

Polygon p1;


p1.input();
p1.display();




}
You need to define the static members of the class.

This static int numPolygons, totalArea, totalPerimeter; requires something like:
1
2
3
4
5
6
7
8
9
10
11
12
#include "Polygon.h"


int Polygon::numPolygons = 0;
int Polygon::totalArea = 0;
int Polygon::totalPerimeter = 0;



Polygon::Polygon():MIN(DEFAULT_MIN), MAX(DEFAULT_MAX) {
numPolygons = area = perimeter = length = width = 0;
}
Topic archived. No new replies allowed.