Hello, I am quite confused on this program we are supposed to write using classes. The first part of the question is like this:
1 2 3 4 5 6 7 8 9 10 11
1) Write a method called contains that takes a Word object, w, as an argument and returns a boolean value.
The post-condition forthis method is that the return
value is trueif and only if the letters in w are a subset
of the letters in the current Word object.
2) Overload the - operatorfor the word class. This operator should take two Word objects as operands, w1 and w2.
The post-condition is that the Word object that is
returned contains the letters in w1 that are not in w2,
in alphabetical order. Note that if w1 contains 2 of
the letter 'a' and w2 contains 1 letter 'a', the return
value should contain 1 'a'.
Sidenote: You could provide a constructor so you can initialize a Word object without having to use the set method and keep the set method incase you wish to change that word object at a later time.
Your contains method prototype should look like such(I think! Don't take my word for it but maybe it will get you thinking about why and when you should use key words such as const.)
bool contains(const Word & w) const;
You are passing a word object (in the above code snippet that is a reference to a word object 'w'). The code's intention is not to modify the parameter(the word object that you passed to the contains function) so it is defined as a const, also the const after the parentheses means that the implicit object(the one that you are using to call contains with) should also not be modified.
1 2
bool contains(string word);
{ return; }
Because you provide the curly braces here with a return value you have already defined the function(mainly, a function that does nothing but return;).
Method is referring to class member functions, yes. Your boolean function is incorrect.