Question: I need a C + + programming code to do the following. - Open the input file called log.txt read it and store the

I need a C++ programming code to do the following.
-Open the input file called "log.txt" read it and store the data in a doubly linked list (created dynamically)(log.pdf file format).
-Sort the information by IP to perform the searches (BE CAREFUL with two and three digit numbers, numeric order not alphabetical).
If there are two or more accesses from the same IP address, the second sorting criterion is the date and time of access.
In case there is another tie, the third criterion is the error message.
-Ask the user for the start and end IPs of the information search. (the input is like a string, first one, and then another )
-Display the records corresponding to those IPs, in the standard output, in descending order, by IP (second criterion is the date and time, first those of Dec, Nov, Oct, Sept).
-Store the result of sorting in ascending order by IP in a file called SortedData.txt (second criterion is the date June, July, August, Sept, Oct, ...) same sorting criteria.
Example of input:
10.50.65.123
10.50.66.0
I already have my log file, and I have worked on this code
#include
#include
#include
#include
using namespace std;
int convmes(const string& mes){
if (mes == "Jan")
return 1;
if (mes == "Feb")
return 2;
if (mes == "Mar")
return 3;
if (mes == "Apr")
return 4;
if (mes == "May")
return 5;
if (mes == "Jun")
return 6;
if (mes == "Jul")
return 7;
if (mes == "Aug")
return 8;
if (mes == "Sep")
return 9;
if (mes == "Oct")
return 10;
if (mes == "Nov")
return 11;
if (mes == "Dec")
return 12;
return -1;
}
class Mes {
public:
string mes;
Mes(string mes) : mes(mes){}
int convmes() const {
return :: convmes(mes);
}
};
class Dia {
public:
int dia;
Dia(int dia) : dia(dia){}
};
class Hora {
public:
string hora;
Hora(string hora) : hora(hora){}
};
class Ip {
public:
string ip;
Ip(string ip) : ip(ip){}
};
class Mensaje {
public:
string mensaje;
Mensaje(string mensaje) : mensaje(mensaje){}
};
class Datos {
public:
Mes mes;
Dia dia;
Hora hora;
Ip ip;
Mensaje mensaje;
Datos(string mes, int dia, string hora, string ip, string mensaje)
: mes(mes), dia(dia), hora(hora), ip(ip), mensaje(mensaje){}
};
struct Node {
Datos data;
Node* prev;
Node* next;
Node(Datos data) : data(data){}
};
void inserta(Node** pth, Node** ptt, Datos dat){
Node* neww = new Node(dat);
neww->data = dat;
if (*pth == nullptr){
*pth = neww;
*ptt = neww;
} else {
neww->prev =*ptt;
(*ptt)->next = neww;
*ptt = neww;
}
}
void imprime( Node* ptt){
for (Node* poi = ptt; poi != nullptr; poi = poi->prev){
cout << poi->data.mes.mes <<""<< poi->data.dia.dia <<""<< poi->data.hora.hora <<""<< poi->data.ip.ip <<""<< poi->data.mensaje.mensaje << endl;
}
}
int main(){
ifstream file;
file.open("bitacora.txt");
if (!file.is_open()){
cout << "Error al abrir el archivo." << endl;
return 0;
} else {
string line;
Node* head = nullptr;
Node* tail = nullptr;
while (getline(file, line)){
stringstream ss(line);
string mes;
string hora;
string ip;
string mensaje;
int dia;
ss >> mes >> dia >> hora >> ip;
getline(ss, mensaje);
mensaje = mensaje.substr(1);
inserta(&head, &tail, Datos(mes, dia, hora, ip, mensaje));
imprime(tail);
}
file.close();
}
}
Help me complete what I need to do to comply with what is indicated
NOTE: VECTORS SHOULD NOT BE USED

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!