I am working off the code that the professor provided, but for some reason I cannot get it to work. It is giving me errors.
I created a project in Visual Studio.
The header file:
#include <iostream>
#include <math.h>
using namespace std;
class xy_coordinate
{
public:
void input();
void print();
double radius();
double angle();
private:
double x,y;
};
Source:
#include <iostream>
#include <math.h>
using namespace std;
void xy_coordinate::input()
{cin>>x>>y;}
void xy_coordinate::print ()
{cout << "(" << x << "," << y <<")" << "\n";}
double xy_coordinate::radius()
{return sqrt (x*x+y*y);}
double xy_coordinate::angle()
{double z, pi= 3.141593;
if (x>=0)
z= atan (y/x);
if (x<0 && y>0)
z = atan (y/x) + pi;
if (x<0 && y <=0)
z = atan (y/x) - pi;
if (x == 0 && y ==0)
z= 0;
return z;
}
I had to replace #include <iostream.h> with #include <iostream>
and adding using namespace std;
because visual studio would not find iostream.h
the error I recieve are the following:
1>source.cpp(5) : error C2653: 'xy_coordinate' : is not a class or namespace name
1>source.cpp(7) : error C2065: 'x' : undeclared identifier
1>source.cpp(7) : error C2065: 'y' : undeclared identifier
1>source.cpp(9) : error C2653: 'xy_coordinate' : is not a class or namespace name
1>source.cpp(13) : error C2653: 'xy_coordinate' : is not a class or namespace name
1>source.cpp(16) : error C2653: 'xy_coordinate' : is not a class or namespace name