2014-01-31 1 views
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; 
} 
+1

실행했을 때 어떤 오류가 있습니까? – mikea

+0

코드가 작동하지 않는 곳과 작동하지 않는 곳을 알려 주어야합니다. – Sean

+0

Eclipse에서 Run을 클릭하면 "Launch failed, Binary not found."라는 메시지가 나타납니다. – user3241171

답변

0

코드는 컴파일 유효하며 내가 문제가 콘솔 창은 시스템에 의해 신속하게 닫혀 있는지 생각하고 결과를 볼 수 없습니다 (35) 및 (17)를 출력합니다. 당신은 당신이 예를

에 관해서는 뭔가를 입력 할 때까지 대기하는 모든 명령을 삽입 할 수 있습니다
int i; 

std::cin >> i; 

또는 MS VC를 사용하는 경우 ++ 당신이 키 조합 Ctrl + F5

와 콘솔 응용 프로그램을 실행할 수 있습니다

반환하기 전에 비슷한

또한 클래스 상자가 사용되지 않아 제거 될 수 있음을 고려하십시오.

관련 문제