Теперь все работает кроме сортировки массива
Код:
#include <iostream>
#include <conio>
#include <vcl.h>
#include <typeinfo>
#pragma hdrstop
class Intarface
{
public:
virtual void Show() = 0;
virtual string _toString() = 0;
virtual int getTotalObjects() = 0;
virtual void setCurrentNumberObject() = 0;
virtual int getCurrentNumberObject() = 0;
virtual bool operator>(Intarface& obj) = 0;
virtual bool operator<(Intarface& obj) = 0;
virtual Intarface* _toObject(string temp) = 0;
virtual Intarface& operator=(Intarface* obj) = 0
};
class Steblo : public Intarface
{
private:
float length;
string title;
static int totalObjects;
int currentNumber;
public:
Steblo();
Steblo(float _length, string _title);
~Steblo();
virtual void Show() {
cout << this->length << " " << this->title;
}
virtual Intarface* _toObject(string temp);
virtual string _toString();
virtual Intarface& operator=(Intarface* obj);
virtual bool operator>(Intarface& obj);
virtual bool operator<(Intarface& obj);
virtual int getTotalObjects();
virtual void setCurrentNumberObject();
virtual int getCurrentNumberObject();
};
int Steblo::totalObjects = 0;
Steblo::Steblo()
{
this->length = 25.5;
this->title = "Lilya";
this->setCurrentNumberObject();
}
Steblo::Steblo(float _length, string _title)
{
this->length = _length;
this->title = _title;
this->setCurrentNumberObject();
}
Intarface* Steblo::_toObject(string temp)
{
float fg;
int found = 0;
int totalVhod = 0;
string temp1;
string temp2[2];
int i = 0;
found = temp.find("_", 0);
do
{
temp1 = temp.substr(found + 1);
temp2[i] = temp.substr(0, found);
temp = temp1;
found = temp.find("_", 0);
totalVhod = temp.rfind("_", 0);
if(found == totalVhod) temp2[i + 1] = temp;
i++;
}while(found > 0);
fg = atof(temp2[0].c_str()); //Ïåðåòâîðåííÿ ðÿäêà â ÷èñëî ç ïëàâàþ÷îþ êîìîþ
Intarface *pInter;
Steblo Steblo1(fg, temp2[1]);
pInter = &Steblo1;
return pInter;
}
string Steblo::_toString()
{
string temp;
char buf[10];
sprintf(buf,"%2.1f",this->length);
temp.append(buf);
temp.append("_");
temp.append(this->title);
return temp;
}
Intarface& Steblo::operator=(Intarface* obj)
{
string temp = obj->_toString();
obj = obj->_toObject(temp);
this->operator =(obj);
return *this;
}
bool Steblo::operator>(Intarface& obj)
{
if(this->currentNumber > obj.getCurrentNumberObject()) return true;
else return false;
}
bool Steblo::operator<(Intarface& obj)
{
if(this->currentNumber < obj.getCurrentNumberObject()) return true;
else return false;
}
int Steblo::getTotalObjects()
{
return this->totalObjects;
}
void Steblo::setCurrentNumberObject()
{
this->totalObjects++;
this->currentNumber = this->totalObjects;
}
int Steblo::getCurrentNumberObject()
{
return this->currentNumber;
}
Steblo::~Steblo()
{
this->length = NULL;
this->title.clear();
this->totalObjects--;
this->currentNumber = NULL;
}
void SortingBibles(Intarface* arr, int SIZE)
{
Intarface *pTemp;
//pTemp = &arr[0];
for(int x = SIZE; x > 0; x--)
{
for(int i = 0; i < SIZE - 1; i++)
{
if(arr[i] > arr[i + 1])
{
pTemp = arr[i];
arr[i] = arr[i+1];
arr[i + 1] = pTemp;
}
}
}
}
#pragma argsused
int main(int argc, char* argv[])
{
Intarface *pIntarface;
string temp23 = "5.5_Beladonna";
Steblo pSteblo;
Steblo *pSteblo1;
pSteblo1 = new Steblo[10];
pIntarface = &pSteblo;
pSteblo1[0] = createObject();
pSteblo1[1].Show();
cout << endl;
pSteblo1[0].Show();
cout << endl;
pIntarface->Show();
cout << endl;
pSteblo1[0] = pSteblo1[3];
pSteblo1[0].Show();
cout << endl;
pSteblo1[0] = pSteblo1[1];
cout << pSteblo1[0].getTotalObjects() << endl;
delete[]pSteblo1;
getch();
return 0;
}