I'm having trouble defining the functions get_last, delete_last, and add_item. I've been working on the program for days and can't get the function definitions to work at all, so i left them blank. COULD SOMEBODY PLEASE HELP!!!

This program is suppose to define a List class that holds a list of values of type double. The class contains a default constructor that initializes the list to empty with a default maximum size, a constructor with a single argument of type int that specifies the maximum number of entries in the list (the list is initialized to empty), a member function add_item that adds an item to the end of the list, a member function full that returns true if the list is full and false otherwise, a member function get_size that returns the number of values in the list, a member function get_last that returns the value of the last item in the list, and a member function delete_last that deletes the last item on the list. The operator << is overloaded to print objects of type List. The List is implemented using dynamic arrays. Furthermore, the list is itself dynamic in that if there is an attempt to add to a full list the maximum size of the list is doubled, and if deletion causes the size to drop below half of the maximumnumber of entries the maximum size is reduced to half of the original.

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

using namespace std;

const int MAX_LIST_SIZE = 50;

typedef double* ArrayPtr;

class List
  // Initializes the List object to an empty list with size MAX_LIST_SIZE

  List(int maxSize);
  // Initializes the List object to be a list with at most
  // maxSize entries.

  void add_item(double number);
  // Precondition: number has a value
  // Postcondition: The argument number has been added to
  // the list. If the list was full before adding, its maximum
  // size is double what it was before adding.

  bool full() const;
  // Returns true if the list if full; false otherwise.

  friend ostream& operator <<(ostream& outs, const List& theObject);
  // Overloads the << operator so it can be used to output
  // values of type List.
  // Precondition: If outs is a file stream then outs has
  // already been connected to a file.

  int get_size() const;
  // Returns the number of values in the list.

  int get_max() const;
  // Returns the maximum number of entries in the list.

  double get_last ();
  // Precondition: The List object is defined and non-empty.
  // Returns the last value in the list.

  void delete_last();
  // Precondition: The List object is defined.
  // Postcondition: If the list was nonempty, the last item has
  // been deleted from the list array and size has been decremented;
  // otherwise the list remains empty. If deletion of the item
  // caused the size of the list to drop below half the maximum,
  // then the maximum is reduced to half the original and the
  // amount of space used to store the array is half what it was.

  ArrayPtr list;
  int max;   // maximum number of elements
  int size;  // number of array positions filled

int main()
  // Variable declarations
  double num;        // a number to be added to the list
  char ans;          // loop control
  int size;

  cout << endl << "Testing the List Class" << endl << endl;

  // Get the maximum number of entries and create a List object
  cout << "What is the maximum number of entries in the list? ";
  cin >> size;
  cout << endl;

  List testList(size);

  // Let the user test add_item, delete_last, and get_last as long
  // as he/she wishes
      cout << endl;
      cout << "Enter a to add to the list, d to delete the last entry, " << endl;
      cout << "p to print the last item (without deleting), or s to stop: "; 
      cin >> ans;
      if (ans == 'a' || ans == 'A')
	  // Get the number to be added, add it, then output the list
	  cout << "Enter a number to add to the list: ";
	  cin >> num;
      else if (ans == 'd' || ans == 'D')
      else if (ans == 'p' || ans == 'P')
	cout << endl << "The last item in the list is " 
	     << testList.get_last() << endl;
      else if (ans != 's' && ans != 'S')
	cout << "Not a valid response - try again!" << endl;  
      cout << endl << "Current List" << endl;
      cout << "Capacity: " << testList.get_max() << " Size: "
	   << testList.get_size() << endl;
      cout << "List entries: " << testList << endl;
  while (ans != 's' && ans != 'S');
  return 0;

  size = 0;
  max = MAX_LIST_SIZE;

List::List (int maxSize)
  max = maxSize;
  size = 0;
  list = new double[maxSize];
  void add_item(double number)

 double get_last()

 void delete_last()

bool List::full() const
  return (size == max);

ostream& operator <<(ostream& outs, const List& theObject)
  for (int i = 0; i < theObject.size; i++)
    outs << theObject.list[i] << "  ";
  return outs;

int List::get_size() const
  return size;

int List::get_max() const
  return max;
This article has been dead for over six months. Start a new discussion instead.