Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have run out of time and have to stop working on this. I have completed the code for the assignment and it runs I

I have run out of time and have to stop working on this. I have completed the code for the assignment and it runs I just need either a pseudocode or flowchart for the below code.

double strToDouble(string str, char ch); struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; class LinkedList {

private:

struct Node { Bid _bid; Node* next; Node* tail; Node() { next = nullptr; }

Node(Bid bid) { _bid = bid; next = nullptr; } };

Node* head; Node * tail; int size = 0;

public: LinkedList(); virtual ~LinkedList(); void Append(Bid bid); void Prepend(Bid bid); void PrintList(); void Remove(string bidId); Bid Search(string bidId); int Size(); };

LinkedList::LinkedList() { head = nullptr; tail = nullptr; }

/** * Destructor */ LinkedList::~LinkedList() { }

void LinkedList::Append(Bid bid) { // FIXME (3): Implement append logic Node* node = new Node(bid); if(head == nullptr) { // If there is ever only an element head = node; } else { if(tail != nullptr) { // Set the next tail to be the current node tail->next = node; } } tail = node; size++; }

void LinkedList::Prepend(Bid bid) { Node* toPrepend = new Node(bid); if(head != nullptr) { // Make the next pointer of the Node to be prepend = head toPrepend->next = head; } head = toPrepend; size++; // increase the size }

void LinkedList::PrintList() { Node* currentNode = head; while(currentNode != nullptr) { cout << currentNode->_bid.bidId << ": " <_bid.title << " | " <_bid.fund << " | " <_bid.amount << " | " << endl; currentNode = currentNode -> next;

} }

void LinkedList::Remove(string bidId) { if(head != nullptr) { if(head->_bid.bidId == bidId) { Node* temp = head->next; delete head; head = temp; } }

Node* currentNode = head; while(currentNode->next != nullptr) { if(currentNode->next->_bid.bidId == bidId) { Node* currTmpNode = currentNode->next; currentNode->next = currTmpNode->next; delete currTmpNode; return; } currentNode = currentNode->next; }

}

Bid LinkedList::Search(string bidId) { Node* currentNode = head; while(currentNode != nullptr) { if(currentNode->_bid.bidId == bidId) { // if the currenNode holds the same bid id the simply return the bid return currentNode->_bid; } currentNode = currentNode -> next; } cout << "Not able to find the Bid with id : " <

int LinkedList::Size() { return size; }

void displayBid(Bid bid) { cout << bid.bidId << ": " << bid.title << " | " << bid.amount << " | " << bid.fund << endl; return; }

Bid getBid() { Bid bid;

cout << "Enter Id: "; cin.ignore(); getline(cin, bid.bidId);

cout << "Enter title: "; getline(cin, bid.title);

cout << "Enter fund: "; cin >> bid.fund;

cout << "Enter amount: "; cin.ignore(); string strAmount; getline(cin, strAmount); bid.amount = strToDouble(strAmount, '$');

return bid; }

void loadBids(string csvPath, LinkedList *list) { cout << "Loading CSV file " << csvPath << endl;

csv::Parser file = csv::Parser(csvPath);

try { for (int i = 0; i < file.rowCount(); i++) {

Bid bid; bid.bidId = file[i][1]; bid.title = file[i][0]; bid.fund = file[i][8]; bid.amount = strToDouble(file[i][4], '$');

//cout << bid.bidId << ": " << bid.title << " | " << bid.fund << " | " << bid.amount << endl;

// add this bid to the end list->Append(bid); } } catch (csv::Error &e) { std::cerr << e.what() << std::endl; } }

double strToDouble(string str, char ch) { str.erase(remove(str.begin(), str.end(), ch), str.end()); return atof(str.c_str()); }

int main(int argc, char* argv[]) {

string csvPath, bidKey; switch (argc) { case 2: csvPath = argv[1]; bidKey = "98109"; break; case 3: csvPath = argv[1]; bidKey = argv[2]; break; default: csvPath = "eBid_Monthly_Sales_Dec_2016.csv"; bidKey = "98109"; }

clock_t ticks;

LinkedList bidList;

Bid bid;

int choice = 0; while (choice != 9) { cout << "Menu:" << endl; cout << " 1. Enter a Bid" << endl; cout << " 2. Load Bids" << endl; cout << " 3. Display All Bids" << endl; cout << " 4. Find Bid" << endl; cout << " 5. Remove Bid" << endl; cout << " 9. Exit" << endl; cout << "Enter choice: "; cin >> choice;

switch (choice) { case 1: bid = getBid(); bidList.Append(bid); displayBid(bid);

break;

case 2: ticks = clock();

loadBids(csvPath, &bidList);

cout << bidList.Size() << " bids read" << endl;

ticks = clock() - ticks; // current clock ticks minus starting clock ticks cout << "time: " << ticks << " milliseconds" << endl; cout << "time: " << ticks * 1.0 / CLOCKS_PER_SEC << " seconds" << endl;

break;

case 3: bidList.PrintList();

break;

case 4: ticks = clock();

bid = bidList.Search(bidKey);

ticks = clock() - ticks; // current clock ticks minus starting clock ticks

if (!bid.bidId.empty()) { displayBid(bid); } else { cout << "Bid Id " << bidKey << " not found." << endl; }

cout << "time: " << ticks << " clock ticks" << endl; cout << "time: " << ticks * 1.0 / CLOCKS_PER_SEC << " seconds" << endl;

break;

case 5: bidList.Remove(bidKey);

break; } }

cout << "Good bye." << endl;

return 0; }

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions