In: Computer Science
(C++) Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. Instructions for Programming Exercise 16 of Chapter 4 have been posted below for your convenience. Exercise 16 A new author is in the process of negotiating a contract for a new romance novel.
The publisher is offering three options. In the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. In the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. In the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. The author has some idea about the number of copies that will be sold and would like to have an estimate of the royalties generated under each option. Write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. The program then outputs the royalties under each option and the best option the author could choose. (Use appropriate named constants to store the special values such as royalty rates and fixed royalties.)
An input of: 20, 5
Should have an output of:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//declare the variables and set r1 to 25000 as
royality 1 (fixed)
double netprice,r1=25000,r2,r3,total;
int copy;
//loop is used to restrict user to enter -ve or
0 values
do
{
//ask user to input the net price of each
novel
cout<<endl<<"Enter the net price of
each novel";
cin>>netprice;//read net
price
}while(netprice<=0);
//loop is used to restrict user to enter -ve or
0 values
do
{
//ask userto input the number of
novels sold
cout<<endl<<"Enter the estimated
number of copies to sold";
cin>>copy;//read the number
}while(copy<=0);
total = netprice*copy; //calculate the total
amount
r2 = total * 0.125; //compute the royality value
of option 2
//condition for royality 3
if(copy<=4000) // compute the royality option
for first 4000 copies
r3 = total * 0.1;//calculate the royality
else //compute the royality if copies sold
greater than 4000
r3= (netprice*4000) * 0.1 + (netprice *
(copy-4000))*0.14;
//display all royality prices
cout<<endl<<"Royality Option 1:
"<<fixed<<setprecision(2)<<r1;
cout<<endl<<"Royality Option 2:
"<<fixed<<setprecision(2)<<r2;
cout<<endl<<"Royality Option 3:
"<<fixed<<setprecision(2)<<r3;
//condition to choose the greatest royality plan
if(r1>r2 && r1>r3)
cout<<endl<<"Author should go through
Royality 1.";
else
if(r2>r3 && r2>r1)
cout<<endl<<"Author should go through
Royality 2.";
else
cout<<endl<<"Author should go through
Royality 3.";
}
OUTPUT