|
-
March 18th, 2009, 11:04 PM
#1
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;
}
-
March 19th, 2009, 02:34 AM
#2
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.
-
March 19th, 2009, 11:49 AM
#3
Re: Help with Classes
got this from the book..just kind of having trouble with classes and such..srry
-
March 19th, 2009, 12:09 PM
#4
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();
}
-
March 19th, 2009, 06:12 PM
#5
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|