Well I'm an electrical engineer. I should have done software engineering. Less maths, less project management, physics was cool and more programming would be what I'd have liked.
I love power though Tis very good. Maths isn't that difficult, once ya hit 3rd year, they show ya all the good formulas and tell ya to forget the previous 2 years of heavy maths! Done! Woot!
Originally posted by hburrows83
This is what i am studying, which has a lot of maths and of course a lot of engineering (software though)
Anyone wanna do my programming assignment for me???
Is that a 2nd year programming assignment?
Looks pretty easy.
Probably read it into a linked list, which will be sorted as you read it in Nice and Easy
Linked_List object should have following variables:
1) (optional) Boolean - End_Of_List (yes or no) which will indicate that this object is the last in the linked list.
2) Entry *Entry_object_ptr - pointer to an object which contains all the details that appear in a single log entry.
3) Linked_List *Previous_ptr - Points to the previous linked list entry
4) Linked_List *Next_ptr - Points to next previous linked list entry
The Boolean is optional as you can just check that next_ptr/previous_ptr == Null. But if you are a sloppy programmer (like most engineers tend to be) it's probably easier to check for that variable then always check that something = null. But you should Assert that the next ptr is not null before trying to access it, or you'll end up with a seg fault
You can probably also make the linked list single direction too and do away with the "previous" pointer. However, if for some reason they change specs and make you sort the list (ouch) then a doubly linked list will make life alot easier. wOOt!
Your Entry_object will require:
You can just use int's, or even short ints. Short ints should be faster. Unsigned means no negative numbers ever. Whatever you choose, JUST BE CONSISTENT. Also port number go up to 2^16, so make sure your chosen int type can handle 65536. Un signed short int can ->((2^16) -1).
unsigned int month = 0; (init) (1-12)
unsigned int day = 0; (init) (1 - 31)
unsigned int hour = 0; (init) (0-23)
unsigned int min = 0; (init) (0-59)
unsigned int sec = 0; (init) (0-59)
char *action; (6chars) *remember that this is just a ptr -> In C you may need to malloc for this. C++, u just say new char name[x] for x character array.
char *protocol; (3ish? check max length of protocol)
char *source_ip = " "; (12 chars)
char *dest_ip =" "; (12 chars)
unsigned int src_port = 0;
unsigned int dest_port = 0;
bool tcp_flags; (set each to false)
There ya go, that's a start.
1) Create a new Entry_object object
2) Read in from log file. Ensure that the first and last entries are not Null (ie that the log file contains data).
Save the srcip+dest_ports of the first and last entryentry (as a char [2,12] + int  ). (nice and easy )
Make sure you keep a counter that counts how many times the read algorithm tries to read in from the file, then decrement 1 cos it needs to detect "EOF"
3) Clear the console in buffer :- Get user input for the date (year month day) watch for buffer underflows/overflows. Use cin.get() to get a single char at a time. Slow, but ensure no buffer overruns
4) Check that the date is valid, if not, get system time.
5) Get the current year from the time you just got ^^.
6) Create a new file -> use the next pointers to access each entry in the linked list and then write each object to the output file in the correct way.
And hell no I'm not gonna do more
Keep in mind the limitations of the number of entries in the log file is limited by the type of int you use for the counter. Please use unsigned. I'm sure the marker will be impressed if they find a -ve entry count
Also remember that filereads will return the last line of text twice, as the second time the EOF flag is set, but the file input buffer will still contain the previous line. Remember to check for EOF correctly
Don't make the newbie mistake of not making a large enough buffer for user input. Users are dumb. If you ask them for 8 characters, make the buffer 1024 chars.
Don't make the newbie mistake of not making an actual character array before writing something to the char pointer
Make sure all pointer initially point to null
Make sure pointers don't == null before you access the object.
Don't confuse nul (character nothing) with null (pointer nothing).
Remember to delete all the memory dynamically allocated for char arrays, and all objects.