-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleclass.cpp
More file actions
84 lines (74 loc) · 1.7 KB
/
simpleclass.cpp
File metadata and controls
84 lines (74 loc) · 1.7 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* =====================================================================================
*
* Filename: simpleclass.cpp
*
* Description: Implementing the Methods of a simple Class. Demonstrates declaration
* of a class and definition of class methods.
*
* Version: 1.0
* Created: 02/01/13 16:42:28
* Revision: none
* Compiler: gcc
*
* Author: Robert Halliday (rh), rob_halliday_1@hotmail.com
* Company: rphhpr
*
* =====================================================================================
*/
#include <iostream>
class Cat
{
public:
Cat(int initialAge);
~Cat();
int GetAge();
void SetAge (int age);
void Meow();
private:
int itsAge;
};
// Cat constructor
Cat::Cat(int initialAge)
{
itsAge = initialAge;
}
// Cat destructor
Cat::~Cat()
{
}
// GetAge, Public accessor function
// returns value of itsAge member
int Cat::GetAge()
{
return itsAge;
}
// definition of SetAge, public accessor function
// 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()
{
std::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();
std::cout << "Frisky is a cat who is ";
std::cout << Frisky.GetAge() << " years old.\n";
Frisky.Meow();
Frisky.SetAge(7);
std::cout << "Now Frisky is ";
std::cout << Frisky.GetAge() << " years old.\n";
return 0;
}