Thread: Header File help

  1. #1
    Registered User
    Join Date
    Sep 2002

    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}.

    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

    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.

    # 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);	
    	bool alphaset[26];
       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);

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    I believe you should change:
    alphaset operator +(alphaset);

    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.

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Göteborg, Sweden
    No, Magos.
    That part of the declaration is correct.

    One question, Traz:
    Why isn't the * operator a member function?
    Last edited by Sang-drax; 09-15-2002 at 01:17 PM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Registered User
    Join Date
    Sep 2002
    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)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM