1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
// CS 1410 Final Project
// add your file prologue information here
#include <iostream>
#include "CarPart Header.h"
using namespace std;
// the printlist function
// Purpose: Prints out the contents for each Node in the List
// Parameter: A list object, by const reference
// Returns: none
void printList(const List&);
// the printFirstNode function
// Purpose: Prints out the contents for the 1st Node in the List
// Parameter: A list object, passed by value to test the copy constructor
// Returns: none
void printFirstNode(List);
int main()
{
// set up cout for displaying prices
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// create a List object
List partsList;
cout << "\nPart I: multiple node test: push_front and pop_front\n";
cout << "\n----------------------------------\n";
// build a List using push_front
partsList.push_front(new Node(new CarPart("FL2016", "Oil Filter", 18.95)));
partsList.push_front(new Node(new CarPart("RS12YC", "Spark Plug", 4.15)));
partsList.push_front(new Node(new CarPart("D5941", "Digital Tire Guage", 12.15)));
partsList.push_front(new Node(new CarPart("G19216", "Car Wash Solution", 8.15)));
cout << "\nThe original nodes in the List:\n";
printList(partsList);
cout << "\n----------------------------------\n";
// test push_front function
cout << "\nAdding to the front of the List:\n";
cout << "\n----------------------------------\n";
partsList.push_front(new Node(new CarPart("X-5077a", "Wiper Blades", 15.45)));
partsList.push_front(new Node(new CarPart("T-280RA", "Turtle Wax Chrome Polish", 3.15)));
printList(partsList);
cout << "\n----------------------------------\n";
// test pop-front
cout << "\nRemoving the first node from the list.\n";
cout << "\n----------------------------------\n";
Node* item = partsList.pop_front();
printList(partsList);
if (item != NULL)
delete item;
cout << "\n----------------------------------\n";
cout << "\nPart Two: Push_back and pop_back";
// test push_back
partsList.push_back(new Node(new CarPart("C120-X", "Assorted Fuses", 7.25)));
partsList.push_back(new Node(new CarPart("CTK-120706", "Mechanic Tool set", 126.00)));
cout << "\nAdding two nodes at the end\n";
cout << "\n----------------------------------\n";
printList(partsList);
// test pop-back
cout << "\n----------------------------------\n";
cout << "\nRemove last node from the list\n";
cout << "\n----------------------------------\n";
item = partsList.pop_back();
printList(partsList);
if (item != NULL)
delete item;
cout << "\n-------------------------------------------\n";
cout << "\nEnd of Test";
cout << "\n-------------------------------------------\n";
system("PAUSE");
return 0;
}
// you have to fill in the code for this function
void printList(const List& theList)
{
}
// you have to fill in the code for this function
void printFirstNode(List theList)
{
cout << theList.getFirstNode;
}
|