CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    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;
    }

  2. #2
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    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.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  3. #3
    Join Date
    Mar 2009
    Posts
    2

    Re: Help with Classes

    got this from the book..just kind of having trouble with classes and such..srry

  4. #4
    Join Date
    Mar 2009
    Location
    Granada, Spain
    Posts
    40

    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();
    }

  5. #5
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    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?
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured