Thread: Help getting started

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    3

    Question Help getting started

    well the assignment is to develop an abstract type for handling characters. Only handling 26 capital letters. I have this need help with CharSet.cc

    Code:
    //CharSet.h
    
    class CharSet
    {
       private:
              bool Contents [26];
    
       public:
              CharSet(); //constructor initializes set to be empty
    
              void Add(char Value); //add character to set corresponding bool set to 
                                                         true
              void Remove(char Value);  //Removes char corresponding set to true
    
              void Union(CharSet ASet); //Union the set passed a parameter into set
    
              void Intersect(CharSet ASet); //Intersects set passed a parameter
                                                              contains results of intersection
              bool Member(char Value) const; 
    }//end class CharSet
    Also have testSet.h which is my test
    Code:
    #include "Charset.h"
    #include <iostream>
    using namespace std;
    void printSet(CharSet ASet)
    {
         for (char c = 'A' ; c <= 'Z' ; c++)
         {
              if (ASet.Member (c))
              {
                   cout << c;
              }; //end if
         }; //end for
         cout << endl;
    }; //end printSet
    int main()
    {
       CharSet Set1;
       CharSet Set2;
       CharSet Set3;
    
       Set1.Add('A');
       Set1.Add('B');
       Set1.Add('C');
       Set2.Add('B');
       Set2.Add('C');
       Set2.Add('D');
       Set3.Add('A');
       Set3.Add('B');
       Set3.Add('C');
    
       Set1.Intersect(Set2);
       Set3.Union(Set2);
       Set2.Remove('C');
       cout << "Expect BC" << endl;
       printSet(Set1);
       cout << "Expect ABCD" << endl;
       printSet(Set3);
       cout << "Expect BD" << endl;
       printSet(Set2);
       return 0;
    }; //end main
    thats what i have I really stuck on what to write in CharSet.cc and I was wondering if anyone could help me get started or anything.
    correct me if im wrong but the add an remove you simple enter Contents[Value]=true; for add and false for remove. My problems is I don't exactly know what to put in the constructor and how to get a set of char in the union portion how do i add them to a set. If someone can maybe explain. I really want to understand this fully.

    Any help would be appreciated.
    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    For example, one function in Charset.cpp would be
    Code:
    #include "CharSet.h"
    
    void CharSet::Add(char Value) {
        Contents[Value-'A'] = true;
    }
    >Also have testSet.h which is my test
    Call it testSet.cpp
    It is not a header file, but it is source code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help getting started..matrices
    By BobDole11 in forum C Programming
    Replies: 7
    Last Post: 11-15-2008, 09:51 PM
  2. Help getting started :(
    By blackocellaris in forum C Programming
    Replies: 4
    Last Post: 11-05-2006, 06:50 PM
  3. Getting started
    By panzeriti in forum Game Programming
    Replies: 3
    Last Post: 06-28-2003, 10:13 AM
  4. How to get started?
    By anoopks in forum Linux Programming
    Replies: 0
    Last Post: 01-14-2003, 03:48 AM
  5. Need help getting started
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2001, 11:08 PM