Hey guys. Ive been trying to write this program for a while and I keep getting errors on line 78, "Circle undeclared." I think it has something to do with the constructors and templates. I dont think im calling it right. Can someone take a look at it for me and tell me where I went wrong? I think I have everything else right(hopefully). I think if you read the code you can see what the program is supposed to do. Thanks!
#include <iostream>
#include <cstdlib>
#include <cmath>
#define pi 3.14159265
using namespace std;
template <class T>
class circle {
public:
circle();
circle(T,T,T,T);
void populate_classobj(T a1, T b1, T a2, T b2);
T radius();
T circumference();
T area();
private:
T x1,x2,y1,y2;
protected:
T distance();
}; //End of class
//Function definitions
template <class T>
circle<T>::circle(T a1,T b1,T a2,T b2)
{
x1=a1;
y1=b1;
x2=a2;
y2=b2;
}
template <class T>
circle<T>::circle()
{
x1=0;
x2=0;
y1=0;
y2=0;
}
template <class T>
void circle<T>::populate_classobj(T a1, T b1, T a2, T b2)
{
x1=a1;
y1=b1;
x2=a2;
y2=b2;
}
template <class T>
T circle<T>::radius()
{
return distance();
}
template <class T>
T circle<T>::circumference()
{
return pi*radius()*2;
}
template <class T>
T circle<T>::area()
{
return pi*pow(radius(),2);
}
template <class T>
T circle<T>::distance()
{
return sqrt( pow((x2-x1),2) + pow((y2-y1),2) );
}
int main() //Main
{
//Initialize variables
float x1,x2,y1,y2;
int input=0;
//Declare object & variables
circle my_obj1 (1,3);
circle my_obj2 (1.5,-0.5,-6.65,10.0);
while(input<4)
{
//Choose functions to compute
cout<<"Press 1 to compute the radius of the circle"<<endl;
cout<<"Press 2 to compute the circumference"<<endl;
cout<<"Press 3 to compute the area of the circle"<<endl;
cout<<"Press 4 to enter new values for Object 1"<<endl;
cout<<"Press 5 to enter new values for Object 2"<<endl;
cout<<"Press 6 to exit"<<endl;
cin>>input;
//If statements
if(input>6)
{
cout<<"PLEASE PICK A NUMBER BETWEEN 1 AND 6"<<endl;;
input=0;
}
if(input==1)
{
cout<<"Radius of object 1 equals: "<< my_obj1.radius() <<endl;
cout<<"Radius of object 2 equals: "<< my_obj2.radius() <<endl;
}
if(input==2)
{
cout<<"Circumference of object 1 equals: "<< my_obj1.circumference() <<endl;
cout<<"Circumference of object 2 equals: "<< my_obj2.circumference() <<endl;
}
if(input==3)
{
cout<<"Area of object 1 equals: "<< my_obj1.area() <<endl;
cout<<"Area of object 2 equals: "<< my_obj2.area() <<endl;
}
if(input==4)
{
cout<<"Please enter new values for object 1: "<<endl;
my_obj1.populate_classobj(x1,x2,y1,y2);
}
if(input==5)
{
cout<<"Please enter new values for object 2: "<<endl;
my_obj2.populate_classobj(x1,x2,y1,y2);
}
if(input==6)
{
return EXIT_SUCCESS;
}
}//While loop end
//Exit program
system("PAUSE");
return 0;
}