c++ - Can't return result from int function -
i making class inherited program in c++. function determane whenever triangle right , calculate area.
here program:
#include <iostream> using namespace std; class puncte { public: int x1,y1; int x2,y2; int x3,y3; puncte(int a, int b, int c, int d, int e, int f):x1(a),y1(b),x2(c),y2(d),x3(e),y3(f){} void afisarep() { cout<<x1<<y1<<x2<<y2<<x3<<y3<<endl; } }; class latura { protected: int l1, l2, l3; public: void latimeal(int a, int b, int c) { l1 = a; l2 = b; l3 = c; } }; class triunghi: public latura { public: int ariatrdr() { return l1*l3/2; } }; int main() { puncte p(2,2,2,2,2,2); latura l; l.latimeal(1,2,4); triunghi t; if (p.x1 == p.x3 && p.y1 == p.y2) { cout << "triunghi dreptunghic!" << endl; cout << t.ariatrdr() << endl; } return (0); }
everthing working fine doesnt show correct result adress , dont know how fix it.
this result.
triunghi dreptunghic! 513242112
you calling l.latimeal(1,2,4);
on object l
.
the object t
created triunghi t;
. not initialized calling latimeal
function. therefore getting undefined value.
you need cal t.latimeal(1,2,4)
function initialize it, after creating object.
Comments
Post a Comment