My code outputs weird numbers. in line "return this->x + this->y + this->z; " it should output all this 3 number sum, but it outputs weird numbers. Expected result: 11
Anyone can help with this?
code:
#include <iostream>
#include <string>
class Point2D {
protected:
double x,y;
public:
Point2D() {
std::cout << "Objekts izveidots bez parametriem." << std::endl;
}
void setx(double x) {
this->x = x;
}
void sety(double y) {
this->y = y;
}
double getsumma() {
return this->x + this->y;
}
void printInfo() {
std::cout << "Divu malu summa ir:" << getsumma() << std::endl;
}
~Point2D() {
std::cout << "Izdzests" << std::endl;
}
};
class Point3D : public Point2D {
protected:
double z;
public:
Point3D() {
std::cout << "Objekts izveidots bez parametriem." << std::endl;
}
void setz(double z) {
this->z = z;
}
double getperimetrs() {
return this->x + this->y + this->z;
}
void printInfo() {
std::cout << "Trijstura perimentrs ir: " << getperimetrs() << std::endl;
}
~Point3D() {
std::cout << "Izdzests" << std::endl;
}
};
int main() {
Point2D z1;
Point3D x1;
z1.setx(5);
z1.sety(3);
x1.setz(5);
z1.printInfo();
x1.printInfo();
system("pause");
}