-
urgent help please...
please help really urgent..the red colour is the correct output whereas the blue display is my display which has a simple error. please give me advice or help me ....
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
//extra space
found d
Code:
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
}
}
the blue colour has extra space... wat problem cause tat please.... i think is my insertinorder problem....correct me if i am wrong
-
You posted a function which has nothing to do with the output because I see no functions that would output that blue text.
-
ok here is my implementation file ..
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 this is my main file
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;
}
-
Count number of times you use
in your programs
-
is there any other instead of changing anything in main/// cause tat main.cpp are supply by my lecturer
-
i show you the preview of the testing
-
this is the error but i couldnt wat is wrong with it ,...
Code:
=======================================
(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
-
You found 2 occurences of the code that puts an empty line, right?
If you cannot remove the code from the main function, you should... o! yes! Remove it from the second place.
-
do you mean in
bool IPlist::isPresent(string address) const
function???
can you find any error in the red code?
-
-
bumpy bumpy please it's urgent.
-
Start ONE new thread with your current question without using the word URGENT anywhere in the title or text content, and do NOT bump it with useless "anyone help please" phrases.