Help writing a program! PLEASE HELPPPPP

You have just gained an internship at a marketing agency. You have been asked to write an algorithm and a C++ program to calculate the revenue an agent will receive based on the earnings of all his clients (artists). There is a file containing the id of each client, along with his/her earning and type of medium that produces the revenue. The agent you are working for has set contract rules that specify his share depending on the medium (book/music/film) and the revenue earned by the artist. While the standard rates might change, the special rate changes that are based on the exact revenue, are relative to the standard rate.

Standard Film Rate 10%
If revenue > 1500000 1.5 * standard film rate

Standard Book Rate 5%
If revenue > 6000 1.5 * standard book rate
If revenue < 2000 .5 * standard book rate

Standard Music Rate 15% If
revenue> 200000 2*standard music rate


You are required to use three return type functions: GetBookRevenue, GetFilmRevenue, and GetMusicRevenue. These functions should return the agent’s share given the rate, and the earnings from a single client.

If the medium type, is not music, film, or book, then the agent will not receive a share. This is classified as ineligible revenue.

You must also print aggregate information: Total Agent Revenue, Total Agent Revenue from films, books, and music respectively, and Total ineligible revenue.


I GOT TO THE POINT WHERE I CREATED A DATA-STRUCT AND READ ALL THE INFORMATION FROM THE INPUT TEXT FILE; I JUST DON'T KNOW HOW TO CREATE THE 3 FUNCTIONS AND BE ABLE TO IDENTIFY THE TYPE AND CALCULATE BASED ON IT.
I'm currently doing the same assignment and I am utterly lost on how even to start this. I'm pretty positive I have started this off wrong, what have you made so far? I might be able to assist with the inFile portion
? hard to follow what you are saying without any code but your struct contains type, right? along with his/her earning and type of medium that produces the revenue. You should be able to look at that value in the struct and make a decision from its value.


you make a function with a struct same as anything else.


void foo(structname &s)
{
if(s.type == something)
code();
else … etc
}
This is what I have so far .
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;

int getBookRevenue(int, double, string);
int getMusicRevenue(int, double, string);
int getFilmRevenue(int, double, string);

int main()
{
/// declare the variables
double standardFilmRate;
double standardBookRate;
double standardMusicRate;
double AgentsShare;
double totalAgentRevenue=0.00;
double totalRevenueBook=0.00;
double totalRevenueFilms=0.00;
double totalRevenueMusic=0.00;
double totalOtherRevenue=0.00;


cout << "Artist ID" << fixed << showpoint << setw(8);
cout << " Type" << fixed << setw(16);
cout << " Earnings" <<fixed << setw(20);
cout << " Agent's Share" <<fixed << setw(1) << endl<<endl;

int ArtistID;
string Type;
double Earnings;
int getBookRevenue(int, double, string);
int getMusicRevenue(int, double, string);
int getFilmRevenue(int, double, string);

ifstream inFile ("earnings.txt");

while (inFile >> ArtistID >> Type >> Earnings){
if(Type == "book"){AgentsShare = getBookRevenue(standardBookRate, Earnings, Type);}
if (Type == "music"){AgentsShare = getMusicRevenue(standardMusicRate, Earnings, Type);}
if (Type == "film"){AgentsShare = getFilmRevenue(standardFilmRate, Earnings, Type);}
if (Type == "interview"){AgentsShare = 0.00;}
cout << ArtistID << setw(16) << Type << setw(16)<<fixed<<showpoint<<setprecision(2)<< Earnings;
cout << setw(20)<<fixed<<showpoint<<setprecision(2)<<AgentsShare<< endl;
}

inFile.close();
if (Type!= "book"||"film"||"music"){totalOtherRevenue = Earnings;}
cout << endl<<endl;
cout << "Total Agent Revenue: " << setw(30)<<totalAgentRevenue << endl;
cout << "Total Agent Revenue from Films: " << setw(20)<<totalRevenueFilms <<endl;
cout << "Total Agent Revenue from Music: " << setw(20)<<totalRevenueMusic <<endl;
cout << "Total Agent Revenue from Book: " << setw(20)<<totalRevenueBook<<endl;
cout << "Total Ineligible Revenue: " << setw(26)<<totalOtherRevenue<<endl;


-- I just cannot figure out a way to get the cumulative outputs altogether.
Please use code tags when posting code. Edit your post, highlight the code, and click the <> botton to the right of the edit window.

Why does getXYZrevenue() take the type string? getBookRevenue() knows that it's getting book revenue. Also, why do these functions return integers? I hear entertainment agents count their pennies. :)

You don't need to declare getXYZrevenue() functions inside of main() since you've already declared them at the top of the file.

You need to initialize standardBookRate, standardFilmRate and StandardMusicRate.

You should get clarification on those rate changes. Does the bonus rate apply to all revenue or just the revenue above the rate change amount? After all, it doesn't make sense for an agent to earn 10% of the total when a film star earns $1,499,999 (=$149,999.90) but 15% of the total ($225,000) when the artist earns just $1 more and hits to the rate change. In the real world, the 15% would apply to earnings over $1,500,000.

I'd approach this like a tax calculations. Create a table that contains the rates and have a function that goes through the table to compute the result. You can even have one function that does all the calculations and have getBookRevenue(), getMusicRevenue() and getFilmRevenue() call it with different rate tables and standard rates. Here's a program that does just that. It assumes that the rates are not marginal, just to make the calculations easier. If they are marginal, you just need to change agentEarnings().

The program reads revenue numbers from cin and prints the agent earnings for all 3 agents.
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";
    }
} 

Topic archived. No new replies allowed.