Networknode.h
#ifndef NETWORKNODE
#define NETWORKNODE
#include <iostream>
using namespace std;
class Networknode{
public:
void add_node_at_end();
void display_list();
};
#endif
networknode.cpp
#include<iostream>
#include"Networknode.h"
using namespace std;
struct node
{ char idnum[20];
char ipad[20];
char os[20];
node *nxt;
};
node *start_ptr = NULL;
node *current;
int option = 0;
void Networknode::add_node_at_end()
{ node *temp, *temp2; // Temporary pointers
// Reserve space for new node and fill it with data
temp = new node;
cout << "Please enter the ID number: ";
cin >> temp->idnum;
cout << "Please enter the ip address of the person : ";
cin >> temp->ipad;
cout << "Please enter the os of the person : ";
cin >> temp->os;
temp->nxt = NULL;
// Set up link to this node
if (start_ptr == NULL)
{ start_ptr = temp;
current = start_ptr;
}
else
{ temp2 = start_ptr;
// We know this is not NULL - list not empty!
while (temp2->nxt != NULL)
{ temp2 = temp2->nxt;
// Move to next link in chain
}
temp2->nxt = temp;
}
}
void Networknode::display_list()
{ node *temp;
temp = start_ptr;
cout << endl;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{ while (temp != NULL)
{ // Display details for what temp points to
cout << "ID : " << temp->idnum << " ";
cout << "IP : " << temp->ipad << " ";
cout << "OS : " << temp->os;
if (temp == current)
cout << " <-- Current node";
cout << endl;
temp = temp->nxt;
}
cout << "End of list!" << endl;
}
}
netowork.h
#ifndef NETWORK
#define NETWORK
#include <iostream>
#include "Networknode.h"
using namespace std;
class Network{
public:
void display_list();
void delete_start_node();
void delete_end_node();
void move_current_on ();
void move_current_back ();
}
#endif
[/cpde]
netork.cpp
[code]
#include <iostream>
#include "Network.h"
#include "Networknode.h"
using namespace std;
struct node
{ char idnum[20];
char ipad[20];
char os[20];
node *nxt;
};
node *start_ptr = NULL;
node *current;
int option = 0;
void Network::delete_start_node()
{ node *temp;
temp = start_ptr;
start_ptr = start_ptr->nxt;
delete temp;
}
void Network::delete_end_node()
{ node *temp1, *temp2;
if (start_ptr == NULL)
cout << "The list is empty!" << endl;
else
{ temp1 = start_ptr;
if (temp1->nxt == NULL)
{ delete temp1;
start_ptr = NULL;
}
else
{ while (temp1->nxt != NULL)
{ temp2 = temp1;
temp1 = temp1->nxt;
}
delete temp1;
temp2->nxt = NULL;
}
}
}
void Network::move_current_on ()
{ if (current->nxt == NULL)
cout << "You are at the end of the list." << endl;
else
current = current->nxt;
}
void Network::move_current_back ()
{ if (current == start_ptr)
cout << "You are at the start of the list" << endl;
else
{ node *previous; // Declare the pointer
previous = start_ptr;
while (previous->nxt != current)
{ previous = previous->nxt;
}
current = previous;
}
}
main program
#include <iostream>
#include "Network.h"
#include "Networknode.h"
void main();
struct node
{ char idnum[20];
char ipad[20];
char os[20];
node *nxt;
};
Networknode *start_ptr = NULL;
Networknode *current;
int option = 0;
{ start_ptr = NULL;
do
{
display_list();
cout << endl;
cout << "Please select an option : " << endl;
cout << "0. Exit the program." << endl;
cout << "1. Add a node to the end of the list." << endl;
cout << "2. Delete the start node from the list." << endl;
cout << "3. Delete the end node from the list." << endl;
cout << "4. Move the current pointer on one node." << endl;
cout << "5. Move the current pointer back one node." << endl;
cout << endl << " >> ";
cin >> option;
switch (option)
{
case 1 : add_node_at_end(); break;
case 2 : delete_start_node(); break;
case 3 : delete_end_node(); break;
case 4 : move_current_on(); break;
case 5 : move_current_back();
}
}
while (option != 0);
}
any help would be much preciated, please help it do by midnight tommorow
EDIT: Title edited to be more descriptive
PsychoCoder

New Topic/Question
Reply



MultiQuote





|