Question: please help me solve in c++! create a class of type has-a with the following class - class coloana {private: char* nume_coloana; string tip; int

please help me solve in c++! create a class of type has-a with the following class

-

class coloana
{private:
char* nume_coloana;
string tip;
int dimensiune;
public:
coloana()
{
nume_coloana = nullptr;
tip="";
dimensiune=0;
}
coloana(const char* nume_coloana)
{
if (nume_coloana != nullptr)
{
this->nume_coloana = new char[strlen(nume_coloana) + 1];
strcpy_s(this->nume_coloana, strlen(nume_coloana) + 1, nume_coloana);
}
}
coloana(const char* nume_coloana, string tip, int dimensiune)
{
this->nume_coloana = new char[strlen(nume_coloana ) + 1];
strcpy_s(this->nume_coloana, strlen(nume_coloana) + 1, nume_coloana);
this->dimensiune = dimensiune;
this->tip = tip;
}
coloana(const coloana& c)
{
if (c.nume_coloana != nullptr)
{
this->nume_coloana = new char[strlen(c.nume_coloana) + 1];
strcpy_s(this->nume_coloana, strlen(c.nume_coloana) + 1, c.nume_coloana);
}
else nume_coloana = nullptr;
this->dimensiune = c.dimensiune;
this->tip = c.tip;
}
~coloana()
{
if (nume_coloana != nullptr)
delete[] nume_coloana;
}
coloana& operator=(const coloana& c)
{
if (nume_coloana != nullptr)
delete[] nume_coloana;
if (c.nume_coloana != nullptr)
{
this->nume_coloana = new char[strlen(c.nume_coloana) + 1];
strcpy_s(this->nume_coloana, strlen(c.nume_coloana) + 1, c.nume_coloana);
}
else nume_coloana = nullptr;
this->dimensiune = c.dimensiune;
this->tip = c.tip;
return *this;
}
string get_tip()
{
return tip;
}
string get_denumire_coloana()
{
string nume = nume_coloana;
return nume;
}
int get_dimensiune()
{
return dimensiune;
}
void set_nume_coloana(const char* nume_coloana)
{
if (nume_coloana != nullptr)
{
if (this->nume_coloana != nullptr)
delete[] this->nume_coloana;
this->nume_coloana = new char[strlen(nume_coloana) + 1];
strcpy_s(this->nume_coloana, strlen(nume_coloana) + 1, nume_coloana);
}
}
void set_tipul(string tip)
{
if (tip != "")
{
this->tip = tip;
}
}
void set_dimensiunea(int dimensiune)
{
if (dimensiune > 0)
{
this->dimensiune = dimensiune;
}
}
char operator[](int index)
{
if (index >= 0 && index < strlen(nume_coloana))
return nume_coloana[index];
}
coloana operator+(int valoare)
{
if (valoare > 0)
{
coloana copie = *this;
copie.dimensiune = copie.dimensiune + valoare;
return copie;
}
}
coloana operator++()
{
this->dimensiune++;
return *this;
}
coloana operator++(int i)
{
coloana copie = *this;
this->dimensiune++;
return copie;
}
int operator()()
{
if (nume_coloana != nullptr)
return strlen(nume_coloana);
}
bool operator!()
{
return dimensiune > 0;
}
bool operator<(int valoare)
{
if (dimensiune < valoare) return true;
else return false;
}
bool operator==(coloana c)
{
int ok = 1;
if (strcmp(nume_coloana, c.nume_coloana) != 0) ok = 0;
if (tip != c.tip) ok = 0;
if (dimensiune != c.dimensiune) ok = 0;
if (ok == 1) return true;
else return false;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!