Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 2-1 Up to Speed Requirement Details The focus of these problems will be working with information extracted from a municipal government data feed containing

Lab 2-1 Up to Speed Requirement Details

The focus of these problems will be working with information extracted from a

municipal government data feed containing bids submitted for auction of property.

The data set is provided in two comma-separated files:

  1. eBid_Monthly_Sales.csv (larger set of 17,937 bids)
  2. eBid_Monthly_Sales_Dec_2016.csv (smaller set of 179 bids)

This assignment is designed to quickly get up to speed with the C++ language and the development environment you will be using throughout this course. We will build a simple console program that uses a menu to enable testing of the logic you will complete. In this version the following menu is presented when the program is run:

Menu:

1. Enter a Bid

2. Load Bids

3. Display All Bids

9. Exit

Enter choice:

The Lab2-1.cpp program is partially completed - it contains token placeholders such as:

  • ?type?
  • ?variable?
  • ?retval? (return value)

Replace these tokens with appropriate C++ identifiers so that the program will compile and run correctly.

Setup: Begin by creating a new C++ Project with a Project Type of "Hello World C++ Project".

  1. Name the project Lab2-1, remember to pick the correct compiler in Toolchains and click Finish. This will create a simple Lab2-1.cpp source file under the /src directory.
  2. Download the lab files and copy them to the following directories:
  1. /Lab2-1
    1. eBid_Monthly_Sales (.csv file)
    2. eBid_Monthly_Sales_Dec_2016 (.csv file)
  2. /src
    1. Lab 2-1.cpp (replacing the existing auto-generated one)
    2. CSVparser.cpp
    3. CSVparser.hpp

Remember to right-click on the project in the Project Explorer pane on the left and 'Refresh' the project so it adds all the new files to the correct folder underneath.

  1. Because this activity uses C++ 11 features you must follow the instructions under C++ Compiler Version in the C++ Development Installation guide to add -std=c++11 compiler switch to the Miscellaneous settings.

Task 1: Reference the CSVParser library

In order to use the CSVParser library functionality in your program you must declare it (or "bring in") those function definitions so they will be compiled into your executable program.

Task 2: Define a vector data structure to hold a collection of bids.

Task 3: Create a data structure and add to the collection of bids.

  1. Each bid read from the input file must be stored in a Bid structure and that structure added to the vector.

Task 4: Define a vector to hold all the bids.

  1. Within the main() method we need a vector defined to hold all the bids returned from the loadBids() method.

Task 5: Complete the method call to load the bids.

Task 6: Loop and display the bids read.

  1. Create a loop to iterate over every bid in the vector and pass each bid instance to the displayBid() method.
  2. Define a timer variable
  3. Initialize a timer variable before loading bids
  4. Calculate elapsed time and display result

Here is sample output from running the completed program to illustrate the separate activities:

Example Input

Choice: 2

Choice: 3

Choice: 9

Display

Menu:

1. Enter a Bid

2. Load Bids

3. Display All Bids

9. Exit

Enter choice: 2

Menu:

1. Enter a Bid

2. Load Bids

3. Display All Bids

9. Exit

Enter choice: 3

Menu:

1. Enter a Bid

2. Load Bids

3. Display All Bids

9. Exit

Enter choice: 9

Output

179 bids read

time: 2993 milliseconds

time: 2.993 seconds

Hoover Steam Vac | 27 | Enterprise

Table | 6 | General Fund

...

...

5 Chairs | 19 | General Fund

2 Chairs | 20 | General Fund

Chair | 71.88 | General Fund

Good bye.

#include #include #include

// FIXME (1): Reference the CSVParser library

using namespace std;

//============================================================================ // Global definitions visible to all methods and classes //============================================================================

// forward declarations double strToDouble(string str, char ch);

struct Bid { string title; string fund; double amount; Bid() { amount = 0.0; } };

//============================================================================ // Static methods used for testing //============================================================================

/** * Display the bid information * * @param bid struct containing the bid info */ void displayBid(Bid bid) { cout << bid.title << " | " << bid.amount << " | " << bid.fund << endl; return; }

/** * Prompt user for bid information * * @return Bid struct containing the bid info */ Bid getBid() { Bid bid;

cout << "Enter title: "; cin.ignore(); 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; }

/** * Load a CSV file containing bids into a container * * @param csvPath the path to the CSV file to load * @return a container holding all the bids read */ ?retval? loadBids(string csvPath) { // FIXME (2): Define a vector data structure to hold a collection of bids.

?type? ?variable?;

// initialize the CSV Parser using the given path csv::Parser file = csv::Parser(csvPath);

// loop to read rows of a CSV file for (int i = 0; i < file.rowCount(); i++) { // FIXME (3): create a data structure to hold data from each row and add to vector } return ?variable?; }

/** * Simple C function to convert a string to a double * after stripping out unwanted char * * * @param ch The character to strip out */ double strToDouble(string str, char ch) { str.erase(remove(str.begin(), str.end(), ch), str.end()); return atof(str.c_str()); }

/** * The one and only main() method */ int main(int argc, char* argv[]) {

// process command line arguments string csvPath; switch (argc) { case 2: csvPath = argv[1]; break; default: csvPath = "eBid_Monthly_Sales_Dec_2016.csv"; }

// FIXME (4): Define a vector to hold all the bids ?type? ?variable?;

// FIXME (7a): Define a timer variable ?type? ?variable?;

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 << " 9. Exit" << endl; cout << "Enter choice: "; cin >> choice;

switch (choice) { case 1: cout << "Not currently implemented." << endl;

break; case 2: // FIXME (7b): Initialize a timer variable before loading bids

// FIXME (5): Complete the method call to load the bids

// FIXME (7c): Calculate elapsed time and display result

break; case 3: // FIXME (6): Loop and display the bids read for (int i = 0; i < ?variable?.?length?; ++i) { displayBid(?variable?); } cout << endl;

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

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago

Question

How would we like to see ourselves?

Answered: 1 week ago