Getter and Setter functions outside the class

edit: I was able to find the answer I was looking for, no need to reply.

I'm currently working on an assignment, and for the second part of it I am required to place all functions outside of a class. The program also utilizes 'Catch' to test several conditions to see if they are met. In the first part of the assignment, where I was required to place the constructors, setters, and getters inside class, my code executed without error. I wrote the second part of the assignment the same way, and received several error messages. I was seemingly able to fix the errors with the constructors by simply placing 'Beverage::' before the constructor and listing the function inside the class. However, the same does not seem to work for my setters and getters. I can't seem to find any tutorials that specifically deal with setters and getters outside of a class. I've commented out most of TEST_CASE so I can work on one function at a time, starting with getDescription. Any ideas of how to resolve this? Thanks in advance.

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  class Beverage 
{
	public:
		string description;
		bool servedHot;
		int ounces;
		char size;
		Beverage();
		Beverage(string newDescription);
		Beverage(string newDescription, bool newServedHot);
		Beverage(string newDescription, bool newServedHot, int newOunces);
		Beverage(string newDescription, bool newServedHot, int newOunces, char newSize);
		string getDescription();
};

Beverage::Beverage ()
{
	description = "No Description";
	servedHot = false;
	ounces = 0;
	size = 'U';
}

Beverage::Beverage (string newDescription)
{
	description = newDescription;
	servedHot = false;
	ounces = 0;
	size = 'U';
}

Beverage::Beverage (string newDescription, bool newServedHot)
{
	description = newDescription;
	servedHot = newServedHot;
	ounces = 0;
	size = 'U';
}

Beverage::Beverage (string newDescription, bool newServedHot, int newOunces)
{
	description = newDescription;
	servedHot = newServedHot;
	ounces = newOunces;
	size = 'U';
}

Beverage::Beverage (string newDescription, bool newServedHot, int newOunces, char newSize)
{
	description = newDescription;
	servedHot = newServedHot;
	ounces = newOunces;
	size = newSize;
}

void setDescription (string newDescription)
{
	string description = newDescription;
}

void setServedHot (bool newServedHot)
{
	bool servedHot = newServedHot;
}

void setOunces (int newOunces)
{
	int ounces = newOunces;
}

void setSize (char newSize)
{
	char size = newSize;
}

Beverage::string getDescription () 
{
	return description;
}

bool getServedHot (bool servedHot)
{
	return servedHot;
}

int getOunces (int ounces)
{
	return ounces;
}

char getSize (char size)
{
	return size;
}

TEST_CASE ("Beverage class functionality", "[Beverage]") 
{
 	Beverage bevOne;
 	Beverage bevTwo("Latte");
 	Beverage bevThree("Latte", true);
 	Beverage bevFour("Latte", true, 8);
 	Beverage bevFive("Latte", true, 8, 'S');

 	CHECK(bevOne.getDescription() == "No Description");
 	//CHECK(bevOne.getServedHot() == false);
 	//CHECK(bevOne.getOunces() == 0);
 	//CHECK(bevOne.getSize() == 'U');

 	//bevOne.setDescription("Hot Chocolate");
 	//bevOne.setServedHot(true);
 	//bevOne.setOunces(12);
 	//bevOne.setSize('M');

 	//CHECK(bevOne.getDescription() == "Hot Chocolate");
 	//CHECK(bevOne.getServedHot() == true);
 	//CHECK(bevOne.getOunces() == 12);
 	//CHECK(bevOne.getSize() == 'M');

 	//CHECK(bevTwo.getDescription() == "Latte");
 	//CHECK(bevTwo.getServedHot() == false);
 	//CHECK(bevTwo.getOunces() == 0);
 	//CHECK(bevTwo.getSize() == 'U');

 	//CHECK(bevThree.getDescription() == "Latte");
 	//CHECK(bevThree.getServedHot() == true);
 	//CHECK(bevThree.getOunces() == 0);
 	//CHECK(bevThree.getSize() == 'U');

 	//CHECK(bevFour.getDescription() == "Latte");
 	//CHECK(bevFour.getServedHot() == true);
 	//CHECK(bevFour.getOunces() == 8);
 	//CHECK(bevFour.getSize() == 'U');

 	//CHECK(bevFive.getDescription() == "Latte");
 	//CHECK(bevFive.getServedHot() == true);
 	//CHECK(bevFive.getOunces() == 8);
 	//CHECK(bevFive.getSize() == 'S');
}
Last edited on
Topic archived. No new replies allowed.