CS 302 Data Structures C Interlude 1 C Classes Classes file PlainBox.h ifndef PLAINBOX define PLAINBOX Set the type of data stored in the box typedef double ItemType; Declaration for the class PlainBox class PlainBox
"CS 302 Data Structures C++ Interlude 1 C++ Classes" is the property of its rightful owner. Permission is granted to
download and print the materials on this website for personal, non-commercial use only, and to display it
on your personal computer provided you do not modify the materials and that you retain all copyright
notices contained in the materials. By downloading content from our website, you accept the terms of this
agreement.
Presentation Transcript
01
CS 302 Data Structures C++ Interlude 1
C++ Classes<br>
02
Classes<br>
03
/** @file PlainBox.h */
#ifndef _PLAIN_BOX
#define _PLAIN_BOX
// Set the type of data stored in the box
typedef double ItemType;
// Declaration for the class PlainBox
class PlainBox
{
private:
// Data field
ItemType item;
public:
// Default constructor
PlainBox ();
// Parameterized constructor
PlainBox (const ItemType & theItem);
// Method to change the value of the data field
void setItem (const ItemType & theItem);
// Method to get the value of the data field
ItemType getItem () const;
}; // end PlainBox
#endif<br>
04
/** @file PlainBox.cpp */
#include "PlainBox.h"
PlainBox::PlainBox ()
{
} // end default constructor
// Mutator method that can change the value of the data field
void setItem (const ItemType & theItem);
// Accessor method to get the value of the data field
ItemType getItem () const;
}; // end PlainBox
#include "PlainBox.cpp" // Include the implementation file
#endif<br>
07
/** @file PlainBox.cpp */
template < class ItemType >;
PlainBox < ItemType >::PlainBox ()
{
} // end default constructor