Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I would like my output to match the correct output(see below). Can someone fix the code? main.cpp should not not be altered. only event.cpp should

I would like my output to match the correct output(see below). Can someone fix the code? main.cpp should not not 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;

namespace sdds { //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] != '\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]!='\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: "; for (int i = 0; i < argc; ++i) {

std::cout << i+1 << ": " << argv[i] << " ";

}

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 an application contains the events from one day // process each one std::cout << "-------------------- "; std::cout << " Day " << day << ' '; std::cout << "-------------------- "; std::ifstream in(argv[day]); char opcode = '\0'; size_t time = secInDay + 1; in >> opcode >> time;

// starting at midnight, until the end of the day for (::g_sysClock = 0u; ::g_sysClock < secInDay; ::g_sysClock++) { // what should happen 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 the while loop in >> time; break; case 'S': // start a new event, the old event is automatically 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 information about the current event currentEvent.display(); break; case 'A': // add a copy of the current event to the archive sdds::Event copy(currentEvent); archive[idxArchive++] = copy; break; } } } } std::cout << "-------------------- "; std::cout << " Archive "; std::cout << "-------------------- "; for (auto i = 0u; i < idxArchive; ++i) archive[i].display(); std::cout << "-------------------- "; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions

Question

=+3. What is the emotion? Love Appeal

Answered: 1 week ago