Created
April 2, 2013 23:51
-
-
Save anonymous/5297244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
* linkedlist.cpp - CSCI212 - Ass1 - Contains LinkedList class definition | |
* Anthony Burchell-Bailey - 4245490 - /4/2013 | |
**********************************************************************/ | |
#include <iostream> | |
#include <cstddef> | |
#include <string> | |
#include "linkedlist.h" | |
#include <iomanip> | |
using namespace std; | |
LinkedList::LinkedList() | |
{ | |
Head = NULL; | |
} | |
LinkedList::~LinkedList() | |
{ | |
while(Head != NULL) | |
{ | |
PNode curr = Head; | |
Head = Head->next; | |
delete curr; | |
} | |
} | |
void LinkedList::AddToTail(string newdata, int newdate, int newtim, float newsize) | |
{ | |
PNode tmp, curr; | |
// create a new customer and store the information | |
tmp = new node; | |
tmp->name = newdata; | |
tmp->file = 1; | |
tmp->ODate = newdate; | |
tmp->OTim = newtim; | |
tmp->NDate = newdate; | |
tmp->NTim = newtim; | |
tmp->Size = newsize; | |
tmp->next = NULL; | |
// add to the end of the list if the list is not empty | |
if (Head != NULL) | |
{ | |
curr = Head; | |
while(((*curr).name).compare(newdata) != 0) | |
{ | |
if(((*curr).name).compare(newdata) > 0) | |
{ | |
tmp->next = Head; | |
Head = tmp; | |
} | |
else | |
{ | |
while(((*curr).name).compare(newdata) < 0 && curr->next) | |
{ | |
curr = curr->next; | |
if((*curr).name.compare(newdata) == 0) | |
{ | |
break; | |
} | |
} | |
if(((*curr).name).compare(newdata) == 0) | |
{ | |
break; | |
} | |
tmp->next = curr->next; | |
curr->next = tmp; | |
} | |
break; | |
} | |
if(((*curr).name).compare(newdata) == 0) | |
{ | |
(*curr).file += 1; | |
(*curr).Size += newsize; | |
if((*curr).ODate < newdate) | |
{ | |
(*curr).ODate = newdate; | |
} | |
if((*curr).NDate > newdate) | |
{ | |
(*curr).NDate = newdate; | |
} | |
} | |
} | |
else | |
Head = tmp; | |
} | |
void LinkedList::Print()//prints list. eg 12 34 21 26 | |
{ | |
PNode ins = Head; | |
double tsize = 0; | |
string unit = "B"; | |
string Aname = "ALL"; | |
int afile = 0; | |
int aodate = ins->ODate; | |
int andate = ins->NDate; | |
int asize = 0; | |
while(ins) | |
{ | |
unit = "B"; | |
afile += ins->file; | |
asize += ins->Size; | |
tsize = ins->Size; | |
if(ins->ODate < aodate) | |
{ | |
aodate = ins->ODate; | |
} | |
if(ins->NDate > andate) | |
{ | |
andate = ins->NDate; | |
} | |
cout << ins->name << "\t" << ins->file << "\t"; | |
cout << ins->ODate << "\t" << ins->NDate << "\t"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "KB"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "MB"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "GB"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "TB"; | |
} | |
} | |
} | |
} | |
cout << setprecision(4) << tsize << unit << "\n"; | |
ins = ins->next; | |
} | |
tsize = asize; | |
unit = "B"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "KB"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "MB"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "GB"; | |
if(tsize > 9999) | |
{ | |
tsize = tsize / 1024; | |
unit = "TB"; | |
} | |
} | |
} | |
} | |
cout << endl; | |
cout << Aname << "\t" << afile << "\t" << aodate << "\t" << andate << "\t" << setprecision(4) << tsize << unit; | |
cout << endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
* linkedlist.h - CSCI212 - Ass1 - Contains LinkedList class declaration | |
* Anthony Burchell-Bailey - 4245490 - /4/2013 | |
**********************************************************************/ | |
#ifndef LIST_H_ | |
#define LIST_H_ | |
#include <cstddef> | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
class LinkedList | |
{ | |
public: | |
LinkedList(); // constructor | |
~LinkedList(); // destructor | |
void AddToTail(string, int, int, float); // previous add function | |
void Print();//prints list. eg 12 34 21 26 | |
private: | |
struct node; | |
typedef node *PNode; | |
struct node{ | |
string name; | |
PNode next; | |
int file; | |
int ODate; | |
int OTim; | |
int NDate; | |
int NTim; | |
float Size; | |
}; | |
PNode Head; | |
PNode Current; // Iterator pointer | |
}; | |
#endif | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
* main.cpp - CSCI212 - Ass1 - main() driver for displaying ls statistics | |
* Anthony Burchell-Bailey - 4245490 - /4/2013 | |
**********************************************************************/ | |
#include <iostream> | |
#include <string> | |
#include <cstdlib> | |
#include "linkedlist.h" | |
using namespace std; | |
void AddToTail(string newdata, int newdate, int newtim, float newsize); // previous add function | |
void Print();//prints list. eg 12 34 21 26 | |
int main() | |
{ | |
cout << "Welcome to ls counter\n"; | |
cout << "User\tFiles\tOldest\t\tLatest\t\tTotSize\n"; | |
LinkedList list; | |
string newdata = "ant", waste, time, hold; | |
int newdate = 19930517; | |
int newmon = 0; | |
int newday = 0; | |
int newyea = 0; | |
int newtim = 0; | |
char namebuffer[20], datetimebuffer[20], monthbuffer[20]; | |
float newsize = 20; | |
cin.ignore(256,'\n'); | |
while(!cin.eof()) | |
{ | |
static char linebuffer[255]; | |
cin.getline(linebuffer, 255, '\n'); | |
sscanf(linebuffer, "%*s %*d %s %*s %f %s %d %s", namebuffer, &newsize, monthbuffer, &newday, datetimebuffer); | |
newdata = string(namebuffer); | |
if(monthbuffer == "Jan") | |
{newmon = 100;} | |
if(monthbuffer == "Feb") | |
{newmon = 200;} | |
if(monthbuffer == "Mar") | |
{newmon = 300;} | |
if(monthbuffer == "Apr") | |
{newmon = 400;} | |
if(monthbuffer == "May") | |
{newmon = 500;} | |
if(monthbuffer == "Jun") | |
{newmon = 600;} | |
if(monthbuffer == "Jul") | |
{newmon = 700;} | |
if(monthbuffer == "Aug") | |
{newmon = 800;} | |
if(monthbuffer == "Sep") | |
{newmon = 900;} | |
if(monthbuffer == "Oct") | |
{newmon = 1000;} | |
if(monthbuffer == "Nov") | |
{newmon = 1100;} | |
if(monthbuffer == "Dec") | |
{newmon = 1200;} | |
if(datetimebuffer[2] == ':') | |
{ | |
time[0] = datetimebuffer[0]; | |
time[1] = datetimebuffer[1]; | |
time[2] = datetimebuffer[3]; | |
time[3] = datetimebuffer[4]; | |
newtim = atoi(time.c_str()); | |
newyea = 20130000; | |
} | |
else | |
{ | |
time[0] = datetimebuffer[0]; | |
time[1] = datetimebuffer[1]; | |
time[2] = datetimebuffer[2]; | |
time[3] = datetimebuffer[3]; | |
newyea = atoi(time.c_str()) * 10000; | |
newtim = 0; | |
} | |
newdate = newyea + newmon + newday; | |
cout << newdata << " " << newdate << " " << newtim << " " << newsize << endl; | |
list.AddToTail(newdata, newdate, newtim, newsize); | |
} | |
list.Print();//prints list | |
cout << "\nThanks for using ls counter\n"; | |
return(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment