Need Help Code Posted Main Cpp File Want Output Like Correct Output See Maincpp Altered Ev Q43905359
Need help with my code. I have posted my main and cpp file. Iwant my output to be like the correct output(see below) Main.cpp isnot to be altered. only event.cpp should be modified.
This is my output:
Command Line:
1: ws
2: monday.txt
3: tuesday.txt
——————–
Day 1
——————–
1. 00:02:55 -> Computer Starting
2. 00:02:55 -> Computer Starting
3. [ No Event ]
4. 01:15:34 -> User logging in
5. 01:20:09 -> User logging in
6. [ No Event ]
7. [ No Event ]
——————–
Day 2
——————–
8. [ No Event ]
9. [ No Event ]
10. 01:20:34 -> User take a break
11. 01:22:30 -> User plays sudoku
12. [ No Event ]
——————–
Archive
——————–
13. [ No Event ]
14. 01:20:00 -> User logging in
15. [ No Event ]
16. [ No Event ]
17. [ No Event ]
18. [ No Event ]
19. [ No Event ]
20. [ No Event ]
21. [ No Event ]
——————–
*** Error in `ws’: double free or corruption (fasttop):0x0000000001a16310 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x81609)[0x7f716d27c609]
ws[0x4012c3]
ws[0x401736]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f716d21d495]
ws[0x400ec9]
======= Memory map: ========
00400000-00402000 r-xp 00000000 00:28 1077143745/home/mmaahi/ws
00601000-00602000 r–p 00001000 00:28 1077143745/home/mmaahi/ws
00602000-00603000 rw-p 00002000 00:28 1077143745/home/mmaahi/ws
01a14000-01a35000 rw-p 00000000 00:00 0 [heap]
7f7168000000-7f7168021000 rw-p 00000000 00:00 0
7f7168021000-7f716c000000 —p 00000000 00:00 0
7f716d1fb000-7f716d3bd000 r-xp 00000000 fd:00 674/usr/lib64/libc-2.17.so
7f716d3bd000-7f716d5bd000 —p 001c2000 fd:00 674/usr/lib64/libc-2.17.so
7f716d5bd000-7f716d5c1000 r–p 001c2000 fd:00 674/usr/lib64/libc-2.17.so
7f716d5c1000-7f716d5c3000 rw-p 001c6000 fd:00 674/usr/lib64/libc-2.17.so
7f716d5c3000-7f716d5c8000 rw-p 00000000 00:00 0
7f716d5c8000-7f716d5dd000 r-xp 00000000 fd:00 31805/usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f716d5dd000-7f716d7dc000 —p 00015000 fd:00 31805/usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f716d7dc000-7f716d7dd000 r–p 00014000 fd:00 31805/usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f716d7dd000-7f716d7de000 rw-p 00015000 fd:00 31805/usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f716d7de000-7f716d8df000 r-xp 00000000 fd:00 682/usr/lib64/libm-2.17.so
7f716d8df000-7f716dade000 —p 00101000 fd:00 682/usr/lib64/libm-2.17.so
7f716dade000-7f716dadf000 r–p 00100000 fd:00 682/usr/lib64/libm-2.17.so
7f716dadf000-7f716dae0000 rw-p 00101000 fd:00 682/usr/lib64/libm-2.17.so
7f716dae0000-7f716dbc9000 r-xp 00000000 fd:00 33767/usr/lib64/libstdc++.so.6.0.19
7f716dbc9000-7f716ddc8000 —p 000e9000 fd:00 33767/usr/lib64/libstdc++.so.6.0.19
7f716ddc8000-7f716ddd0000 r–p 000e8000 fd:00 33767/usr/lib64/libstdc++.so.6.0.19
7f716ddd0000-7f716ddd2000 rw-p 000f0000 fd:00 33767/usr/lib64/libstdc++.so.6.0.19
7f716ddd2000-7f716dde7000 rw-p 00000000 00:00 0
7f716dde7000-7f716de09000 r-xp 00000000 fd:00 667/usr/lib64/ld-2.17.so
7f716dfef000-7f716dff4000 rw-p 00000000 00:00 0
7f716e005000-7f716e008000 rw-p 00000000 00:00 0
7f716e008000-7f716e009000 r–p 00021000 fd:00 667/usr/lib64/ld-2.17.so
7f716e009000-7f716e00a000 rw-p 00022000 fd:00 667/usr/lib64/ld-2.17.so
7f716e00a000-7f716e00b000 rw-p 00000000 00:00 0
7fffd3449000-7fffd346a000 rw-p 00000000 00:00 0 [stack]
7fffd352b000-7fffd352d000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0[vsyscall]
Script done on Sat 18 Jan 2020 03:39:09 PM EST
This is the correct output:
Command Line:
1: ws
2: monday.txt
3: tuesday.txt
——————–
Day 1
——————–
1. 00:02:55 -> Computer Starting
2. 00:02:55 -> Computer Starting
3. [ No Event ]
4. 01:15:34 -> User logging in
5. 01:20:09 -> User logging in
6. 09:01:04 -> Browser closed
7. 17:33:33 -> User checks email
——————–
Day 2
——————–
8. 01:02:23 -> User starts working on homework
9. [ No Event ]
10. 01:20:34 -> User take a break
11. 01:22:30 -> User plays sudoku
12. 01:26:40 -> User resumes homework
Archive
——————–
13. [ No Event ]
14. 01:20:00 -> Authentication Failed
15. 01:23:20 -> Browser starts
16. 09:01:04 -> Browser closed
17. 17:33:33 -> User checks email
18. 01:02:23 -> User starts working on homework
19. 01:22:30 -> User plays sudoku
20. [ No Event ]
21. 01:26:40 -> User resumes homework
//EVENT.CPP
unsigned int g_sysClock = 0;
namespacesdds
{
//constructor
Event::Event() {
secMidnight = 0;
description=nullptr;
}
void Event::display() {
static int counter = 1;
int hour = 0;
int min = 0;
int sec = 0;
hour = secMidnight /3600;
min = (secMidnight – (hour *3600)) / 60;
sec = (secMidnight – (hour *3600) – (min * 60));
cout << setw(3)<< setfill(‘ ‘) << counter++ << “. “;
if ( description!=nullptr&& description[0] != ‘ ‘) {
cout<< setw(2) << setfill(‘0’) << hour << “:”<< setw(2) << setfill(‘0’) << min << “:”<< setw(2) << setfill(‘0’) << sec << “-> ” << description << endl;
// cout <<“[ No Event ]” << endl;
}
else {
cout<< “[ No Event ]” << endl;
}
void Event::setDescription(const char *src){
if (src != nullptr &&src[0]!=’ ‘) {
description = new char[strlen(src)+1];
strcpy(description, src);
secMidnight = g_sysClock;
}
else {
description = nullptr;
}
}
Event::~Event() {
delete[] description;
}
main.cpp
int main(int argc, char** argv) {
std::cout << “Command Line:n”;
for (int i = 0; i < argc; ++i) {
std::cout << i+1 <<“: ” << argv[i] << “n”;
}
std::cout << std::endl
sdds::Event archive[10];
size_t idxArchive = 0;
sdds::Event currentEvent;
const size_t secInDay = 60u * 60u * 24u;
for (auto day = 1; day < argc; ++day)
{
// each parameter for anapplication contains the events from one day
// process each one
std::cout <<“——————–n”;
std::cout << ” Day ” <<day << ‘n’;
std::cout <<“——————–n”;
std::ifstream in(argv[day]);
char opcode = ‘ ‘;
size_t time = secInDay + 1;
in >> opcode >>time;
// starting at midnight, untilthe end of the day
for (::g_sysClock = 0u;::g_sysClock < secInDay; ::g_sysClock++)
{
// what shouldhappen this second
while (time ==::g_sysClock)
{
// skip the delimiter
in.ignore();
// read the next opcode
in >> opcode;
// end of the file
if (in.fail())
break;
// handle the operation code
switch (opcode)
{
case ‘T’: // a new time code, this is exit thewhile loop
in >> time;
break;
case ‘S’: // start a new event, the old event isautomatically finished
char buffer[1024];
in.get(buffer, 1024,’,’);
currentEvent.setDescription(buffer);
break;
case ‘E’: // end the current event
currentEvent.setDescription(nullptr);
break;
case ‘P’: // print to scren the informationabout the current event
currentEvent.display();
break;
case ‘A’: // add a copy of the current event tothe archive
sdds::Eventcopy(currentEvent);
archive[idxArchive++] =copy;
break;
}
}
}
}
std::cout << “——————–n”;
std::cout << ” Archiven”;
std::cout << “——————–n”;
for (auto i = 0u; i < idxArchive; ++i)
archive[i].display();
std::cout << “——————–n”;
}
Expert Answer
Answer to Need help with my code. I have posted my main and cpp file. I want my output to be like the correct output(see below) Ma…
OR