no it is not the case.. as the main are supplied by my lecturer..
can you correct it for me ???? the red section has an error tats why i just got half mark
my implementation code
Code:
#include "IPlist.h"
IPlist::IPlist()
// default constructor
// creates a new empty list
{
list = NULL;
}
IPlist::~IPlist()
// destructor - reallocates all dynamic memory of list
{
while(list != NULL)
{
node *tmp = list;
list = list-> link;
delete tmp; // release the memory pointed to by tmp
}
}
IPlist::IPlist (const IPlist & other)
// copy constructor to create a deep copy of other IPlist object
{
if(other.list == NULL)
list = NULL;
else
{
//copy the first node
node *current = other.list; // pointer to traverse the list
list = new node; // create the node
list->IPaddress = current->IPaddress; // copy the IPaddress
list->link = NULL; // set the link field of the node to NULL
current = current->link; // make current point to the next node
node *newNode = list; // pointer to create a node
// copy the remaining list
while(current != NULL)
{
newNode->link = new node; // create a node
newNode = newNode->link;
newNode->IPaddress = current->IPaddress;//copy the IPaddress
newNode->link = NULL; // set the link of newNode to NULL
current = current->link; // make current point to the next node
}
}
}
bool IPlist::empty() const
// precondition : none
// postcondition : returns true if list is empty
// and otherwise false
{
return list == NULL;
}
void IPlist::insertInOrder(string address)
// precondition : list is ordered and address is not in list
// postcondition : list is ordered and contains address
{
node *tmp = new node;
tmp->IPaddress = address;
tmp->count = 1;
tmp->link = NULL;
if(list == NULL || list->IPaddress > address) // if list is null or ipaddress in list is larger than address
{
tmp->link = list; // Insertion at
list = tmp; // the beginning
}
else
{
node *cur = list;
node *prev = NULL;
while(cur != NULL && cur->IPaddress < address)
{
prev = cur; // else insertion
cur = cur->link; // in the middle
}
prev->link = tmp; // otherwise insertion
tmp->link = cur; // at the end
}
}
bool IPlist::isPresent(string address) const
// precondition : none
// postcondition : returns true if a node containing address
// is present in list and otherwise false
{
node *current; // pointer to traverse the list
bool found = false;
current = list; // set current to point to the first node in the list
while(current != NULL && !found) // search the list
if(current->IPaddress == address) // search item is found
found = true;
else
current = current->link; // make current point to next node
return found;
}
void IPlist::updateCount(string address)
// precondition : address is in list
// postcondition : the count of node with address has been incremented
{
node *tmp = list; // tmp point to the first node of list
while( tmp->IPaddress != address) // if ipaddress is not address
tmp = tmp->link; // go to next node
tmp->count++; // increament count by 1
}
node * IPlist::find (string address) const
// precondition : none
// postcondition : returns a pointer to node containing address or
// NULL if not present
{
node *tmp;
for(tmp = list; tmp != NULL; tmp = tmp->link)
if(address == tmp->IPaddress)
return tmp;
}
void IPlist::display() const
// precondition : none
// postcondition : the list has been displayed
// one record per line, tab-separated
// with heading IPaddress Count
{
cout << "IP address" << '\t' << "Count" << endl;
node *curr = list;
while (curr != NULL)
{
cout << curr->IPaddress << '\t' << curr->count << endl; // display Ip Address and Count
curr = curr->link;
}
cout << endl;
}
and my main code
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
#include "IPlist.h"
int main()
{
IPlist ip;
string data[]={"a","b","c","a","b","c","a","d"};
// some strings to insert into IPlist for testing
// they don't really need to be IP addresses
for (int i = 0; i < 8; i++)
{
if (!ip.isPresent(data[i]))
ip.insertInOrder(data[i]);
else
ip.updateCount(data[i]);
}
ip.display();
cout << endl;
node *current = ip.find("d");
if (current != NULL)
cout << "found "<< current->IPaddress << endl;
system("pause");
return EXIT_SUCCESS;
}
Code:
From View message header detail Ros Ballantyne <[email protected]>
Sent Monday, October 30, 2006 7:13 pm
To [email protected]
Subject COMP125 Assignment 3 preview
=======================================
(spaces,tabs and newlines do not matter)
*******************************************
* FILE NAMES DO MATTER *
* *
* SAME preview (as last night) *
* BUT gives 2 marks for each test *
* and some marks for some correct output *
* and tells you if filenames are incorrect*
******************************************
CHECKING FILENAMES
Testing Application
Program compiled
There are 4 tests each worth 1 mark
====== Test 1 Data File contains ========
192.149.089.061
100.001.004.031
034.056.078.012
192.149.089.061
100.001.004.031
192.149.089.061
111.022.033.004
192.149.089.061
111.022.033.004
111.022.033.004
============================
====== Test 1 Batch input to program contains ========
data1.txt
============================
** Passed test 1
====== Test 2 Data File contains ========
111.022.033.004
111.022.033.004
111.022.033.004
111.022.033.004
111.022.033.004
111.022.033.004
111.022.033.004
111.022.033.004
111.022.033.004
111.022.033.004
============================
====== Test 2 Batch input to program contains ========
data2.txt
============================
** Passed test 2
====== Test 3 Data File contains ========
192.149.089.061
100.001.004.031
034.056.078.012
192.149.089.061
100.001.004.031
192.149.089.061
111.022.033.004
192.149.089.061
111.022.033.004
111.022.033.004
============================
====== Test 3 Batch input to program contains ========
error.txt
error2.txt
error.txt
data3.txt
============================
** Passed test 3
====== Test 4 Data File contains ========
============================
====== Test 4 Batch input to program contains ========
data4.txt
============================
** Passed test 4
Testing Linking With Other Main programs
There are 4 tests
=================Main 1 contains =====================
#include <iostream>
#include <cstdlib>
using namespace std;
#include "IPlist.h"
int main()
{
IPlist ip;
if (ip.empty())
cout << "empty" << endl;
system("pause");
return EXIT_SUCCESS;
}
=======================================================
Program compiled
** Passed test 1
=================Main 2 contains =====================
#include <iostream>
#include <cstdlib>
using namespace std;
#include "IPlist.h"
int main()
{
IPlist ip;
string data[]={"a","b","c","a","b","c","a","d"};
// some strings to insert into IPlist for testing
// they don't really need to be IP addresses
for (int i = 0; i < 8; i++)
{
if (!ip.isPresent(data[i]))
ip.insertInOrder(data[i]);
else
ip.updateCount(data[i]);
}
ip.display();
cout << endl;
node *current = ip.find("d");
if (current != NULL)
cout << "found "<< current->IPaddress << endl;
system("pause");
return EXIT_SUCCESS;
}
=======================================================
Program compiled
** Half marks for test 2
** sample output **
IP address Count
a 3
b 2
c 2
d 1
found d
** your output **
IP address Count
a 3
b 2
c 2
d 1
found d
=================Main 3 contains =====================
#include <iostream>
#include <cstdlib>
using namespace std;
#include "IPlist.h"
void testCopyConstructor(IPlist x);
int main()
{
IPlist ip;
string data[]={"a","b","c","a","b","c","a","d"};
// some strings to insert into IPlist for testing
// they don't really need to be IP addresses
for (int i = 0; i < 8; i++)
{
if (!ip.isPresent(data[i]))
ip.insertInOrder(data[i]);
else
ip.updateCount(data[i]);
}
ip.display();
testCopyConstructor(ip);
ip.display(); // should be same as before
system("pause");
return EXIT_SUCCESS;
}
void testCopyConstructor(IPlist x)
{
// copy constructor will be automatically called when pass by value
// if we have written a correct copy constructor to make a deep copy
// then changing x will not change the corresponding argument
// (in this case ip in the main program)
x.insertInOrder("w");
x.insertInOrder("x");
}
=======================================================
Program compiled
** Half marks for test 3
** sample output **
IP address Count
a 3
b 2
c 2
d 1
IP address Count
a 3
b 2
c 2
d 1
** your output **
IP address Count
a 3
b 2
c 2
d 1
IP address Count
a 3
b 2
c 2
d 1
=================Main 4 contains =====================
#include <iostream>
#include <cstdlib>
using namespace std;
#include "IPlist.h"
int main()
{
IPlist ip;
string data[]={"a","b","c","a","b","c","a","d","xx","zz"};
// some strings to insert into IPlist for testing
// they don't really need to be IP addresses
for (int i = 0; i < 8; i++)
{
if (!ip.isPresent(data[i]))
ip.insertInOrder(data[i]);
else
ip.updateCount(data[i]);
}
ip.display();
cout << endl;
if (ip.empty())
cout << "PROBLEMS " << endl;
node *current;
for (int i = 0; i < 10; i++)
{
current = ip.find(data[i]);
if (current != NULL)
cout << "found "<< current->IPaddress << endl;
else
cout << "Not found" << endl;
}
system("pause");
return EXIT_SUCCESS;
}
=======================================================
Program compiled
** Half marks for test 4
** sample output **
IP address Count
a 3
b 2
c 2
d 1
found a
found b
found c
found a
found b
found c
found a
found d
Not found
Not found
** your output **
IP address Count
a 3
b 2
c 2
d 1
found a
found b
found c
found a
found b
found c
found a
found d
Not found
Not found