Adt help....

This is a discussion on Adt help.... within the C++ Programming forums, part of the General Programming Boards category; hey I'm new here and I was wondering if anyone can help me to under stand what an ADT (abstract ...

  1. #1
    Novice Programmer Pyroteh's Avatar
    Join Date
    Jan 2005
    Location
    Alaska
    Posts
    82

    Adt help....

    hey I'm new here and I was wondering if anyone can help me to under stand what an ADT (abstract data type) is.... this isn't for homework or anything I just want to understand it.... I've read the chapter on ADT's many times but still don't really get it....

    a quick and east example would be great also...


    Code:
     cout << "test to see if I'm doing the code tags right :P" << endl;
    Last edited by Pyroteh; 01-12-2005 at 01:12 AM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    there may be other uses for this, but let me give you an example -

    you have a payroll program you need to write.
    you will have 3 classes
    class 1: a base class called person ( ADT)
    class 2: hourly worker
    class 3: salaried worker

    classes 2 and 3 are derived from "person"
    person looks like this -
    Code:
    class person
    {
          char name[20];
          date birthday;
          virtual float calculatePayCheck(void) const = 0;      //this line makes this class pure virtual
                                                                                  //  (abstract)
                                                                                  //it is the responsibility of all derived     
                                                                                 //classes to specify the action to be taken
                                                                                  //when this function is called
    }
    since both salaried and hourly workers both get pay checks and since you may need to reference both types of employees together when creating their paychecks, you can now refer to both of them the same way. let me elaborate. you want to store all employees in an array. well you certainly can't create an array that stores both salaried and hourly workers. but you can create an array of pointers type "person". both types of employees pay checks gets calculated differently, however, you can now treat both types as if they were the same. instead of having to call Salaried::calculatePayCheck and Hourly::calculatePayCheck you just simply call calculatePayCheck and the compiler/program knows which is which.

    this is a really rough explaination - my intention was to dumb it down quite a bit becuase it is a rather abstract subject . i suggest reading up on polymorphism and then re-reading about ADT. you probably really won't understand all that well until you do some examples too.
    Last edited by misplaced; 01-11-2005 at 04:29 PM.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    In a short statement:

    An ADT is a class that you use as a base class for several related classes, where it does not make sense to create an object of the base type.

    In misplaced's demonstration, for example, the derived classes of HourlyEmployee and SalariedEmployee make sense. You can have a salaried employee or an hourly one, and they are logically connected (not to mention share a "lot" of functionality), but in the example, you can't have someone who is neither, so Person becomes abstract.

    *edit*
    If you are at all familiar with Java, then the idea is similar to that of an Interface in Java (of course, in C++, you can have functionality in your ADTs). And from an OO standpoint, ADTs are essentially interfaces.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Novice Programmer Pyroteh's Avatar
    Join Date
    Jan 2005
    Location
    Alaska
    Posts
    82
    ok thanks guys....

    would this count as a valid ADT?

    Code:
    class ModuloCounter
    {
    public:
         void Increment();
    
    private:
         unsigned int m_nCount;
    } 
    
    void ModuloCounter::Increment()
    {
        if (m_nCount >= THE_VALUE_YOU_WANT)
        {
             m_nCount = 0;
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  2. Array-based ADT list
    By campermama in forum C++ Programming
    Replies: 0
    Last Post: 06-14-2004, 01:32 PM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. Problem with My Sets ADT
    By jawwadalam in forum C++ Programming
    Replies: 2
    Last Post: 10-04-2002, 06:36 AM
  5. ADT Initialization/Passing of Array from Friended ADT
    By Wiggin in forum C++ Programming
    Replies: 1
    Last Post: 04-27-2002, 12:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21