(Financial application: find the profit-per-item) Use the scheme in programming Exercise 5.39 to write a function that computes the profit-per-item. The header of the function is: double computeProfitPerItem(double quantity) Write a test program that displays the following table:

PHOTO EMBED

Sun Nov 08 2020 00:51:22 GMT+0000 (Coordinated Universal Time)

Saved by @mahmoud hussein #c++

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


int compute_profit(int quantity);

int main()
{
	int quantity = 1000;
	cout << "Quantity " << setw(9) << "Profit-per-item (in $)"<<endl;
    for ( ; quantity <= 10000; quantity+=1000)
    {
            cout<<quantity<< setw(9)<<compute_profit(quantity)<<endl;
    }
   
}
int compute_profit(int quantity)
{
    int profit = 0;
   

   
    if (quantity < 1000)
        profit += quantity; // * 1
    else
    {
        profit += 1000;
        quantity -= 1000;
        if (quantity < 4000)
            profit += quantity * 2;
        else
        {
            profit += 8000; // 4000 * 2
            quantity -= 4000;
            profit += quantity * 5;
        }
    }
    
    return profit;
}


content_copyCOPY

http://cpp.sh/