I have a homework assignment that asks for me to make a class named Coord containing two double variables named xval and yval. In the class, there should be construtor and display methods and a friend function named conPol(). convPol() should accept two doubles, r and theta to convert polar coordinates into polar coordinates. I have everything coded, except now I've run into some errors. Here is what I have so far
#include <iostream>
#include <cmath>
using namespace std;
class Coord
{
friend double covPol(Coord&, Coord&);
private:
double xval, yval;
public:
Coord(double, double);
void display();
};
Coord::Coord(double X, double Y)
{
xval = X;
yval = Y;
}
void Coord::display()
{
cout << "The x-cordinate is: " << endl;
cout << "The y- coordinate is: " << endl;
}
double convPol(Coord &r, Coord &theta)
{
xval = r* cos (theta);
yval = r* sin (theta);
}
int main()
{
Coord One(2 , 4);
One.convPol(2,4);
One.display();
return 0;
}
Here are the errors:
Error 1 error C2065: 'xval' : undeclared identifier c:\users\thomas\documents\visual studio 2013\projects\conpol().cpp\conpol().cpp\source.cpp 36 1 conPol().cpp
Error 2 error C2665: 'cos' : none of the 3 overloads could convert all the argument types c:\users\thomas\documents\visual studio 2013\projects\conpol().cpp\conpol().cpp\source.cpp 36 1 conPol().cpp
Error 3 error C2065: 'yval' : undeclared identifier c:\users\thomas\documents\visual studio 2013\projects\conpol().cpp\conpol().cpp\source.cpp 37 1 conPol().cpp
Error 4 error C2665: 'sin' : none of the 3 overloads could convert all the argument types c:\users\thomas\documents\visual studio 2013\projects\conpol().cpp\conpol().cpp\source.cpp 37 1 conPol().cpp
Error 5 error C2039: 'convPol' : is not a member of 'Coord' c:\users\thomas\documents\visual studio 2013\projects\conpol().cpp\conpol().cpp\source.cpp 45 1 conPol().cpp
6 IntelliSense: identifier "xval" is undefined c:\Users\Thomas\Documents\Visual Studio 2013\Projects\conPol().cpp\conPol().cpp\Source.cpp 36 2 conPol().cpp
7 IntelliSense: no instance of overloaded function "cos" matches the argument list
argument types are: (Coord) c:\Users\Thomas\Documents\Visual Studio 2013\Projects\conPol().cpp\conPol().cpp\Source.cpp 36 12 conPol().cpp
8 IntelliSense: identifier "yval" is undefined c:\Users\Thomas\Documents\Visual Studio 2013\Projects\conPol().cpp\conPol().cpp\Source.cpp 37 2 conPol().cpp
9 IntelliSense: no instance of overloaded function "sin" matches the argument list
argument types are: (Coord) c:\Users\Thomas\Documents\Visual Studio 2013\Projects\conPol().cpp\conPol().cpp\Source.cpp 37 12 conPol().cpp
From what I understand from this, is that my friend function is not able to get the private variables from my class. Also, my sin and cos functions are not working. I've included so I'm not sure why it doesn't work. As for the friend function not being able to get the variables, I've no idea.