-
Header File help
My prof gave me an assignment. it was to creat a header file and implement it. its similar to what i had the semister previous.
Define and implement an abstract data structure "AlphaSet" to represent a set of characters {a, b, c,..., z}.
[fyi]
AlphaSet: It is a collection of letters a...z. An example: S = {a, b, d, i, n} is a collection of 5 letters.
overload these
Code:
1 Union + C = A + B C = { x | x in A or x in B}
2 Intersection * C = A * B C = { x | x in A and x in B}
3 Subtract - C = A - B C = { x | x in A and x not in B}
4 Insert + C = A + p C = All letters in A and the letter (stored) in p
5 Delete - C = A - p C = A without the letter (stored) in p
6 Copy = C = A C = { x| x in A}
7 Complement ! C = !A C = { x| x not in A}
8 Subset < A < B Returns true if the all the letters in A are in B; returns false, otherwise.
9 Superset > A > B Returns true if the all the letters in B are in A; returns false, otherwise.
10 Equal == A == B Returns true if the letters in A and B are the same; returns false, otherwise.
11 Print << cout << A Prints the set A in the format {a, c, t, u}
12 Read >> cin >> A Reads a set A entered in the format {a, c, t, u}
i also had to:
Use a boolean array of size 26 to represent a set in AlphaSet.
Implement the ten operations given in the table. The operations indicated above must be implemented by overloading the operators.
In addition to the operations indicated above include the following functions:
A member function Assign that accepts a string as a parameter and assigns a set to have the letters in that string.
A function named Member, which when called A.Member(p) returns true only if the letter stored in p is found in the set A.
A function named Size that returns the size of a set.
i wrote a header file but im clue less on most of the implementation i just wanted to check my *.H file with u guys before i started rattleing myself with implementating it.
Code:
# ifndef alphaset_H
# define alphaset_H
# include <iostream.h>
# include <fstream.h>
class alphaset
{
friend ostream & operator <<(ostream &,alphaset &);
friend istream & operator >>(istream &,alphaset &);
friend alphaset operator *(alphaset,alphaset);
private:
bool alphaset[26];
public:
alphaset(bool=0);
alphaset operator +(alphaset);
alphaset operator -(alphaset);
alphaset operator *(alphaset);
alphaset operator !(alhpaset);
alphaset operator +(alphaset, char)
alphaset operator -(alphaset, char)
void operator =(alphaset);
bool operator ==(alphaset &);
bool operator <(alphaset);
bool operator >(alphaset);
void assign (bool);
void assign (bool[26]);
bool member (char);
int size (alphaset);
};
#endif
-
I believe you should change:
alphaset operator +(alphaset);
into:
alphaset& operator +(alphaset&, alphaset&);
(and on the others)
After all, you need two sets to do an addition (A + B, you can't do just A + :)).
And according to those iostream declarations you have in your code, you need to use & (they are references). I'm not sure if you must return a reference, or if you can just return an object.
-
No, Magos.
That part of the declaration is correct.
One question, Traz:
Why isn't the * operator a member function?
-
i dont know why i did that, perhaps cause i was thinking about something else such as A*B and A*p but the latter wasnt given as an operation to do so i assume i shall take out the 3rd friend function the alphaset operator *(alphaset, alphaset)