/*********************************************************************** * PROGRAM: class1Commented.cpp * This program illustrates how to properly comment a C++ * program. This is called a header comment and should be * present in every program. It should specify the overall * function of the code and identify the author. * * This program is the first attempt at maintaining a linked list * in C++. There is one class called linkedListclass which * has all methods as "stubs" * * AUTHOR: Martin Maskarinec * Date: 01/27/2010 ***********************************************************************/ #include using namespace std; /*********************************************************************** * CLASS linkedListclass * This class implements the linked list for this program. It * has private data members for the value and a pointer to the * next one. The methods to create, get the value, insert after * and print the list are stubs for now. ***********************************************************************/ class linkedListclass { public: /*********************************************************************** * NAME: linkedListclass (constructor) * INPUT: newvalue --> an integer with which to initialize the dvalue * of this node. * OUTPUT: none * FUNCTION: initialize the private data members of this node. ***********************************************************************/ linkedListclass(int newvalue) { cout << "Method linkedListClass::linkedListClass called...\n\n"; } /*********************************************************************** * NAME: getdvalue * INPUT: None. * OUTPUT: An integer --> the current value of dvalue * FUNCTION: This is the accessor method for dvalue. ***********************************************************************/ int getdvalue() { cout << "Method linkedListClass::getdvalue called...\n\n"; return(1); } /*********************************************************************** * NAME: addbehind * INPUT: An integer to insert * OUTPUT: None. * FUNCTION: Add the given value after the first element in the list. ***********************************************************************/ void addbehind(int newvalue) { cout << "Method linkedListClass::addbehind called...\n\n"; } /*********************************************************************** * NAME: printlist * INPUT: None. * OUTPUT: None. * FUNCTION: This will print all the elements in the linked list. ***********************************************************************/ void printlist() { cout << "Method linkedListClass::printlist called...\n\n"; } /*********************************************************************** * PRIVATE DATA MEMBERS for linkedListclass * Each instance of this class will have an integer data member * and a pointer to the next element of the linked list. * ***********************************************************************/ private: int dvalue; linkedListclass *next; }; /*********************************************************************** * NAME: main * INPUT: None. * OUTPUT: An integer --> 0 if main exits normally * FUNCTION: This is the main entry point of the program. Here, we * normally would declare all instances and perhaps * present the user with a menu choice of options. This * program simply provides "driver" calls to linked list * class methods. ***********************************************************************/ int main() { linkedListclass *first; first= new linkedListclass(23); cout << "The value is " << first->getdvalue() << endl; first->addbehind(45); first->printlist(); first->addbehind(100); first->printlist(); return 0; }