Repository navigation
Expand file tree
/
Copy pathAlchemist.cpp
More file actions
119 lines (106 loc) · 5.31 KB
/
Copy pathAlchemist.cpp
File metadata and controls
119 lines (106 loc) · 5.31 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
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
#include "Element.h"
#include "Alchemist.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
// Name: Alchemist() - Default Constructor
// Desc: Used to build a new Alchemist
// Preconditions - Requires default values
// Postconditions - Creates a new Alchemist
Alchemist::Alchemist(){}
// Name: Alchemist(name) - Overloaded constructor
// Desc - Used to build a new Alchemist
// Preconditions - Requires name
// Postconditions - Creates a new Alchemist
Alchemist::Alchemist(string name){}
// Name: GetName()
// Desc - Getter for Alchemist name
// Preconditions - Alchemist exists
// Postconditions - Returns the name of the Alchemist
string Alchemist::GetName(){
return m_myName;
}
// Name: SetName(string)
// Desc - Allows the user to change the name of the Alchemist
// Preconditions - Alchemist exists
// Postconditions - Sets name of Alchemist
void Alchemist::SetName(string name){
m_myName = name;
}
// Name: DisplayElements()
// Desc - Displays a numbered list of all elements known by the Alchemist
// Preconditions - Alchemist exist
// Postconditions - None
void Alchemist::DisplayElements(){
for (int i = 0; i < m_numElements; i++){
cout << i+1 << ". ";
cout << m_myElements[i].m_name << endl;
}
}
// Name: GetNumElements()
// Desc - Returns number of elements known by the Alchemist
// Preconditions - Alchemist exists
// Postconditions - None
int Alchemist::GetNumElements(){
return m_numElements;
}
// Name: CheckElement(Element)
// Desc - Checks to see if the Alchemist has an element
// Preconditions - Alchemist already has elements
// Postconditions - Returns true if Alchemist has element else false
bool Alchemist::CheckElement(Element check){
bool value = false;
for(int i = 0; i < GetNumElements(); i++){
if((check.m_name).compare(m_myElements[i].m_name) == 0){
value = true;
cout << "TRUE" << endl;
}
}
return value;
}
// Name: AddElement(Element)
// Desc - Adds element to m_myElements if not known increases numElements
// Preconditions - Alchemist exists and new element not already known
// Postconditions - Adds element to m_myElements
void Alchemist::AddElement(Element add){
m_numElements += 1;
m_myElements[m_numElements-1] = add;
}
// Name: GetElement(int)
// Desc - Checks to see if the alchemist has an element
// Preconditions - Alchemist already has elements
// Postconditions - Returns element at index
Element Alchemist::GetElement(int num){
return m_myElements[num];
}
// Name: AddAttempt
// Desc - Increments attempts
// Preconditions - Alchemist attempts a merge
// Postconditions - Increments every time a merge is attempted
void Alchemist::AddAttempt(){
m_attempts += 1;
}
// Name: GetAttempts()
// Desc - Returns number of attempts for that Alchemist
// Preconditions - Alchemist exists
// Postconditions - Returns total number of attempts
int Alchemist::GetAttempts(){
return m_attempts;
}
// Name: AddRepeat()
// Desc - Increments repeats for every time an element has already been found
// Preconditions - Alchemist attempts a merge
// Postconditions - Increments every time a merge yields an element already fou\
nd
void Alchemist::AddRepeat(){
m_repeats += 1;
}
// Name: GetRepeats()
// Desc - Returns number of repeats for that Alchemist
// Preconditions - Alchemist exists
// Postconditions - Returns total number of repeats
int Alchemist::GetRepeats(){
return m_repeats;
}