Same effect, here's the program I wrote that template for, it's a semi large menu so I broke it down into something smaller for working with the list. My class is just a public char array and a pointer to next.
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include "cust.hpp"
void new_cust(Customer *iter);
void test_func(Customer *iter, Customer *root);
int main(){
//Declare and initialize the customer root node
Customer *root;
Customer *iter;
root = new Customer;
root->next = NULL;
strcpy( root->name, "Start");
iter = root;
for ( ;; ) {
int selection;
cout<<"1. Customers"<<endl
<<"2. Employees"<<endl
<<"3. Locations"<<endl
<<"4. Inventory"<<endl
<<"5. Exit"<<endl
<<"Select an option: ";
cin>>selection;
cin.ignore();
switch(selection){
case 1:
clrscr();
int sel1;
cout<<"1. Create New Customer"<<endl
<<"2. View Customer Account"<<endl
<<"3. Lease Movie to Customer"<<endl
<<"4. View Customer List"<<endl
<<"Select an option: ";
cin>>sel1;
cin.ignore();
switch(sel1){
case 1:
new_cust(iter);
break;
case 2:
test_func(iter, root);
break;
case 3:
//lease movie function();
break;
case 4:
//view customer list function();
break;
default:
cout<<"Invalid selection"<<endl;
break;
}
break;
case 2:
clrscr();
int sel2;
cout<<"1. Create New Employee"<<endl
<<"2. View Employee Data Sheet"<<endl
<<"3. Enter Payroll"<<endl
<<"4. View Payroll Report"<<endl
<<"5. View Employee List"<<endl
<<"Select an option: ";
cin>>sel2;
cin.ignore();
switch(sel2){
case 1:
//new employee function();
break;
case 2:
//view employee data sheet function();
break;
case 3:
//enter payroll function();
break;
case 4:
//view payroll report function();
break;
case 5:
//view employee list function();
break;
default:
cout<<"Invalid selection"<<endl;
break;
}
break;
case 3:
clrscr();
int sel3;
cout<<"1. View Customer List per Location"<<endl
<<"2. View Employee List per Location"<<endl
<<"3. View Inventory List per Location"<<endl
<<"Select an option: ";
cin>>sel3;
cin.ignore();
switch(sel1){
case 1:
//view customer list per location function();
break;
case 2:
//view employee list per location function();
break;
case 3:
//view inventory list per location function();
break;
default:
cout<<"Invalid selection"<<endl;
break;
}
break;
case 4:
clrscr();
int sel4;
cout<<"1. Check-In Inventory"<<endl
<<"2. View Inventory List"<<endl
<<"3. Remove Movie"<<endl
<<"Select an option: ";
cin>>sel4;
cin.ignore();
switch(sel1){
case 1:
//check-in inventory function();
break;
case 2:
//view inventory function();
break;
case 3:
//remove movie function();
break;
default:
cout<<"Invalid selection"<<endl;
break;
}
break;
case 5:
return 0;
default:
cout<<"Invalid selection"<<endl;
break;
}
}
}
// Function to add a new customer
void new_cust(Customer *iter) {
char temp[80];
iter->next = new Customer;
iter = iter->next;
cout << "Enter your name: ";
cin.getline( temp, 80 );
strcpy( iter->name, temp );
iter->next = NULL;
}
//test print of list
void test_func(Customer *iter, Customer *root) {
iter = root;
while ( iter != NULL )
{
int q = 1;
cout << iter->name << " " << q++ << endl;
iter = iter->next;
}
}