Program to construct house with bricks with 3 dimensional vector - c++

I have 2 classes : 1 brick and 1 construction class, I must built a house or an object with bricks, each construction can take a brick as an argument, it has also operators + , - and ^ , and +=, -= , ^= , that add a construction on the right of the construction, "behind" (in the depth and 1 level above a construction...
I have to do this with the appropriate according indices of my 3 dimensional vector....
The problem is: Everything compiles fine, but my program crashes when I start this... I spent a whole day on this program and I dont know where my error is...
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// Pour simplifier
typedef string Forme ;
typedef string Couleur ;
class Brique
{
private:
Forme forme ;
Couleur couleur ;
public:
/*****************************************************
Compléter le code à partir d'ici
*******************************************************/
Brique( Forme f, Couleur c ) : forme(f),couleur(c) {};
ostream& afficher(ostream& sortie) const ;
Forme getForme() const {return forme;};
Couleur getCouleur() const {return couleur;};
};
ostream& Brique::afficher(ostream & sortie) const {
if (this->getCouleur() != "") {
return sortie<<"("<<this->getForme()<<", "<<this->getCouleur()<<")";
}
else {
return sortie<<this->getForme();
}
};
ostream& operator<<(ostream& sortie, Brique const& z) {
return z.afficher(sortie);
};
class Construction
{
friend class Grader;
public:
vector<vector<vector<Brique> > > contenu;
public:
Construction(Brique b) : contenu(1, vector<vector<Brique> >(1, vector<Brique>(1,b))) {};
//Construction(Construction c) ;
ostream& afficher(ostream& sortie) const ;
Construction& operator^=(Construction const & z) ;
Construction& operator-=(Construction const & z) ;
Construction& operator+=(Construction const & z) ;
};
ostream& Construction::afficher(ostream& sortie) const {
size_t i(contenu.size());
for (size_t j = 0; j< i; j++) {
cout<<"Couche "<<j<<" :"<<endl;
for (size_t k = 0; k<contenu[j].size() ; k++) {
for (size_t t = 0; t< contenu[j][k].size(); t++) {
cout <<contenu[j][k][t];
}
}
}
return cout;
};
ostream& operator<<(ostream& o, Construction const& z) {
return z.afficher(o);
};
Construction& Construction::operator^=(Construction const & z) {
//int i(this->contenu.size());
//int j(this->contenu[i].size());
//int k(this->contenu[i][j].size());
int m(z.contenu.size());
//int n(z.contenu[m].size());
//int p(z.contenu[m][n].size());
this->contenu.push_back(z.contenu[m]);
return *this;
};
Construction& operator^(Construction & o, Construction & z) {
//o.contenu.push_back(z.contenu[z.contenu.size()]);
o^= z;
return o;
}
Construction& Construction::operator+=(Construction const & z) {
int i(this->contenu.size());
int j(this->contenu[i].size());
//int k(this->contenu[i][j].size());
int m(z.contenu.size());
int n(z.contenu[m].size());
//int p(z.contenu[m][n].size());
if ( n < j) { return *this;}
else if ( n > j) {
int a(0);
for (auto element : z.contenu[m][n]) {
this->contenu[i][j].push_back(element);
++a;
if (a == n) { return * this;}
}
}
else {
this->contenu[i].push_back(z.contenu[m][n]);
}
return *this;
}
Construction operator+(Construction t, Construction z) {
return t+=z;
}
Construction& Construction::operator-=(Construction const & z) {
int i(this->contenu.size());
int j(this->contenu[i].size());
int k(this->contenu[i][j].size());
int m(z.contenu.size());
int n(z.contenu[m].size());
int p(z.contenu[m][n].size());
if ( p < k) { return *this;}
else {
this->contenu[i][j].push_back(z.contenu[m][n][p]);
}
return *this;
}
Construction& operator-(Construction & o, Construction const & z) {
/*
int i(o.contenu.size());
int m(z.contenu.size());
int n(z.contenu[m].size());
int p(z.contenu[m][n].size());
o.contenu[i][m].push_back(z.contenu[m][n][p]);
*/
return o-=z;
}
const Construction operator*(unsigned int n, Construction const& a)
{
Construction b = a;
for (unsigned int i=1;i<n;i++) {
b.operator+=(a);
}
return b;
};
const Construction operator/(unsigned int n, Construction const& a)
{
Construction b=a;
for (unsigned int i=1;i<n;i++) {
b^=a;
}
return b;
};
const Construction operator%(unsigned int n, Construction const& a)
{
Construction b=a;
for (unsigned int i=1;i<n;i++) {
b-=a;
}
return b;
};
/*******************************************
* Ne rien modifier après cette ligne.
*******************************************/
int main()
{
// Modèles de briques
Brique toitD("obliqueD", "rouge");
Brique toitG("obliqueG", "rouge");
Brique toitM(" pleine ", "rouge");
Brique mur (" pleine ", "blanc");
Brique vide (" ", "");
unsigned int largeur(4);
unsigned int profondeur(3);
unsigned int hauteur(3); // sans le toit
// on construit les murs
Construction maison( hauteur / ( profondeur % (largeur * mur) ) );
cout<<maison;
// on construit le toit
Construction toit(profondeur % ( toitG + 2*toitM + toitD ));
toit ^= profondeur % (vide + toitG + toitD);
// on pose le toit sur les murs
maison ^= toit;
// on admire notre construction
cout << maison << endl;
return 0;
}
anybody got an Idea why my program crashes?

Related

NULL data stored by overloaded istream

This is part of my polynomial.cpp to get terms by overloading istream
void Newterm(float coef, int deg) {
if (terms == capacity) {
capacity *= 2;
Term* tmp = new Term[capacity];
copy(termArray, termArray + terms, tmp);
termArray = tmp;
delete[] tmp;
}
termArray[terms].degree = deg;
termArray[terms++].coef = coef;
}
friend istream& operator >> (istream& is, Polynomial& pl) {
cout << "number of terms : ";
int t; is >> t;
cout << endl;
float coeff;
int degree;
for (int i = 0; i < t;i++) {
cout << i + 1 << "'s term: ";
is >> coeff >> degree;
pl.Newterm(coeff, degree);
}
return is;
};
of course, i tried to figure out whaaat made this result..
tried:
removing 'for' loop
this actually worked.. but it only works when terms=1
firstly creating term and input data
Newterm(0,0);
is>>pl.termArray[i].coef>>pl.termArray[i].degree;
it couldn't fix anything...
so i think it has to do with loops..
but whyyyy?
Using std::vector instead of doing your own memory managment
(why reinvent the wheel if there is a tested solution in the standard library)
#include <iostream>
#include <vector>
struct Term final
{
Term() = default;
~Term() = default;
Term(int d, double c) :
degree{ d },
coef{ c }
{
}
int degree{ 0 };
double coef{ 1.0 };
};
class Polynomial final
{
public:
Polynomial() = default;
~Polynomial() = default;
explicit Polynomial(const std::initializer_list<Term> terms) :
m_terms{ terms }
{
}
void add(const Term& term)
{
m_terms.push_back(term);
}
private:
std::vector<Term> m_terms;
};
std::istream& operator>>(std::istream& is, Polynomial& polynomial)
{
std::size_t n{ 0 }; // indices are not ints the can't be < 0
is >> n;
for (std::size_t i = 0; i < n; ++i)
{
Term term{};
is >> term.coef;
is >> term.degree;
polynomial.add(term);
}
return is;
}
int main()
{
// to show you that std::vector can handle all the memory managment for you
// constructor with an initializer list that adds 3 terms
// that's also why the Term has a constructor, it is to make it work with
// initializer list
Polynomial p{ { 1,2.0 }, { 2,4.0 }, { 1,-1.0 } };
}

Problem with Segmentation Fault with doing operations on class

Sorry for variables not being all in engilsh. I have a problem when i try to do the += operation on class called Uklad3.
It is initialized the same way as previous ones, but with this one the segmentation failure comes up when i try to do any operations on it.
Any sugestions how to fix it? I am not a proffesional programmer.
I sumbited the whole code because I know it might be little hard to read, I am learning and this is for ma class.
The goal of the operation += is to add points from one coordinate system to the other. It is only the portion of the task but this is where I have a problem.
class punkt
{
private:
double x;
double y;
double z;
public:
punkt(){};
string name;
punkt(string,double,double,double);
double getx() const {return x;}
double gety() const {return y;}
double getz() const {return z;}
};
punkt::punkt(string name_,double x_, double y_, double z_)
{
name=name_;
x=x_;
y=y_;
z=z_;
}
class Uklad
{
public:
static const int size = 10;
punkt tablica[size];
string uklad_name;
void add(punkt);
int licznik;
Uklad(){licznik=0;};
Uklad(string);
Uklad & operator+=(const Uklad &var)
{
for(int i=0;i<var.licznik;i++)
{
tablica[licznik]=var.tablica[i];
licznik++;
}
}
Uklad & operator-= (const Uklad &var)
{
for(int i=0;i<licznik;i++)
{
for(int j=0;j<var.licznik;j++)
{
if((tablica[i].getx()==var.tablica[i].getx()) and (tablica[i].gety()==var.tablica[i].gety()) and (tablica[i].getz()==var.tablica[i].getz()))
{
for(int k=i;k<licznik;k++)
{
tablica[k]=tablica[k+1];
}
licznik--;
}
}
}
}
};
Uklad::Uklad(string uklad_name_)
{
uklad_name=uklad_name_;
cout<<"Tworze uklad"<<endl;
}
void Uklad::add(punkt toAdd)
{
if(licznik<size)
{
tablica[licznik]=toAdd;
licznik++;
}
}
}
ostream & operator<<(ostream &s, const punkt &Punkt)
{
cout<<Punkt.name<<" "<<Punkt.getx()<<" "<<Punkt.gety()<<" "<<Punkt.getz();
return s<<" ";
}
ostream & operator<<(ostream &s, const Uklad &uklad)
{
for(int i=0;i<uklad.licznik;i++)
{
if(i==uklad.licznik-1) cout<<uklad.tablica[i]<<" ";
else
cout<<uklad.tablica[i]<<"; ";
}
return s<<" ";
}
int main()
{
//1.
string name1,name2,name3;
cin>>name1;
cin>>name2;
Uklad uklad1(name1);
Uklad uklad2(name2);
//2.
const int M=2;
double xtemp, ytemp, ztemp;
string nametemp;
string xs,ys,zs;
for(int i=0;i<M;i++)
{
cin>>nametemp;
cin>>xtemp;
cin>>ytemp;
cin>>ztemp;
punkt punktT(nametemp,xtemp,ytemp,ztemp);
uklad1.add(punktT);
}
//3.
const int N=2;
double xtemp2, ytemp2, ztemp2;
string nametemp2;
string xs2,ys2,zs2;
for(int i=0;i<N;i++)
{
cin>>nametemp2;
cin>>xtemp2;
cin>>ytemp2;
cin>>ztemp2;
punkt punktT2(nametemp2,xtemp2,ytemp2,ztemp2);
uklad2.add(punktT2);
}
//4.
cin>>name3;
Uklad uklad3(name3);
//5.
uklad3+=uklad1;
cout<<uklad3;
return 0;
}
static const int size = 10;
You make array about 10 size and after all this loops you go out of range of the array. That's why you have this error. You can give it higher size. Or you can use vectors. In case of using array you must be sure you will not go out of range.
I formated the code and add initializer to licznik. This code haven't segmentation fault error
class punkt
{
private:
double x;
double y;
double z;
public:
punkt(){};
string name;
punkt(string,double,double,double);
double getx() const {return x;}
double gety() const {return y;}
double getz() const {return z;}
};
punkt::punkt(string name_,double x_, double y_, double z_)
{
name=name_;
x=x_;
y=y_;
z=z_;
}
class Uklad
{
public:
static const int size = 10;
punkt tablica[size];
string uklad_name = "";
void add(punkt);
int licznik = 0;
Uklad(){licznik=0;};
Uklad(string);
Uklad& operator+=(const Uklad &var)
{
for(int i=0;i<var.licznik;i++)
{
cout << licznik << " += ";
tablica[licznik]=var.tablica[i];
licznik++;
}
return *this;
}
Uklad & operator-= (const Uklad &var)
{
for(int i=0;i<licznik;i++)
{
for(int j=0;j<var.licznik;j++)
{
cout << i << " -=";
if((tablica[i].getx()==var.tablica[i].getx()) and (tablica[i].gety()==var.tablica[i].gety()) and (tablica[i].getz()==var.tablica[i].getz()))
{
for(int k=i;k<licznik;k++)
{
tablica[k]=tablica[k+1];
}
licznik--;
}
}
}
return *this;
}
};
Uklad::Uklad(string uklad_name_)
{
licznik = 0;
uklad_name=uklad_name_;
cout << "Tworze uklad" << endl;
}
void Uklad::add(punkt toAdd)
{
if(licznik<size)
{
tablica[licznik]=toAdd;
licznik++;
}
}
ostream & operator<<(ostream &s, const punkt &Punkt)
{
cout<<Punkt.name<<" "<<Punkt.getx()<<" "<<Punkt.gety()<<" "<<Punkt.getz();
return s<<" ";
}
ostream & operator<<(ostream &s, const Uklad &uklad)
{
for(int i=0;i<uklad.licznik;i++)
{
if(i==uklad.licznik-1) cout<<uklad.tablica[i]<<" ";
else
cout<<uklad.tablica[i]<<"; ";
}
return s<<" ";
}
int main()
{
//1.
string name1,name2,name3;
cin>>name1;
cin>>name2;
Uklad uklad1(name1);
Uklad uklad2(name2);
//2.
const int M=2;
double xtemp, ytemp, ztemp;
string nametemp;
string xs,ys,zs;
for(int i=0;i<M;i++)
{
cin>>nametemp;
cin>>xtemp;
cin>>ytemp;
cin>>ztemp;
punkt punktT(nametemp,xtemp,ytemp,ztemp);
uklad1.add(punktT);
}
//3.
const int N=2;
double xtemp2, ytemp2, ztemp2;
string nametemp2;
string xs2,ys2,zs2;
for(int i=0;i<N;i++)
{
cin>>nametemp2;
cin>>xtemp2;
cin>>ytemp2;
cin>>ztemp2;
punkt punktT2(nametemp2,xtemp2,ytemp2,ztemp2);
uklad2.add(punktT2);
}
//4.
cin>>name3;
Uklad uklad3(name3);
//5.
uklad3+=uklad1;
cout<<uklad3;
return 0;
}

PairArr::operator=(PairArr(ValArrInt(ytemp, NY),ValArrInt(btemp,NY)));

template <typename T1,typename T2>
class Pair
{
private:
T1 a;
T2 b;
public:
T1 & first() { return a; }
T2 & second() { return b; }
T1 first() const { return a; }
T2 second() const { return b; }
Pair(const T1 & aval, const T2 & bval) : a(aval), b(aval) {};
Pair() {}
};
using ValArrInt = std::valarray<int>;
using PairArr = Pair<ValArrInt, ValArrInt>;
class Wine : private string, private PairArr
{
private:
int NY;
public:
Wine(const char * l, int y, const int yr[], const int bot[]);
void Show() const;
};
Wine::Wine(const char * l, int y, const int yr[], const int bot[])
:string(l), NY(y)
{
PairArr::operator=(PairArr(ValArrInt(yr, NY), ValArrInt(bot, NY)));
}
void Wine::Show() const
{
cout << "Wine: " << (const string &)*this << endl;
cout << "\tYear\tBottles\n";
for (int i = 0; i < NY; i++)
{
cout << "\t" << PairArr::first()[i] << "\t"
<< PairArr::second()[i] << endl;
}
}
In this line:
PairArr::operator=(PairArr(ValArrInt(yr, NY), ValArrInt(bot, NY)));
Why does the PairArr component end up with ValArrInt(yr, NY) (the first argument) being both its a, and b members.
Tested with this:
const int YRS = 3;
int y[YRS] = { 1993,1995,1998 };
int b[YRS] = { 48,60,72 };
Wine more("Gushing Grap Red", YRS, y, b);
more.Show();
off-topic:
Keeps asking me to add more details for the amount of code... But no.
Is there some sort of ratio of code to non-code I'm supposed to meet?
So, apparently you have a misprint, you typed aval in both places:
Pair(const T1 & aval, const T2 & bval) : a(aval), b(aval) {};

Writing an accessor method for inherited class with sparse member data?

Say I have a simple vector class, vec:
#include <iostream>
#include <stdlib.h>
class vec {
public:
vec() {}
// Constructor.
vec(int n) {
len = n;
data = new double[len];
}
// Destructor.
~vec() { delete [] data; }
// Accessor.
double & operator[](int i) const {
check_index(i);
return data[i];
}
// Other methods...
// ....
protected:
int len;
double * data;
void check_index(int i) const {
if(i < 0 || i >= len) {
std::cerr << "Bad access.\n";
exit(1);
}
}
};
Now suppose I have a special type of vector with sparse structure, e.g., where every even-index is zero. Call this oddvec. Instances of oddvec should be declared just as with the vec class, but underneath, the memory use should be efficient since only half the data is non-zero.
The accessor for the oddvec class should return 0 if the index is even, and return the odd-index element (stored sequentially) otherwise. There a couple problems with this:
The double & return type is violated if the index is even, since the constant value, 0, is returned.
It's not clear to me how to handle the situation when an even index element is used as an lvalue. E.g., v[0] = 3.0 should not be allowed in the oddvec class, but is perfectly acceptable in the vector class. We can't simply throw an error when even indexes are used, because even indexes are fine as long as the intention is as an rvalue.
How do I design the accessor function for the oddvec class, while both keeping the memory storage efficient and inheriting all the methods from the parent?
Non-working example of oddvec:
class oddvec : public vec {
public:
// Constructor.
oddvec(int n) {
len = n;
data = new double[len/2];
}
// Accessor (doesn't work!)
double & operator[](int i) const {
check_index(i);
if (i%2 == 0)
return 0;
else
return data[(i-1)/2];
}
};
Upon compilation:
main.cpp: In member function ‘double& oddvec::operator[](int) const’:
main.cpp:49:20: error: invalid initialization of non-const reference of type ‘double&’ from an rvalue of type ‘double’
return 0;
Working example using proxy classes:
I have implemented a proxy class as suggested in the answer below.
proxies.h
#ifndef PROXIES_H
#define PROXIES_H
#include <iostream>
#include <stdlib.h>
class proxy {
public:
proxy(int i, double v, double * d) {
index = i;
value = v;
data = d;
}
void operator=(double rhs) {
data[index] = rhs;
}
friend std::ostream & operator<<(std::ostream & outs, const proxy & p) {
outs << p.value;
return outs;
}
protected:
int index;
double value;
double * data;
};
class oddproxy : public proxy {
public:
oddproxy(int i, int v, double * d) : proxy(i, v, d) {}
void operator=(double rhs) {
if (index%2 == 0) {
std::cerr << "Even entries of oddvec are not assignable.\n";
exit(1);
}
data[index/2] = rhs;
}
};
#endif
vectors.h
#ifndef VECTORS_H
#define VECTORS_H
#include "proxies.h"
class vec {
public:
vec() {}
// Constructor.
vec(int n) {
len = n;
data = new double[len];
}
// Destructor.
~vec() { delete [] data; }
// Accessor.
proxy operator[](int i) const {
check_index(i);
return proxy(i, data[i], data);
}
inline int length() const { return len; }
// Other methods...
// ....
protected:
int len;
double * data;
void check_index(int i) const {
if(i < 0 || i >= len) {
std::cerr << "Bad access.\n";
exit(1);
}
}
};
class oddvec : public vec {
public:
// Constructor.
oddvec(int n) {
len = n;
data = new double[len/2];
}
// Accessor.
oddproxy operator[](int i) const {
check_index(i);
return oddproxy(i, (i%2 == 0) ? 0 : data[i/2], data);
}
};
#endif
main.cpp
#include <iostream>
#include "vectors.h"
int main () {
int N = 5;
vec V(N);
oddvec O(N);
for(int i=0; i < V.length(); i++) {
V[i] = i;
if(i%2 != 0) {
O[i] = i;
}
}
for(int i=0; i < O.length(); i++) {
std::cout << "V[" << i << "]=" << V[i] << ", "
<< "O[" << i << "]=" << O[i] << "\n";
}
O[0] = 13;
return 0;
}
output
V[0]=0, O[0]=0
V[1]=1, O[1]=1
V[2]=2, O[2]=0
V[3]=3, O[3]=3
V[4]=4, O[4]=0
Even entries of oddvec are not assignable.
You can use proxy object to do this.
simple sample code:
#include <iostream>
#include <vector>
using namespace std;
class very_odd_vector{
public:
class only_odd_proxy;
friend class only_odd_proxy;
only_odd_proxy operator [](int index);
int operator [](int index)const{return index%2==0?0:content[index/2];}
unsigned int size()const{return content.size()*2;}
private:
vector<int> content{1,3,5,7,9};
};
class very_odd_vector::only_odd_proxy{
public:
only_odd_proxy(very_odd_vector& vec,int index):vec(vec),index(index){}
operator int(){return index%2==0 ? 0 : vec.content[index/2];}
only_odd_proxy& operator =(int value){
if(index%2==0)
cout << "BAD OPERATION";//any error you want
else
vec.content[index/2] = value;
return *this;
}
private:
very_odd_vector& vec;
int index;
};
auto very_odd_vector::operator [](int index)->only_odd_proxy{return only_odd_proxy(*this,index);}
int main(){
very_odd_vector v;
cout << "reading value\n";
for(int i=0;i<v.size();++i)
cout << v[i] <<'\n';
cout << "writting value\n";
for(int i=0;i<v.size();++i){
cout << i << ':';
v[i]=10;
cout << '\n';
}
cout << "reading value\n";
for(int i=0;i<v.size();++i)
cout << v[i] <<'\n';
}
Edit for updated part of question :
I think this class will fit your need more.
//Both base and inherit class return this class
class maybe_readonly_proxy {
public:
maybe_readonly_proxy(double* data, bool readonly):readonly(readonly),data(data){}
maybe_readonly_proxy& operator=(double rhs) {
if(readonly){/*whatever error*/}
else {*data = rhs;}
return *this;
}
operator double()const{return *data;}
private:
bool readonly;
double * data;
};
You may need a variable to contain readonly (0 in this case) value, or modify the operator double() the check readonly state
Or just implement get and set method separately and do not use this proxy may be another choice.

Assigning new object from object returned by a method C++

I have overloaded the "+" operator so when I make class1 + class1 = class2 . The only Problem is when I pass it to another object.
The "+" operator is already overloaded so when you make class2 + class1, it adds the class1 object to the class2 object.
Here is the example:
#include<iostream.h>
class Figura {
public:
int x, y, poz;
int tip; //1 = punct ; 2 = dreapta; 3 = dreptunghi
Figura() { };
Figura(const Figura&) { };
};
class Grup {
private:
int nr_elemente;
Figura **figuri;
public:
int i;
Grup(int nr_el) {
nr_elemente = nr_el;
figuri = new Figura*[nr_elemente];
i = 0;
}
Grup() {
nr_elemente = 100;
figuri = new Figura*[nr_elemente];
i = 0;
}
~Grup() { /*delete[] figuri;*/ };
Grup(const Grup&) { };
Grup& operator=(const Grup&) {
return *this;
}
int _nr_elemente() {
return i;
}
void afiseaza_elemente() {
for(int j = 0; j < i; j++)
cout<<"Figura nr:"<<j<<" tip :"<<figuri[j]->tip<<" x:"<<figuri[j]->x<<" y:"<<figuri[j]->y<<" poz:"<<figuri[j]->poz<<endl;
}
friend Grup operator+(const Figura& fig1, const Figura& fig2) {
Grup grt;
grt + fig1;
grt + fig2;
cout<<grt.i<<endl; // current number of elements begining with 0, so it should print 1 (fig1 and fig2)
grt.afiseaza_elemente(); // prints the elements attributes
return grt;
};
friend Grup operator+(const Grup& gr1, const Grup& gr2) {};
void operator+(const Figura& fig);
};
void Grup::operator+(const Figura& fig) {
Grup::figuri[Grup::i] = new Figura;
Grup::figuri[Grup::i]->tip = fig.tip;
Grup::figuri[Grup::i]->poz = fig.poz;
if(fig.tip == 2) {
Grup::figuri[Grup::i]->x = fig.x;
Grup::figuri[Grup::i]->y = 0;
} else if(fig.tip == 3) {
Grup::figuri[Grup::i]->x = fig.x;
Grup::figuri[Grup::i]->y = fig.y;
}
else {
Grup::figuri[Grup::i]->x = 0;
Grup::figuri[Grup::i]->y = 0;
}
Grup::i++;
}
class Punct : public Figura
{
public:
Punct(int poz) {
Punct::tip = 1;
Punct::poz = poz;
}
};
class Segment : public Figura
{
public:
Segment(int poz, int x) {
Segment::tip = 2;
Segment::poz = poz;
Segment::x = x;
}
};
class Dreptunghi : public Figura
{
public:
Dreptunghi(int poz, int x, int y) {
Dreptunghi::tip = 3;
Dreptunghi::poz = poz;
Dreptunghi::x = x;
Dreptunghi::y = y;
}
};
void main(void) {
Grup gr(10);
Punct pct(1);
Segment sgm(3, 5);
gr + pct;
gr + sgm;
Grup gr2 = pct + sgm;
cout<<"--------------------------"<<endl;
cout<<gr2.i<<endl; // prints a weird number
gr2.afiseaza_elemente(); // prints the elemenets atributes, but because gr2.i is negative shows nothing
}