Thread: CLasses

  1. #1
    Registered User zergdeath1's Avatar
    Join Date
    Sep 2003
    Posts
    39

    CLasses

    Please im just practicing to get better at classes:

    Code:
    #include<iostream.h>
    #define PI 3.14
    
    class circle {
    int x;
    
    public:
    int radiuss (int r) {x=r;}
    int radius (void) {return  PI(x^2);}
    };
    
    int main (){
    circle one;
    one.radiuss (2);
    cout<<one.radius;
    return 0;
    }
    Stolen Quote: Buttered Toast always lands butter side down and cats always land on their feet, what happens when you strap buttered Toast to the back of a cat?
    My Quote: Practice Makes Perfect Nobodys Perfect Why Practice?

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    So what is your question? I assume you will have a problem with x^2 since the "^" operator is actually the XOR operator...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Give your member variables and functions more descriptive names.

    Code:
    class circle 
    {
    private:
    	int nRadius;
    public:
    	void SetRadius (int nRadius_) {nRadius=nRadius_; }
    	int GetArea (void) {return  PI*pow(nRadius,2); }
    };
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM