Thread: Data Abstraction?

  1. #1
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235

    Data Abstraction?

    Recently I finished a Binary Tree program. Though finished, my teacher's comments were "you did not abstract your data seperately" so here i am, i have an idea of what is meant but id like for some explanation better.

    Ok so i have a structure like this:
    Code:
    typedef struct mystruct{
         int data;
         char charater;
         float dat;
        }MYSTRUCT;
    so far what iv understood is that id have a separate struct like to manipulate the data, anyhow I'm just here for further advice, or if anyone can link me up to examples which shows this concept, I'd prefer examples if there are, i tried google but couldnt find any close to the concept, maybe its just me:

    Code:
    typedef  struct data{
           MYSTRUCT *data;
           struct data *right;
           struct data *left;
    }DATA;
    
    DATA *DataPtr;
    Thanks
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  2. #2
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Check this out, Senor.

    Code:
    typedef struct data_t
    {
      void *absract;
      struct data_t *left, *right;  
    } data_t;
    Now a data_t doesn't physically hold your data, rather it just points to your data. Thus it is abstract. Did Elysia not explain this to you?

  3. #3
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Quote Originally Posted by c++0x View Post
    Check this out, Senor.

    Code:
    typedef struct data_t
    {
      void *absract;
      struct data_t *left, *right;  
    } data_t;
    Now a data_t doesn't physically hold your data, rather it just points to your data. Thus it is abstract. Did Elysia not explain this to you?
    Hehe, is who i think? Damn Elysia, I have seen my message box in red, but havent checked, i totally forgot.
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  4. #4
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Yep but I half 2 act dum cuz I alreddy gt messed up. So yes, this is "Jeff" ..........4m class ;-)

  5. #5
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Quote Originally Posted by c++0x View Post
    Yep but I half 2 act dum cuz I alreddy gt messed up. So yes, this is "Jeff" ..........4m class ;-)
    Hehe k Jeff, umm well i just read Elysia's Mssg, but dnt want to send her all codes, it will be too much, if i could just grasp the real idea behind the concept i think i can take it up from there.

    so void *absract; will be pointing to the current data, and the pointers to the left and right will act the same way i had them doing, right is that the idea.
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  6. #6
    Banned
    Join Date
    Dec 2008
    Location
    Maputo, Mozambique
    Posts
    82
    Check this out

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    int sorter(const void *a, const void *b)
    {
      return *(const int *a) - *(const int *)b;
    }
    
    int main(void)
    {
      int my_values[] = {1,7,35,12,133,-17,32,151,16737};
      int **array;
      int i;
    
      if((array = malloc(sizeof(my_values) / sizeof(*my_values) * sizeof(int *))))
      {
        for(i = 0; i < sizeof(my_values) / sizeof(*my_values); i++)
          array[i] = my_values + i;
      }
    
      qsort(array, sizeof(my_values) / sizeof(*my_values), sizeof(int *), sorter);
    
      for(i = 0; i < sizeof(my_values) / sizeof(*my_values); i++)
        printf("&#37;d\n", *array[i]);
    
      return 0;
    }
    Abstract.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by c++0x View Post
    Check this out, Senor.

    Code:
    typedef struct data_t
    {
      void *absract;
      struct data_t *left, *right;  
    } data_t;
    Now a data_t doesn't physically hold your data, rather it just points to your data. Thus it is abstract. Did Elysia not explain this to you?
    You should not rely much on techniques like this, I think.
    It create opportunity for a lot of bugs.
    Abstraction is better left for C++, where there are much better facilities to make this.

    Of course, using C, techniques like this may be important to know, but you must also know that they can be dangerous, as well.
    And unfortunately, C lacks good generic programming, which makes things such as this common.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Quote Originally Posted by Elysia View Post
    You should not rely much on techniques like this, I think.
    It create opportunity for a lot of bugs.
    Abstraction is better left for C++, where there are much better facilities to make this.

    Of course, using C, techniques like this may be important to know, but you must also know that they can be dangerous, as well.
    And unfortunately, C lacks good generic programming, which makes things such as this common.

    Hmm i see, teacher said its good to learn this so that when you move to C++ you have an idea already about how stuff works, anyway semester is done , just wanted to figure something about the concept
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  9. #9
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Good Teacher.. Really good teacher.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  10. #10
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Quote Originally Posted by WDT View Post
    Good Teacher.. Really good teacher.
    Yup, he's cool !
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM