Advertisement
jinglis

Bids Project

May 10th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. /*
  2.  * Name: James Inglis
  3.  * Project: Bids
  4.  * Course: CSI107 (Spring 2013)
  5.  * Date May 9, 2013
  6.  * Description: This program takes the bids and slogans,
  7.  * converts all bids to American dollars, and displays all bids
  8.  * and slogans with "<company>" replace by your company's name.
  9.  */
  10.  
  11. #include <iostream>
  12. #include <cstring>
  13. #include <string>
  14. #include <iomanip>
  15. using namespace std;
  16.  
  17. double convertEurosToDollars(double bid); // This function converts the Euros input
  18.                                           // to American dollars.
  19.  
  20. double findMinIndex(double vals[], int numVals); // This function finds the minimum bids and returns it.
  21.  
  22. int main()
  23. {
  24.     const string COMPANY = "Inglis Corp"; //
  25.     const int NUM_AGENCIES = 4; // The size of the array
  26.     double bids[NUM_AGENCIES], minIndex; // The storing of bids in array // minIndex is used for the return variable   
  27.     string slogans[NUM_AGENCIES]; // storing the slogans into an array
  28.     int i; // counting variable
  29.  
  30.     cout << "Enter bid (in Euros) and slogan for 4 agencies : " << endl; // outputting  
  31.  
  32.     for (i = 0; i < NUM_AGENCIES; i++) // going through each element
  33.     {
  34.         cin >> bids[i];
  35.         bids[i] = convertEurosToDollars(bids[i]); //
  36.         getline(cin, slogans[i]); // taking in the string after the whitespace
  37.  
  38.     }
  39.     double index; // This code finds "<company>" and replaces it with "Inglis Corp
  40.     int j;
  41.     for (j = 0; j < NUM_AGENCIES; j++)
  42.     {
  43.         index = slogans[j].find("<company>");
  44.         cout << index << endl;
  45.         slogans[j].replace(index, 9, COMPANY);
  46.     }
  47.     // The calling function to find the minimum bid
  48.     minIndex = findMinIndex(bids, NUM_AGENCIES);
  49.  
  50.     // Displaying the Bids and Slogans
  51.     cout << "Bids ($)" << "\t" << "Slogan" << endl;
  52.  
  53.     for (i = 0; i < NUM_AGENCIES; i++)
  54.     {
  55.         cout << fixed << setprecision(2) << bids[i] << "\t\t" << slogans[i] << endl;
  56.     }
  57.      // Displaying the slogans, depending on the bids
  58.     if (minIndex == bids[0])
  59.     {
  60.         cout << "Best bid:  $"  << minIndex << fixed << setprecision(2) << slogans[0];
  61.     }
  62.  
  63.     else if (minIndex == bids[1])
  64.     {
  65.         cout << "Best bid:  $"  << minIndex << fixed << setprecision(2) << slogans[1] << endl;
  66.     }
  67.     else if (minIndex == bids[2])
  68.     {
  69.         cout << "Best bid:  $"  << minIndex << fixed << setprecision(2) << slogans[2] << endl;
  70.     }
  71.     else if (minIndex == bids[3])
  72.     {
  73.         cout << "Best bid:  $"  << minIndex << fixed << setprecision(2) << slogans[3] << endl;
  74.     }
  75.     else
  76.         cout << "Best bid:  $"  << minIndex << fixed << setprecision(2) << slogans[4] << endl;
  77.  
  78.     return 0;
  79.  
  80. }
  81. // function definition to converting Euros to Dollars
  82. double convertEurosToDollars(double euroBid)
  83. {
  84.     const double US_DOLLARS = 1.31;
  85.     double converted;
  86.     // The assignment to convert euros to dollars
  87.     converted = euroBid * US_DOLLARS;
  88.  
  89.     return converted;
  90.  
  91. }
  92. // function definition to find the mimimum value
  93. double findMinIndex(double vals[], int numVals)
  94. {
  95.     double min;
  96.  
  97.     min = vals[0];
  98.  
  99.     for ( int i = 1; i < numVals; i++)
  100.     {
  101.         if (min >= vals[i])   // The statment for the minimum value
  102.         {
  103.             min = vals[i];
  104.         }
  105.         else if (min == vals[i]) // If minimum values are the same
  106.         {
  107.             return vals[i];
  108.         }
  109.  
  110.     }
  111.  
  112.     cout <<  "min" << min << endl;
  113.  
  114.     return min;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement