|
-
Jun 28th, 2001, 06:16 PM
#1
Thread Starter
Member
Beginning Classes
I started learning c++ a few weeks ago, and now I got to the chapter with Basic Classes. I kind of understood the whole chapter, but when I tried to make my own program using classes, it didn't work. So I tried to copy one from the book. It doesn't work also. Can someone tell me whats wrong with this program?
Ps. I just started learning c++, so please don't use those advanced methods. Thank You.
Here's the program:
#include <iostream.h>
#include <stdlib.h>
class cat
{
public: // begins public section
int getAge();
void setAge(int age);
void meow();
private: // begins private section
int itsAge();
};
// GetAge, public accesor function
// returns value of itsAge member
int cat::getAge()
{
return itsAge;
}
// definition of setAge, public
// accesor dunction
// returns sets itsAge member
void cat::setAge(int age)
{
// set member variable its age to
// value passed in by parameter age
itsAge = age;
}
//definition of Meow method
// returns : void
// parameters : none
// action : Prints "meow" to screen
void cat::meow()
{
cout << "Meow.\n";
}
// Create a cat, set its age, have it
// meow, tell us its age, then move again.
int main()
{
cat Frisky;
Frisky.setAge(5);
Frisky.meow();
cout << "Frisky is a cat who is " ;
cout << Frisky.getAge() << " years old.\n";
Frisky.meow();
system("PAUSE");
return 0;
}
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
|