Using @super's suggestion and a little warning fixing.
The two important changes are in the line as suggested by @super:
printf("r=%.3f; phi=%.3f\n",distanta(),phi());
The variables 'r' and 'unghi' are both variables local to member functions and cannot be accessed outside of those functions. The "distanta()" and "phi()" member functions provide exactly what is needed in the printf and are the perfect way of getting the values needed.
The other change is explicitly stating that mprint() is a void:
void mprint(){
All functions in C++ (even main!) must have a return type. Also removed 'virtual' as there is no derived class (and I would have had to move the function to the public section of the class to keep it as virtual).
I have added the includes and the main() function so that anyone reading this code may cut and paste it into their compiler to get a working version without any more effort.
Further cleanup turns mx and my into private variables to prevent the user of the class from being able to modify these variables.
#include <cmath>
#include <cstdio>
#include <iostream>
class Puncte{
private:
double mx;
double my;
public:
Puncte(double x, double y) {
mx = x;
my = y;
}
double mx() {return mx;}
double my() {return my;}
double distanta (){
double r = sqrt(mx*mx + my*my);
return r;
}
double phi (){
double unghi = atan(my/mx) * 180.0 / M_PI;
if(unghi > 0 && mx < 0 && my < 0) unghi = unghi + 180;
if (unghi < 0 && mx>0 && my < 0) unghi = unghi + 360;
if (unghi < 0 && mx<0 && my > 0) unghi = unghi + 180;
return unghi;
}
void mprint(){
printf("r=%.3f; phi=%.3f\n",distanta(),phi()) ; //unable to resolve identifier
}
};
int main() {
Puncte puncte(3.5, 8.9);
std::cout << "Point(" << puncte.mx() << ", " << puncte.my()
<< "): radius = " << puncte.distanta() << std::endl;
return 0;
}
Output:
$> main
Point(3.5, 8.9): radius = 9.56347
Process finished with exit code 0