Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: James Inglis
- * Project: Bids
- * Course: CSI107 (Spring 2013)
- * Date May 9, 2013
- * Description: This program takes the bids and slogans,
- * converts all bids to American dollars, and displays all bids
- * and slogans with "<company>" replace by your company's name.
- */
- #include <iostream>
- #include <cstring>
- #include <string>
- #include <iomanip>
- using namespace std;
- double convertEurosToDollars(double bid); // This function converts the Euros input
- // to American dollars.
- double findMinIndex(double vals[], int numVals); // This function finds the minimum bids and returns it.
- int main()
- {
- const string COMPANY = "Inglis Corp"; //
- const int NUM_AGENCIES = 4; // The size of the array
- double bids[NUM_AGENCIES], minIndex; // The storing of bids in array // minIndex is used for the return variable
- string slogans[NUM_AGENCIES]; // storing the slogans into an array
- int i; // counting variable
- cout << "Enter bid (in Euros) and slogan for 4 agencies : " << endl; // outputting
- for (i = 0; i < NUM_AGENCIES; i++) // going through each element
- {
- cin >> bids[i];
- bids[i] = convertEurosToDollars(bids[i]); //
- getline(cin, slogans[i]); // taking in the string after the whitespace
- }
- double index; // This code finds "<company>" and replaces it with "Inglis Corp
- int j;
- for (j = 0; j < NUM_AGENCIES; j++)
- {
- index = slogans[j].find("<company>");
- cout << index << endl;
- slogans[j].replace(index, 9, COMPANY);
- }
- // The calling function to find the minimum bid
- minIndex = findMinIndex(bids, NUM_AGENCIES);
- // Displaying the Bids and Slogans
- cout << "Bids ($)" << "\t" << "Slogan" << endl;
- for (i = 0; i < NUM_AGENCIES; i++)
- {
- cout << fixed << setprecision(2) << bids[i] << "\t\t" << slogans[i] << endl;
- }
- // Displaying the slogans, depending on the bids
- if (minIndex == bids[0])
- {
- cout << "Best bid: $" << minIndex << fixed << setprecision(2) << slogans[0];
- }
- else if (minIndex == bids[1])
- {
- cout << "Best bid: $" << minIndex << fixed << setprecision(2) << slogans[1] << endl;
- }
- else if (minIndex == bids[2])
- {
- cout << "Best bid: $" << minIndex << fixed << setprecision(2) << slogans[2] << endl;
- }
- else if (minIndex == bids[3])
- {
- cout << "Best bid: $" << minIndex << fixed << setprecision(2) << slogans[3] << endl;
- }
- else
- cout << "Best bid: $" << minIndex << fixed << setprecision(2) << slogans[4] << endl;
- return 0;
- }
- // function definition to converting Euros to Dollars
- double convertEurosToDollars(double euroBid)
- {
- const double US_DOLLARS = 1.31;
- double converted;
- // The assignment to convert euros to dollars
- converted = euroBid * US_DOLLARS;
- return converted;
- }
- // function definition to find the mimimum value
- double findMinIndex(double vals[], int numVals)
- {
- double min;
- min = vals[0];
- for ( int i = 1; i < numVals; i++)
- {
- if (min >= vals[i]) // The statment for the minimum value
- {
- min = vals[i];
- }
- else if (min == vals[i]) // If minimum values are the same
- {
- return vals[i];
- }
- }
- cout << "min" << min << endl;
- return min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement