-3
私はクラスを継承したプログラムをC++で作成しています。その機能は、三角形が正しいときはいつでも決定し、その面積を計算することです。ここでint関数の結果を返すことができません
はプログラムです:
#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が正常に動作しているが、それは正しい結果が、住所を表示doesntの、私はそれを修正する方法を知りません。
これが結果です。
Triunghi dreptunghic!
513242112
'Latura'クラスでは' int'メンバには初期化の後に*不定値*が残っています。 –
私が見ることができるように、 'Latura l 'とそれに続く' l.LatimeaL(1,2,4);は 'main()'では無意味です。を削除し、 't.LatimeaL(1,2,4);'は 't'の宣言に従うべきです。 – WhozCraig
オブジェクト 'p'、' l'、 't'は何らかの方法で結びついていると思います。それらは完全に独立した3つのオブジェクトです。 – molbdnilo