Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- using namespace std;
- //============================================================================
- // Global definitions visible to all methods and classes
- //============================================================================
- // FIXME (1): Define a data structure to hold bid information together as a single unit of storage.
- struct Info {
- char title;
- int fund;
- int vehicleID;
- int bidAmount;
- };
- // FIXME (4): Display the bid values passed in data structure
- /**
- * Display the bid information
- *
- * @param ?type? data structure containing the bid info
- */
- void displayBid(Info itemOne) {
- cout << "Title: " << itemOne.title << endl;
- cout << "Fund: " << itemOne.fund << endl;
- cout << "Vehicle: " << itemOne.vehicleID << endl;
- cout << "Bid Amount: " << itemOne.bidAmount << endl;
- return;
- }
- // FIXME (3): Store input values in data structure
- /**
- * Prompt user for bid information
- *
- * @return data structure containing the bid info
- */
- Info getBid() {
- Info itemOne;
- cout << "Enter title: ";
- cin.ignore();
- getline(cin, itemOne.title);
- cout << "Enter fund: ";
- cin >> itemOne.fund;
- cout << "Enter vehicle: ";
- cin.ignore();
- getline(cin, itemOne.vehicleID);
- cout << "Enter amount: ";
- cin.ignore();
- string strAmount;
- getline(cin, strAmount);
- itemOne.bidAmount = strToDouble(strAmount, '$');
- return;
- }
- /**
- * Simple C function to convert a string to a double
- * after stripping out unwanted char
- *
- * credit: http://stackoverflow.com/a/24875936
- *
- * @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() {
- // FIXME (2): Declare instance of data structure to hold bid information
- Info itemOne;
- // loop to display menu until exit chosen
- int choice = 0;
- while (choice != 9) {
- cout << "Menu:" << endl;
- cout << " 1. Enter Bid" << endl;
- cout << " 2. Display Bid" << endl;
- cout << " 9. Exit" << endl;
- cout << "Enter choice: ";
- cin >> choice;
- // FIXME (5): Complete the method calls then test the program
- switch (choice) {
- case 1:
- itemOne = getBid();
- break;
- case 2:
- displayBid(itemOne);
- break;
- }
- }
- cout << "Good bye." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement