-
Help with Classes
Im wondering on how i would display the "area" in main?
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Circle
{ private:
double radius;
public:
void setRadius (double r)
{radius=r;}
double getArea()
{return 3.14*pow(radius,2);}
int main () {
return 0;
}
-
Re: Help with Classes
How can you get as far as to write a class, several #include and using statements (which involve the objects that answer your question) and ask how to print something to the screen? Are you reading from a book or did you get this code off someone else?
Please use code tags. You can find info on them in the FAQ.
-
Re: Help with Classes
got this from the book..just kind of having trouble with classes and such..srry
-
Re: Help with Classes
Create an instance of that class, set it a radius and then print it:
Code:
int main(){
Circle c;
c.setRadio(34);
cout<<c.getArea();
}
-
Re: Help with Classes
But, ideally, if you've gotten this far, the book should really have explained how to do what you're asking to do. Can I ask what the book is?