--------------------- main.cpp -------------------------------------------------------
#include <iostream>
#include "Header.h"
using namespace std;
int main()
{
Kula k1;
k1.wyswietl();
return 0;
}
-------------------- Header.h -----------------------------------------------
#include <iostream>
#include <string>
using namespace std;
class Punkt
{
float x, y;
string nazwa;
public:
void wyswietl();
Punkt(string n = "S", float a = 0, float b = 0);
};
class Kolo :public Punkt //klasa Kolo dziedziczy publicznie z klasy Punkt
{
protected:
float r;
string nazwa;
public:
void wyswietl();
Kolo(string nk = "Kolko", string np = "S", float a = 0, float b = 0, float pr = 1);
};
class Kula : public Kolo
{
string nazwa;
public:
Kula(string nk = "Kula", string np = "S", float a = 0, float b = 0, float pr = 3);
void wyswietl();
};
---------------------------------- Source.cpp ---------------------------------------------------------
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#include "Header.h"
using namespace std;
void Punkt::wyswietl()
{
cout << nazwa << "(" << x << "," << y << ")" << endl;
}
Punkt::Punkt(string n = "S", float a = 0, float b = 0)
{
nazwa = n;
x = a;
y = b;
}
void Kolo::wyswietl()
{
cout << "Kolo o nazwie: " << nazwa << endl;
cout << "Srodek kola: " << endl;
Punkt::wyswietl();
cout << "Promien: " << r << endl;
cout << "Pole kola : " << M_PI * r*r << endl;
}
Kolo::Kolo(string nk = "Kolko", string np = "S", float a = 0, float b = 0, float pr = 1)
:Punkt(np, a, b)
{
nazwa = nk;
r = pr;
}
Kula::Kula(string nk = "Kula", string np = "S", float a = 0, float b = 0, float pr = 3)
:Kolo(nk, np, a, b, pr)
{
nazwa = nk;
}
void Kula::wyswietl()
{
cout << endl;
Kolo::wyswietl();
cout << "Objetosc kuli : " << ((float)4 / 3)*(M_PI*pow(r, 3)) << endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Błędy dla visual studio enterprise 2017
C2572 'Punkt::Punkt': redefinition of default argument : parameter 1
C2572 'Punkt::Punkt': redefinition of default argument : parameter 2
C2572 'Punkt::Punkt': redefinition of default argument : parameter 3
C2572 'Kolo::Kolo': redefinition of default argument : parameter 1
C2572 'Kolo::Kolo': redefinition of default argument : parameter 2
C2572 'Kolo::Kolo': redefinition of default argument : parameter 3
C2572 'Kolo::Kolo': redefinition of default argument : parameter 4
C2572 'Kolo::Kolo': redefinition of default argument : parameter 5
C2572 'Kula::Kula': redefinition of default argument : parameter 1
C2572 'Kula::Kula': redefinition of default argument : parameter 2
C2572 'Kula::Kula': redefinition of default argument : parameter 3
C2572 'Kula::Kula': redefinition of default argument : parameter 4
C2572 'Kula::Kula': redefinition of default argument : parameter 5