Thread: array

  1. #1
    Unregistered
    Guest

    array

    How to write a constructor function to initialize the list to an empty list (array). The argument of the constructor will determine the maximum items which may be entered into the list.
    and how to make it return true if the list is full

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >How to write a constructor function to initialize the list to an empty list (array).
    Code:
    Constructor :: Constructor ( int n )
    {
      // Don't forget to check for errors
      array = new char[n];
      size = n;
    }
    >how to make it return true if the list is full
    Make a helper function that specifically checks if the array is full and returns true if it is:
    Code:
    bool Constructor :: isFull()
    {
      size_t len;
      if ( ( len = strlen ( array ) ) == size )
        return true;
      cout<<"Total space:     "<< size <<"\n"
          <<"Available space: "<< size - len <<"\n";
      return false;
    }
    And lastly, be sure to free the allocated space with your destructor.

    -Prelude
    My best code is written with the delete key.

  3. #3
    unregistered
    Guest
    that was so helpful thank you very much and God bless you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM