-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path55_constructors.cpp
More file actions
74 lines (67 loc) · 1.18 KB
/
55_constructors.cpp
File metadata and controls
74 lines (67 loc) · 1.18 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
/*Goal: learn to use constructors*/
#include<iostream>
using namespace std;
//The cats class that we used earlier in the lesson.
class Cats
{
string name;
string breed;
int age;
public:
Cats(); //declaring the constructor
void setName(string nameIn);
void setBreed(string breedIn);
void setAge(int ageIn);
string getName();
string getBreed();
int getAge();
void printInfo();
};
//defining the constructor
Cats::Cats()
{
cout<<"Assigning inital values in the constructor\n";
name = "Unknown";
breed = "Unknown"; //the initial value of the breed
age = 99; //the initial value of the age
}
void Cats::setName(string nameIn)
{
name = nameIn;
}
void Cats::setBreed(string breedIn)
{
breed = breedIn;
}
void Cats::setAge(int ageIn)
{
age = ageIn;
}
string Cats::getName()
{
return name;
}
string Cats::getBreed()
{
return breed;
}
int Cats::getAge()
{
return age;
}
void Cats::printInfo()
{
cout<<name<<" "<<breed<<" "<<age;
}
//+++++++
int main()
{
Cats cat1;
cout<<"Cat1 information: ";
cat1.printInfo();
return 0;
}
/*
Assigning inital values in the constructor
Cat1 information: Unknown Unknown 99
*/