eclipse - C++ getArea() and cout not working -
this code, relatively new c++. other c++ program i've ever written atm app. project, i'm trying find area of box, suggestions n why isn't working?
anyways heres code
/* * c.cpp * * created on: jan 31, 2014 * author: university of denver. yeah, smoke weed. */ class box { public: // pure virtual function virtual double getvolume() = 0; private: double length; // length of box double breadth; // breadth of box double height; // height of 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 area of object. cout << "total rectangle area: " << rect.getarea() << endl; tri.setwidth(5); tri.setheight(7); // print area of object. cout << "total triangle area: " << tri.getarea() << endl; return 0; }
the code valid compiled , outputs 35 , 17. think problem console window closed system , not see result. can insert command wait until enter example
int i; std::cin >> i;
or similar before return
if use ms vc++ can run console applications key combination ctrl + f5
also take account class box not used , may removed.
Comments
Post a Comment