Thread: Classes
View Single Post
Old Apr 28th, 2005, 1:45 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
It's a waste of space, but here you go (this is in C++):
#include <iostream>
using namespace std;

class Number
{
private:
    int num;
    
    // this is a constructor - it's executed as soon as the class is created.
    Number ()
    {
        num = 0;
    }
    
    // this is a destructor - it's executed when the class is destroyed.
    ~Number ()
    {
    }
    
public:
    int getNum ()
    {
        return num;
    }
    
    void setNum (int newNum)
    {
        num = newNum;
    }
    
    void printNum ()
    {
        cout << num << endl;
    }
    
    void incrementNum ()
    {
        num++;
    }
}

int main ()
{
    Number num; // this creates a new instance of the class called "num"
    
    while (num.getNum() <= 10)
    {
        num.incrementNum();
        num.printNum();
    }
    
    return 0;
}
NB: this is untested. Enjoy!
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote