-4
下面的代碼中,三角形和矩形區域的面積爲0。需要一些提示,我該如何解決這個問題。 也,如果我能得到一些固定在這,這將是偉大的!C++形狀區域:獲取區域0
#include <iostream.h>
#include <conio.h>
class shape
{
protected:
double x,y;
public:
void get_data(void);
virtual void display_area(void){ }
};
class triangle:public shape
{
protected:
double AoT;
public:
void display_area(void);
};
class rectangle:public shape
{
protected:
double AoR;
public:
void display_area(void);
};
void shape::get_data(void)
{
cout<<"Enter the vlaue of Base(x) and Height(y):"<<endl;
cin>>x>>y;
}
void triangle::display_area(void)
{
AoT=0.5*x*y;
cout<<"The area of Triangle in unit sq. is:"<<AoT<<endl;
}
void rectangle::display_area(void)
{
AoR=x*y;
cout<<"The area of Rectangle in Unit sq. is:"<<AoR<<endl;
}
main()
{
clrscr();
shape s, *p;
triangle t;
rectangle r;
s.get_data();
p=&t;
p->display_area();
p=&r;
p->display_area();
getch();
}
在先進的感謝。需要對此快速注視,因爲我',米kinda despo大聲笑
你是什麼輸入? – Downvoter
x和y是我的輸入@cad – Anuj
't'和'p'不受's'輸入的影響。 – MikeCAT