1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
struct Rate {
double revenue; // if the artist's revenue is this much
double multiplier; // then the agent's base rate is multiplied by this
};
// Compute an agent's earnings based on a rate table and the artist's
// revenue. The rate table entries must be in order of increasing
// revenue. The last Rate must have revenue==0 and the multiplier
// applies to all rates larger than the previous one.
double agentEarnings(double baseRate, double artistRevenue, Rate rates[])
{
size_t i;
for (i=0; rates[i].revenue; ++i) {
if (artistRevenue < rates[i].revenue) {
break;
}
}
double result = artistRevenue * (baseRate * rates[i].multiplier);
// cerr << result << '\n';
return result;
}
double getFilmRevenue(double baseRate, double artistRevenue)
{
static Rate rates[] = {
{1'500'000, 1.0 }, // no multiple up to 1,500,000
{0, 1.5 } // 1.5 multiple above 1,500,000
};
return agentEarnings(baseRate, artistRevenue, rates);
}
double getBookRevenue(double baseRate, double artistRevenue)
{
static Rate rates[] = {
{2'000, 0.5 }, // 0.5 multiple up to 2000
{6'000, 0.5 }, // no multiple up to 6000
{0, 1.5} // 1.5 multiple above 6000
};
return agentEarnings(baseRate, artistRevenue, rates);
}
double getMusicRevenue(double baseRate, double artistRevenue)
{
static Rate rates[] = {
{200'000, 1.0 }, // no multiple up to 200,000
{0, 2.0 } // 2x multiple above 200.000
};
return agentEarnings(baseRate, artistRevenue, rates);
}
int
main()
{
/// declare the variables
double standardFilmRate = 0.10;
double standardBookRate = 0.05;
double standardMusicRate = 0.15;
double revenue;
cout << setprecision(2) << fixed;
while (cin >> revenue) {
cout << " At $" << revenue << '\n';
cout << "\ta film agent earns $" << getFilmRevenue(standardFilmRate, revenue) << '\n';
cout << "\ta book agent earns $" << getBookRevenue(standardBookRate, revenue) << '\n';
cout << "\ta music agent earns $" << getMusicRevenue(standardMusicRate, revenue) << '\n';
cout << "\n\n";
}
}
| |