Question: Read the input file log.txt . Create a hash table whose key is the network ( the first two numbers of the IP address

Read the input file "log.txt".
Create a hash table whose key is the network (the first two numbers of the IP address) and whose value is a summary of that network.
This summary must include the number of accesses, the number of connections (unique IPs) as well as the IPs of that domain ordered in ascending order NOT Adjusted to 3 digits.
The table size must be the largest prime number that is less than 65536.
If it happens that the table fills up and can no longer receive more data, send an error message "Table full, impossible to enter more data"
You must propose the hash function to use, and justify this in the code as a comment
Make a method that, given a network, returns the value associated with it, displaying the information in the way shown in the output examples
Your program receives as input a number N , followed by N domains
The output is for each domain, the domain summary
This is my code, help me fulfill what is requested
#include iostream
#include fstream
#include sstream
#include vector
using namespace std;
struct Log {
string month, hour, message;
int day, port, network1, network2, host1, host2;
Log(string month, int day, string hour, int network1, int network2, int host1, int host2, int port, string message) :
month(month), hour(hour), message(message), day(day), port(port), network1(network1), network2(network2), host1(host1), host2(host2){}
};
int convmonth(const string& month){
if (month == "Jan") return 1;
if (month == "Feb") return 2;
if (month == "Mar") return 3;
if (month == "Apr") return 4;
if (month == "May") return 5;
if (month == "Jun") return 6;
if (month == "Jul") return 7;
if (month == "Aug") return 8;
if (month == "Sep") return 9;
if (month == "Oct") return 10;
if (month == "Nov") return 11;
if (month == "Dec") return 12;
return -1;
} struct NetworkNode { string network;
vector>> hosts;
};
class Graph { vector networks;
NetworkNode* searchNetwork(const string& red_key){ for (self& red : networks) if (red.red == red_key) return &red;
return nullptr;
} vector* searchHost(NetworkNode* networkNode, const string& host_key){ for (self& host : networkNode->hosts) if (host.first == host_key) return &host.second;
return nullptr;
} bool recordExists(const vector& records, const Record& reg){ for (const auto& r : records){ if (r.day == reg.day && r.month == reg.month && r.time == reg.time && r.port == reg.port && r.message == reg.message) return true;
} return false;
} public: void insert(Registry& reg){ string red_key = to_string(reg.red1)+"."+ to_string(reg.net2);
string host_key = to_string(reg.host1)+"."+ to_string(reg.host2);
NetworkNode* networkNode = networksearch(red_key);
if (!rednode){ networks.push_back({red_key});
networknode = &networks.back();
} self* host = searchHost(networknode, host_key);
if (!host){ networknode->hosts.push_back({host_key, {}});
host = &networknode->hosts.back().second;
} if (!registrationExists(*host, reg)) host->push_back(reg);
} void networkswithhighestoutdegree(){ int max_degree =0;
for (self& network : networks){ int degree =0;
for (self& host : red.hosts) degree += host.second.size();
max_degree =(degree > max_degree)? degree : max_degree;
} for (self& network : networks){ int degree =0;
for (self& host : red.hosts) degree += host.second.size();
if (degree == max_degree) cout << red.red << endl;
}} void iphavingmostaccess(){ int max_access =0;
string max_ip;
for (self& network : networks){ for (self& host : network.hosts){ int access = host.second.size();
if (access > max_access){ max_access = access;
max_ip = network.net +"."+ host.first;
}}} cout << max_ip << endl;
}};
int main(){ ifstream file("b3.txt");
if (!file.is_open()){ cout << "Error opening file." << endl;
return 0;
} string line;
Graph graph;
while (getline(file, line)){ stringstream ss(line);
string month, time, message, ip;
int day, port, network1, network2, host1, host2;
ss >> month >> day >> hour >> ip;
getline(ss, message);
message = message.substr(1);
stringstream ipstr(ip);
string inpt;
getline(ipstr, inpt, '.'); red1= stoi(inpt);
getline(ipstr, inpt, '.'); red2= stoi(inpt);
getline(ipstr, inpt, '.'); host1= stoi(inpt);
getline(ipstr, inpt, ':'); host2= stoi(inpt);
port = stoi(inpt);
Register reg(month, day, time, network1, network2, host1, host2, port, message);
graph.insert(reg);
} file.close();
graph.networkswithhighestoutdegree();
cout << endl;
graph.ipthathasmostaccess();
return 0;
}
NOTE: Use the same libraries, it is forbidden to change or add any other

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!