-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatFrisky.cpp
More file actions
59 lines (58 loc) · 1.24 KB
/
CatFrisky.cpp
File metadata and controls
59 lines (58 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream> // for cout
using namespace std;
class Cat // begin declaration of the class
{
public: // begin public section
Cat(int initialAge); // constructor
~Cat(); // destructor
int GetAge(); // accessor function
void SetAge(int age); // accessor function
void Meow();
private: // begin private section
int itsAge; // member variable
};
// constructor of Cat,
Cat::Cat(int initialAge)
{
itsAge = initialAge;
}
Cat::~Cat() // destructor, takes no action
{
}
// GetAge, Public accessor function
// returns value of itsAge member
int Cat::GetAge()
{
return itsAge;
}
// Definition of SetAge, public
// accessor function
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 meow again.
int main()
{
Cat Frisky(5);
Frisky.Meow();
cout << "Frisky is a cat who is ";
cout << Frisky.GetAge() << " years old.\n";
Frisky.Meow();
Frisky.SetAge(7);
cout << "Now Frisky is ";
cout << Frisky.GetAge() << " years old.\n";
system("pause");
return 0;
}