CSCI 160: Lecture notes on C++ classes

And a linked list example

This linked list only uses the ListItem class, no "outer" list class, and as a result main must keep track of its own pointer to the first (head) list item.
#include <cstdio>
#include <cstdlib>
using namespace std;

class ListItem {
public:

   // available constructors to create new list item
   //   - default has no parameters,
   ListItem();
   //   - alternative version lets you create and initialize
   //     with desired data at the same time
   ListItem(float data, ListItem* next);

   // destructor to free up space once finished
   ~ListItem();

   // functions (aka methods) to get and set data field
   void SetData(float data);
   float GetData();

   // functions to get and set pointer to next item
   void SetNext(ListItem* ptr);
   ListItem *GetNext();

   // function to print list item contents
   void printdata();
   // function to print all following list contents
   void printlist();

private:
   ListItem* nextitem;
   float     listdata;
};

// ============== MAIN ROUTINE ============
int main()
{
  ListItem *head, *itemptr;
  char word[20];
  bool quit = false;

  head = NULL;

  do {
     printf("Enter a positive integer to insert in the list\n,");
     printf("or anything else to quit\n");
     scanf("%20s", word);
     if (atoi(word) <= 0) {
        quit = true;
        printf("Goodbye!\n\n");
     } else {
        itemptr = new ListItem(atoi(word), head);
        head = itemptr;
        printf("The new list contents are:\n   ");
        head->printlist();
        printf("\n\n");
     }
  } while (!quit);

  return 0;
}

// ============= STAND-ALONE FUNCTIONS ===========

// ============= LISTITEM CLASS ROUTINES =========
ListItem::ListItem()
{
   listdata = 0.0;
   nextitem = NULL;
}

ListItem::ListItem(float data, ListItem* next)
{
  listdata = data;
  nextitem = next;
}


ListItem::~ListItem()
{
  if (nextitem != NULL)
     nextitem->~ListItem();
   nextitem = NULL;
   listdata = 0.0;
}


void ListItem::SetData(float data)
{
   listdata = data;
}

float ListItem::GetData()
{
   return listdata;
}

void ListItem::SetNext(ListItem* ptr)
{
   nextitem = ptr;
}

ListItem *ListItem::GetNext()
{
   return nextitem;
}

void ListItem::printdata()
{
   printf("%g\n", listdata);
}

void ListItem::printlist()
{
   printf(" %g", listdata);
   if (nextitem != NULL)
      nextitem->printlist();
}