Tuesday, July 14, 2009

C++ Help Please!?

Hello, I am trying to run this class, but when I compile, it is telling me that "cout" and "endl" are undeclared integers....? I obviously just want the results to be output, but what do I have to do to fix this? Any help is appreciated.





class Rectangle


{


public:


Rectangle()


{


height= 0;


width = 0;


}





Rectangle(double h, double w)


{


height = h;


width = w;


}





double getHeight() // retrive the height to print in main


{


return height;


}





double getWidth() // retrive the width to print in main


{


return width;


}





double getArea()const


{


return height * width;


}





double getPerimeter()


{


return ((height * 2) + (width * 2));


}





private:


double height;


double width;


};





int main()


{


Rectangle rectangle1(5,50);


Rectangle rectangle2(3.5,35.9);





cout %26lt;%26lt; rectangle1.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle1.getPerimeter() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle2.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle2.getPerimeter() %26lt;%26lt; endl;





return 0;


}

C++ Help Please!?
Just add the following two lines at the start





#include %26lt;iostream%26gt;


using namespace std;
Reply:#include %26lt;iostream%26gt;


using std::cout;


using std::endl;








or, just


#include %26lt;iostream%26gt;


//and you have to use the namespace in your code.





std::cout%26lt;%26lt; blah %26lt;%26lt; cout::endl;


No comments:

Post a Comment