Mam taki program i przez konstruktor robię dostęp do provate float r, ale nie działa. Jeśli dam protected to jest ok, Jednak to chodz o to żeby to "r" było prywatne. Ne wiem gdzie robię błąd.
#include <iostream>
#include <math.h>
using namespace std;
class Kolo
{
float r,x,y;
string nazwa;
public:
void wyswietl()
{
cout<<"Jest to koło "<<nazwa<<" o promieniu"<<r<<endl;
cout<<"Œrodek koła ("<<x<<","<<y<<")"<<endl;
cout<<"Powierzchnia tego ko³a wynosi: "<<M_PI*r*r<<endl;
}
Kolo(string n="Felga",float promien=1,float a=1,float b=1)
{
nazwa =n;
r=promien;
x=a;
y=b;
}
};
class Kula:public Kolo
{
string nazwa;
public:
void wyswietl()
{
cout<<"Kula o nazwie "<<nazwa<<endl;
cout<<"Ob Kuli to :"<<M_PI*3/4*r*r*r<<endl;
}
Kula(string nk="pilka",float promien=8,float a=0,float b=0)
:Kolo(nk,promien,a,b)
{
string name = nk;
}
};
int main()
{
setlocale(LC_ALL,"");
cout << "Hello world!" << endl;
Kula k1("pilka",4,1,2);
k1.wyswietl();
return 0;
}