Nizej jest kod ktory nie dziala. Staram sie aby iterator wyswietlil pole i obwod figury ale niestety nie trybi :/ Ktos wie jak to naprawic? Przeciazylem strumien dla klasy kwadrat i prosokat i proboje to zrobic poprzez cout << &it jednak niestety nie dziala ;[
#ifndef Figura_h
#define Figura_h
#include<string>
#include<iostream>
using namespace std;
class figura{
public:
figura(){
}
~figura(){
}
virtual string getNazwa(){
return nazwa;
}
virtual double obwod(){
return 0;
}
virtual double pole(){
return 0;
}
virtual figura getData(){
figura ob;
return ob;
}
virtual void wyswietl(){
cout << getNazwa() << ", Obwod: " << obwod() << ", Pole: " << pole() << endl;
}
protected:
string nazwa;
};
#endif
#ifndef kwadrat_h
#define kwadrat_h
#include"Figura.h"
class kwadrat : public figura{
private:
double a;
public:
kwadrat(){
nazwa = "Kwadrat domyslny";
}
kwadrat(double a, string name){
this->a = a;
this->nazwa = name;
}
~kwadrat(){}
virtual double obwod(){
return 4*a;
}
virtual double pole(){
return a*a;
}
virtual string getNazwa(){
return nazwa;
}
virtual figura getData(){
cin >> a;
cin >> nazwa;
kwadrat kwadzio(a,nazwa);
return kwadzio;
}
virtual void wyswietl(){
cout << getNazwa() << ", Obwod: " << obwod() << ", Pole: " << pole() << endl;
}
friend ostream & operator <<(ostream * out, kwadrat &sample);
};
ostream &operator << (ostream &out, kwadrat &sample){
out << "Pole kwadratu wynosi " << sample.pole() << ", a obwod: " << sample.obwod() << endl;
return out;
}
#endif
#ifndef prosokat_h
#define prosokat_h
#include"Figura.h"
class prostokat : public figura{
public:
prostokat(){
nazwa = "Prostokat";
}
prostokat(double a, double b, string name){
this->a = a;
this->b = b;
this->nazwa = name;
}
~prostokat(){}
virtual double obwod(){
return (2*a)+(2*b);
}
virtual double pole(){
return a*b;
}
virtual string getNazwa(){
return nazwa;
}
virtual figura getData(){
cin >> a;
cin >> b;
cin >> nazwa;
prostokat prostokacik(a,b,nazwa);
return prostokacik;
}
virtual void wyswietl(){
cout << getNazwa() << ", Obwod: " << obwod() << ", Pole: " << pole() << endl;
}
friend ostream & operator << (ostream & out, prostokat &sample);
private:
double a,b;
};
ostream & operator << (ostream & out, prostokat &sample){
out << "Pole wynosi " << sample.pole() << ", natomiast obwod " << sample.obwod() << endl;
return out;
}
#endif
#ifndef Header_h
#define Header_h
#include"prostokat.h"
#include"Figura.h"
#include"kwadrat.h"
#include<vector>
#include<iterator>
class BazaFigur{
public:
BazaFigur(){}
~BazaFigur(){
}
void dodajKwadrat(){
kwadrat *kwadzio;
kwadzio->getData();
dodajFigure(kwadzio);
}
void dodajProsokat(){
prostokat *prosokat;
prosokat->getData();
dodajFigure(prosokat);
}
void dodajFigure(figura *nowa){
Baza.push_back(nowa);
}
void czytej(){
int ile = Baza.size();
vector<figura*>::iterator it;
for(it=Baza.begin();it!=Baza.end();++it){
cout << ⁢
}
}
private:
vector<figura*> Baza;
};
#endif
#include"Header.h"
#include<iostream>
#include<string>
using namespace std;
void main(){
BazaFigur nowa;
kwadrat *kwadzio = new kwadrat();
kwadzio->getData();
prostokat *prostokont = new prostokat();
prostokont->getData();
nowa.dodajFigure(kwadzio);
nowa.dodajFigure(prostokont);
nowa.czytej();
cin.ignore(2);
}
Zakładki