0
이것은 제 코드입니다. C++에 비교적 익숙합니다. 필자가 작성한 유일한 C++ 프로그램은 atm 앱뿐이었습니다. 이 프로젝트에서 상자의 영역을 찾으려고하는데, 왜 이것이 작동하지 않는가?C++ getArea() 및 cout이 작동하지 않습니다.
어쨌든을 heres 내 코드
/*
* 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