Response:
The following code is provided along with the corresponding output in the diagram:
Description:
//Use this header file for visual studio.
#include "stdafx.h"
//Include requisite header files.
#include<iostream>
//Adhere to standard naming conventions.
using namespace std;
//Set up a namespace for royalty rates.
namespace royaltyRates
{
//Declare and set the necessary constants.
const double PAY_ON_DELIVERY_OF_NOVAL = 5000;
const double PAY_ON_PUBLISH_OF_NOVAL = 20000;
const double PER_ON_NET_PRICE_SECOND_OPTION =
0.125;
const double PER_ON_NET_PRICE_FIRST_4000 = 0.1;
const double PER_ON_NET_PRICE_OVER_4000 = 0.14;
};
//Begin the execution of the main() function.
int main()
{
//Declare and initialize necessary variables.
//These will be utilized to compute
//the royalties for each option.
float net_price;
int num_copies;
float royaltyUnderOption1, royaltyUnderOption2,
royaltyUnderOption3;
royaltyUnderOption1 = royaltyUnderOption2
= royaltyUnderOption3 = 0;
//Ask the user for the net price of each
//novel copy.
cout << "Please enter the net price for each ";
cout << "copy of the novel: ";
cin >> net_price;
//Request the user to provide the estimated quantity
//of copies likely to be sold.
cout << "Please enter the estimated number ";
cout << "of copies to be sold: ";
cin >> num_copies;
//Output the necessary details and the royalty
//calculated for the first option.
cout << "\n*** Option 1: ****" << endl;
cout << "Net price of each novel: $" << net_price;
cout << endl;
cout << "Estimated number of copies to be sold ";
cout << "is: " << num_copies << endl;
cout << "$";
cout << royaltyRates::PAY_ON_DELIVERY_OF_NOVAL;
cout << " is paid to the author for delivering ";
cout << "the completed manuscript and $";
cout << royaltyRates::PAY_ON_PUBLISH_OF_NOVAL;
cout << " is paid for the publication of ";
cout << "the novel." << endl;
royaltyUnderOption1 =
royaltyRates::PAY_ON_DELIVERY_OF_NOVAL +
royaltyRates::PAY_ON_PUBLISH_OF_NOVAL;
cout << "Total amount of royalty under option 1 ";
cout << "is $" << royaltyUnderOption1 << endl;
//Output the necessary details and the royalty
//calculated for option 2.
cout << "\n*** Option 2: ****" << endl;
cout << "Net price of each novel: $";
cout << net_price << endl;
cout << "Estimated number of copies to be sold ";
cout << "is: " << num_copies << endl;
royaltyUnderOption2 =
(royaltyRates::PER_ON_NET_PRICE_SECOND_OPTION *
net_price)* num_copies;
cout << "Total amount of royalty under option 2 ";
cout << "is $" << royaltyUnderOption2 << endl;
//Output the necessary details and royalty
//calculated for option 3.
cout << "\n*** Option 3: ****" << endl;
cout << "Net price of each novel: $" << net_price;
cout << endl;
cout << "Estimated number of copies to be sold ";
cout << "is: " << num_copies << endl;
//If copies sold exceed 4000.
if (num_copies > 4000)
{
//The total royalty is 10% for net
//price of the first 4000 copies and 14% for net
//price for those sold beyond 4000.
royaltyUnderOption3 =
(royaltyRates::PER_ON_NET_PRICE_FIRST_4000 *
net_price) * 4000 +
(royaltyRates::PER_ON_NET_PRICE_OVER_4000 *
net_price) * (num_copies - 4000);
}
//Otherwise,
else
{
//The royalty will amount to 10% of the net
//price of the first 4000 copies.
royaltyUnderOption3 =
(royaltyRates::PER_ON_NET_PRICE_FIRST_4000 *
net_price) * num_copies;
}
cout << "Total amount of royalty under option 3 ";
cout << "is $" << royaltyUnderOption3 << endl;
//If royalty from option 1 surpasses
//that from options 2 and 3, option 1 is
//the optimal choice.
if (royaltyUnderOption1 > royaltyUnderOption2 &&
royaltyUnderOption1 > royaltyUnderOption3)
{
cout << "\nOption 1 is the best option that ";
cout << "the author can select." << endl;
}
//If the royalty under option 2 exceeds
//royalties from options 1 and 3, option 2 is
//the best choice.
else if (royaltyUnderOption2 > royaltyUnderOption1
&& royaltyUnderOption2 > royaltyUnderOption3)
{
cout << "\nOption 2 is the best option that ";
cout << "the author can select." << endl;
}
//If the royalty from option 3 is superior to
//the royalties from options 1 and 2, then option 3 is
//the ideal choice.
else
{
cout << "\nOption 3 is the best option that ";
cout << "the author can select." << endl;
}
//Use this command when utilizing visual studio.
system("pause");
return 0;
}