Derwin
Starter
Ex-GM
Posts: 2,832
|
Post by Derwin on Mar 11, 2009 1:28:15 GMT -5
Spencer and Jonah are the new Andrew/Habes combination.
|
|
|
Post by Spencer on Mar 11, 2009 1:28:17 GMT -5
I want Ashes to get to 1000. And Play to get to 3000. I'll get it done. YEE! Are you at work?
|
|
|
Post by Sheryl Yoast on Mar 11, 2009 1:28:26 GMT -5
Guys I sent Galo's sister a friend request on Facebook. Don't tell him though.
|
|
|
Post by GP on Mar 11, 2009 1:29:10 GMT -5
I keep feeling like I need to go outside and get fresh air so I dont pass out. lmao
|
|
|
Post by Funky George! on Mar 11, 2009 1:29:10 GMT -5
i love spence
|
|
|
Post by Spencer on Mar 11, 2009 1:29:12 GMT -5
Do you ever just want to make copies of every key that you need to make for yourself so you can bring a chick home and then freak her out by saying, "Ya, those 1000 keys are the keys of my ex girlfriends. Before I killed them"
|
|
|
Post by Spencer on Mar 11, 2009 1:29:27 GMT -5
Guys I sent Galo's sister a friend request on Facebook. Don't tell him though. I wont.
|
|
Play
All-Star
Los Angeles Clippers
Posts: 5,702
|
Post by Play on Mar 11, 2009 1:29:36 GMT -5
I think UOSLR is pretty sick. Right now, it's doing excellent. have my team ready by 96
|
|
|
Post by Spencer on Mar 11, 2009 1:29:44 GMT -5
i love spence WTF is with the sad face
|
|
Ducky
All-Star
Ex-GM
Posts: 7,215
|
Post by Ducky on Mar 11, 2009 1:29:51 GMT -5
Right now, it's doing excellent. have my team ready by 96 The Kings will be ready.
|
|
|
Post by Apollo on Mar 11, 2009 1:29:53 GMT -5
lol
|
|
Play
All-Star
Los Angeles Clippers
Posts: 5,702
|
Post by Play on Mar 11, 2009 1:29:59 GMT -5
always at work
|
|
|
Post by Spencer on Mar 11, 2009 1:30:06 GMT -5
Right now, it's doing excellent. have my team ready by 96 My team sucks.
|
|
Ducky
All-Star
Ex-GM
Posts: 7,215
|
Post by Ducky on Mar 11, 2009 1:30:20 GMT -5
Spencer and Jonah are the new Andrew/Habes combination. Wizzam!
|
|
Play
All-Star
Los Angeles Clippers
Posts: 5,702
|
Post by Play on Mar 11, 2009 1:30:23 GMT -5
Jacquez Mercier was a sick pick. Marcus Bigelow was a sick pick.
|
|
|
Post by Spencer on Mar 11, 2009 1:30:31 GMT -5
Play, I have your 97 1st. Bend over sugar.
|
|
|
Post by Funky George! on Mar 11, 2009 1:31:04 GMT -5
i love spence WTF is with the sad face i dunno. saw a sick concert tonight. how are you?
|
|
|
Post by Spencer on Mar 11, 2009 1:31:14 GMT -5
Spencer and Jonah are the new Andrew/Habes combination. Wizzam! Ducky is gonna run my BBS team for me?
|
|
|
Post by Sheryl Yoast on Mar 11, 2009 1:31:26 GMT -5
I JUSSSS WANNNA KNOW WHERE DA GOLD AT!
|
|
Play
All-Star
Los Angeles Clippers
Posts: 5,702
|
Post by Play on Mar 11, 2009 1:31:26 GMT -5
Eb's bitch>>>all other sig bitches.
|
|
|
Post by Spencer on Mar 11, 2009 1:31:33 GMT -5
i dunno. saw a sick concert tonight. how are you? Jonas Brothers?
|
|
Ducky
All-Star
Ex-GM
Posts: 7,215
|
Post by Ducky on Mar 11, 2009 1:31:33 GMT -5
#include "bst.h" #include <iostream> #include <iomanip> #include <fstream>
using namespace std;
/************************ private: node * head; treeNode * root; int size; ************************/
BST::BST():root(NULL), head(NULL), size(0) { } BST::BST(char * fileName):root(NULL), head(NULL), size(0) { ifstream infile; data currData; char vendorName[100]; char phoneNum[100]; char productType[100]; int eventNum = 0; char events[100];
infile.open(fileName); if(!infile) { cerr << "fail to open " << fileName << " for input!" << endl; exit(1); }
infile.get(vendorName, 100, ';'); while(!infile.eof()) { //read in the attributes of current record infile.ignore(100, ';'); infile.get(phoneNum, 100, ';'); infile.ignore(100, ';'); infile.get(productType, 100, ';'); infile.ignore(100, ';'); infile >> eventNum; infile.ignore(100, ';'); infile.get(events, 100, '\n'); infile.ignore(100, '\n'); //populate current data currData.setVendorName(vendorName); currData.setPhoneNum(phoneNum); currData.setProductType(productType); currData.setEventNum(eventNum); currData.setEvents(events);
cout << vendorName << endl; cout << phoneNum << endl; cout << productType << endl; cout << eventNum << endl; cout << events << endl << endl;
//add current data to the table add(currData);
//start reading in next record infile.get(vendorName, 100, ';'); } infile.close (); } BST::BST(const BST& aBST):size(aBST.size), root(NULL), head(NULL) { //copy the array of linked list int i; for(i = 0; i < size; i++) { //copy each linked list in the array if(aBST.head == NULL) head = NULL; else { //copy the first node in current chain head = new node(aBST.head->item);
//copy the rest of the chain node * srcNode = aBST.head->next; node * destNode = head; while(srcNode) { destNode->next = new node(srcNode->item); destNode = destNode->next; srcNode = srcNode->next; } destNode->next = NULL; } }
*this = aBST;
} BST::~BST() { destroyTree(root);
node * curr = head; while(head) { curr = head->next; delete head; head = curr; } } void BST::add(const data& aData) { data * ptrItem = new data; *ptrItem = aData; //make a deep copy addToTree(ptrItem); addToList(ptrItem); } bool BST::remove(char * name) { //removeFromTree(name); if(removeFromList(name)) return true; else return false; } bool BST::retrieve(char * key, data& aData)const { treeNode * curr = root;
char vendorName[100];
while(curr) { curr->item.getVendorName(vendorName); int temp = strcmp(vendorName, key); if(temp == 0) { aData = curr->item; return true; } else if(temp < 0) { curr = curr->right; } else { curr = curr->left; //return retrieve(root->left, key, aData); } } return false; } bool BST::retrieve(char * key, data * aData)const { // Purpose: Search for vendor(s) by type of product
int j = 0;
//search for the data in the chain (linked list) node * curr = head; data arrdata[50]; char productType[100]; while(curr) { curr->item.getProductType(productType); if(strcmp(key, productType) == 0) { // Stock exists, so return the data arrdata[j] = curr->item; cout << endl << arrdata[j] << endl; curr = curr->next; j++; } else curr = curr->next; } if(j > 0) return true; else return false; } void BST::displayByName()const { cout << "Data in the Tree: " << endl << endl; display(root); } void BST::displayByProductType()const { node * currVendor;
cout << "Data in the List: " << endl << endl;
for(currVendor = head; currVendor; currVendor = currVendor->next) { //we can use << on data object because we overload << in the data class cout << '\t' << currVendor->item << endl; } } void BST::writeOut(char * fileName)const { // Purpose: Writes Vendor list to output file
ofstream outfile;
outfile.open(fileName); if(!outfile) { cerr << "Failed to open file: " << fileName << endl; exit(1); }
node * curr; char vendorName[100]; char phoneNum[100]; char productType[100]; int eventNum = 0; char events[100]; for(curr = head; curr; curr = curr->next) { //we can use << on data object because we overload << in the data class curr->item.getVendorName(vendorName); curr->item.getPhoneNum(phoneNum); curr->item.getProductType(productType); curr->item.getEvents(events); outfile << vendorName << ';' << phoneNum << ';' << productType << ';' << curr->item.getEventNum() << ';' << events << '\n'; }
outfile.close(); } void BST::addToList(data * ptrItem) { // Purpose: inserts a new Vendor into the Vendor list
node * prev = NULL; node * curr = head; bool i = 1;
while(curr!=NULL) { prev = curr; curr = curr->next;
// Check to see if Vendor Name already exists if(curr && (curr->item == *ptrItem)) { cout << "Item already exists: Not "; i = 0; } }
if(i == 1) { while((curr!=NULL) && (ptrItem->compareItem(*ptrItem,curr->item)) < 0) { prev = curr; curr = curr->next; }
prev = NULL; curr = head;
// Traverse linked list to find the position to insert while(curr!=NULL && (curr->item < (*ptrItem))) { prev = curr; curr = curr->next; }
// Create a new node and insert the data node * newNode = new node(*ptrItem); newNode->next= NULL;
// Link the newNode into the linked list newNode->next = curr; if(prev == NULL) head = newNode; else prev->next = newNode; } } bool BST::removeFromList(char * key) { // Purpose: Remove specified vendor from vendor list
node * prev = NULL; node * curr = head; char vendorName[100]; //search for the data to be removed by vendor name while(curr) { curr->item.getVendorName(vendorName); if(strcmp(key, vendorName) == 0) { //find match and remove the node if(!prev) head = curr->next; else prev->next = curr->next;
curr->next = NULL; delete curr; return true; } else { prev = curr; curr = curr->next; } } return false; } void BST::addToTree(data * ptrItem) { insert(root, ptrItem); } void BST::insert(treeNode*& root, data * ptrItem) {
treeNode * curr = root;
if(curr && curr->item == *ptrItem) { cout << "" << endl; } else { if(!root) { root = new treeNode(*ptrItem); size++; } else if(ptrItem->compareItem(root->item, *ptrItem) == 1) { insert(root->left, ptrItem); } else { insert(root->right, ptrItem); } } } void BST::display(treeNode * root)const { if(root) { display(root->left); cout << '\t' << root->item << endl; display(root->right); } }
void BST::destroyTree(treeNode *& root) { if(root) { destroyTree(root->left); destroyTree(root->right); delete root; root = NULL; } }
#include "data.h" #include <iostream> #include <iomanip>
using namespace std;
/************************* private: char * vendorName; char * phoneNum; char * productType; int eventNum; char * events; *************************/
ostream& operator<<(ostream& outfile, const data& aData) { // Prints a Winery item to screen outfile << left << setw (25) << aData.vendorName << setw (15) << aData.phoneNum << setw (25) << aData.productType << setw (5) << aData.eventNum << setw (100) << aData.events; return outfile; } data::data():vendorName(NULL), phoneNum(NULL), productType(NULL), eventNum(0), events(NULL) {
} data::data(char * vendorName, char * phoneNum, char * productType, char * events): vendorName(NULL), phoneNum(NULL), productType(NULL), eventNum(0), events(NULL) { setVendorName(vendorName); setPhoneNum(phoneNum); setProductType(productType); setEventNum(eventNum); setEvents(events); } data::data(const data& aData):vendorName(NULL), phoneNum(NULL), productType(NULL), events(NULL) { setVendorName(aData.vendorName); setPhoneNum(aData.phoneNum); setProductType(aData.productType); setEventNum(aData.eventNum); setEvents(aData.events); } data::~data() { if(vendorName) delete [] vendorName; if(phoneNum) delete [] phoneNum; if(productType) delete [] productType; if(events) delete [] events; } const data& data::operator=(const data& aData) { //if it is a self copy, don't do anything if(this == &aData) return *this; //make current object *this a copy of the passed in aData else { setVendorName(aData.vendorName); setPhoneNum(aData.phoneNum); setProductType(aData.productType); setEventNum(aData.eventNum); setEvents(aData.events); return *this; } } /*int data::compareRating(data& d1, data& d2) { // Input: Two data objects used for comparison // Returns: -1 if 1st value is < // 0 if values are equal // 1 if 1st value is >
float Rating1 = d1.rating; float Rating2 = d2.rating;
if(Rating1 < Rating2) return -1; else if (Rating1 == Rating2) return 0; else return 1; // if Rating1 > Rating2 } int data::compareAcreage(data& d1, data& d2) { // Input: Two data objects used for comparison // Returns: -1 if 1st value is < // 0 if values are equal // 1 if 1st value is > int Acres1 = d1.acreage; int Acres2 = d2.acreage;
if(Acres1 < Acres2) return -1; else if (Acres1 == Acres2) return 0; else return 1; // if Acres1 > Acres2 } */
void data::setVendorName(char * vendorName) { //release the exisisting memory if there is any if(this->vendorName) delete [] (this->vendorName);
//set new vendor name this->vendorName = new char[strlen(vendorName)+1]; strcpy_s(this->vendorName, strlen(vendorName) + 1, vendorName); } void data::setPhoneNum(char * phoneNum) { //release the exisisting memory if there is any if(this->phoneNum) delete [] (this->phoneNum);
//set new phone number this->phoneNum = new char[strlen(phoneNum)+1]; strcpy_s(this->phoneNum, strlen(phoneNum) + 1, phoneNum); } void data::setProductType(char * productType) { //release the exisisting memory if there is any if(this->productType) delete [] this->productType;
//set new product type this->productType = new char[strlen(productType)+1]; strcpy_s(this->productType, strlen(productType) + 1, productType); } void data::setEventNum(int eventNum) { this->eventNum = eventNum; } void data::setEvents(char * events) { //release the exisisting memory if there is any if(this->events) delete [] this->events;
//set new events this->events = new char[strlen(events)+1]; strcpy_s(this->events, strlen(events) + 1, events); } void data::getVendorName(char * vendorName)const { strcpy_s(vendorName, strlen(this->vendorName) + 1, this->vendorName); } void data::getPhoneNum(char * phoneNum)const { strcpy_s(phoneNum, strlen(this->phoneNum) + 1, this->phoneNum); } void data::getProductType(char * productType)const { strcpy_s(productType, strlen(this->productType) + 1, this->productType); } int data::getEventNum(void)const { return eventNum; } void data::getEvents(char * events)const { strcpy_s(events, strlen(this->events) + 1,this->events); } int data::compareItem(data& d1, data& d2) { // Input: Two data objects used for comparison // Returns: -1 if 1st value is < // 0 if values are equal // 1 if 1st value is >
char Name1[100]; char Name2[100];
d1.getVendorName(Name1); d2.getVendorName(Name2);
if(strcmp(Name1,Name2) <= 0) return -1; else if (strcmp(Name2,Name1) == 0) return 0; else return 1; } bool operator<(const data& d1, const data& d2) { // Input: Two data objects to be compared // Output: true -> if 1st is < // false -> if 1st is >= char name1[100]; char name2[100];
d1.getProductType(name1); d2.getProductType(name2);
if(strcmp(name1, name2) < 0) return true; else return false; } bool operator==(const data& d1, const data& d2) { // Input: Two data objects names to be compared // Output: true -> if values are equal // false -> otherwise char name1[100]; char name2[100];
d1.getVendorName(name1); d2.getVendorName(name2);
if(strcmp(name1, name2) == 0) return true; else return false; }
//TO DO LIST: // BST = overloader // remove (tree)
// //This is the Vendor Database program //Written by: Jonah Brasseur //Date: January //Sources: Li Liang, Jeff Abramson //
#include <stdlib.h> #include <crtdbg.h> #include "data.h" #include "bst.h"
#include <iostream> #include <iomanip> #include <fstream> #include <cassert>
using namespace std;
void displayMenu(); char getCommand(); void executeCmd(char command, BST& vendors); void getVendor(data & adata); int getInt(char * prompt); float getFloat(char * prompt); void getString(char * prompt, char * input); void displayTree(const BST & vendors); void displayList(const BST & vendors);
const int MAX_LEN = 100;
int main() { char command = 'a'; char inputFileName[] = "vendor-input.txt"; char outputFileName[] = "vendor-output.txt"; BST vendors(inputFileName);
cout << "\nWelcome to CS 260 Vendor Management System! "<< endl; cout << "\nImplemented by: Jonah Brasseur" << endl; cout << "--------------------------------" << endl; displayMenu(); command = getCommand();
while(command != 'q') { executeCmd(command, vendors); displayMenu(); command = getCommand(); } vendors.writeOut(outputFileName); cout << "\nThank you ... exiting" << endl << endl; return 0; }
void displayMenu() { cout << "Vendor Management System -- select a command:"<< endl; cout << "\ta: add a vendor" << endl << "\tr: remove a vendor (by specifying the name)" << endl << "\ts: search for a vendor (by providing the name)" << endl << "\tp: search for a vendor (by providing product type)" << endl << "\td: display vendors (sorted by name)" << endl << "\tv: display vendors (sorted by product type)" << endl << "\tt: display internal tree diagram" << endl << "\tq: quit and save" << endl << "\tx: exit without saving" << endl << endl; }
char getCommand() { char cmd; cout << "Please enter your choice:"; cin >> cmd; cin.ignore(100, '\n'); return tolower(cmd); }
void executeCmd(char command, BST & vendors) { data adata; char key[MAX_LEN];
switch(command) { case 'a': getVendor(adata); vendors.add(adata); cout << "added to the database" << endl << endl; break; case 'r': getString("\nPlease enter the name of the winery you want to remove: ", key); if(vendors.remove(key)) cout << endl << key << " has been removed from the database" << endl << endl; else cout << endl << key << " does not exist in the database" << endl << endl; break; case 's': getString("\nPlease enter the name of the winery you want to search: ", key); if(vendors.retrieve(key, adata)) cout << endl << adata << endl << endl; else cout << endl << key << " does not exist in the database" << endl << endl; break; case 'p': getString("\nPlease enter the name of the winery you want to search: ", key); if(vendors.retrieve(key, &adata)) break; else cout << endl << key << " does not exist in the database" << endl << endl; break; case 'd': displayTree(vendors); break; case 'v': displayList(vendors); break; case 't': //display(vendors); break; case 'x': //abort(); break; default: cout << "illegal command!" << endl; break; } }
void getVendor(data & adata) { char vendorName[MAX_LEN]; char phoneNum[MAX_LEN]; char productType[MAX_LEN]; int eventNum; char events[MAX_LEN];
cout << "\nPlease enter information about the winery (type q to quit): " << endl; getString("\tVendor name: ", vendorName); if ((vendorName != "q") || (vendorName != "Q")) { getString("\tPhone number: ", phoneNum); getString("\tType of product: ", productType); eventNum = getInt("\tThe amount of events: "); getString("\tName(s) of events: ", events);
adata.setVendorName(vendorName); adata.setPhoneNum(phoneNum); adata.setProductType(productType); adata.setEventNum(eventNum); adata.setEvents(events); } }
int getInt(char * prompt) { int temp; cout << prompt; cin >> temp; while(!cin) { cin.clear(); cin.ignore(100, '\n'); cout << "Illegal input -- try again: "; cin >> temp; } cin.ignore(100, '\n'); return temp; }
float getFloat(char * prompt) { float temp; cout << prompt; cin >> temp; while(!cin) { cin.clear(); cin.ignore(100, '\n'); cout << "Illegal input -- try again: "; cin >> temp; } cin.ignore(100, '\n'); return temp; } void getString(char * prompt, char * input) { cout << prompt; cin.get(input, MAX_LEN, '\n'); cin.ignore(100, '\n'); } void displayTree(const BST & vendors) { vendors.displayByName(); } void displayList(const BST & vendors) { vendors.displayByProductType(); }
|
|
|
Post by Apollo on Mar 11, 2009 1:31:40 GMT -5
Jacquez Mercier was a sick pick. Marcus Bigelow was a sick pick. Yeah, but he was a lotto pick. Not a 24th Overall pick.
|
|
Ducky
All-Star
Ex-GM
Posts: 7,215
|
Post by Ducky on Mar 11, 2009 1:32:00 GMT -5
my program kicks ass.
|
|
Play
All-Star
Los Angeles Clippers
Posts: 5,702
|
Post by Play on Mar 11, 2009 1:32:02 GMT -5
lol they better have lotto picks.
|
|