0
這是我的代碼,我對C++比較陌生。我曾經寫過的唯一的其他C++程序是一個atm應用程序。對於這個項目,我試圖找到一個盒子的區域,任何建議ñ爲什麼這不起作用?C++ getArea()和cout不能正常工作
反正我的繼承人代碼
/*
* c.cpp
*
* Created on: Jan 31, 2014
* Author: University of Denver. Yeah, I smoke weed.
*/
class Box
{
public:
// pure virtual function
virtual double getVolume() = 0;
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
#include <iostream>
using namespace std;
// Base class
class Shape
{
public:
// pure virtual function providing interface framework.
virtual int getArea() = 0;
void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
int height;
};
// Derived classes
class Rectangle: public Shape
{
public:
int getArea()
{
return (width * height);
}
};
class Triangle: public Shape
{
public:
int getArea()
{
return (width * height)/2;
}
};
int main(void)
{
Rectangle Rect;
Triangle Tri;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout << "Total Rectangle area: " << Rect.getArea() << endl;
Tri.setWidth(5);
Tri.setHeight(7);
// Print the area of the object.
cout << "Total Triangle area: " << Tri.getArea() << endl;
return 0;
}
運行時會出現什麼錯誤? – mikea
你將不得不告訴我們什麼是不工作的,代碼中哪裏不工作,以及你期望看到什麼。 – Sean
當我點擊Eclipse中的Run時,出現提示「Launch failed。Binary not found。」。 – user3241171