Question: Instructions Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. Instructions for Programming Exercise 16

Instructions

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. 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.)

I wrote the following but it was not correct, I'd be very grateful for the help thanks.

//main.cpp

//includeheaderfiles

#include

#include

#include

usingnamespacestd;

intmain()

{

//declarevariables

doublebookCost;

doublesoldCopies;

doubleoption_two_royalties;

doubleoption_three_royalties;

stringbestoption;

//Setconstantforroyalties

constdoubleCHOICE_ONE_ROYALTIES=25000;

constdoubleCHOICE_TWO_ROYALTY_RATE=0.125;

constdoubleCHOICE_THREE_ROYALTY_RATE_UNDER_4000=0.10;

constdoubleCHOICE_THREE_ROYALTY_RATE_OVER_4000=0.14;

//Readcostofbook

cout

cin>>bookCost;

//Readnumberofcopiessold

cout

cin>>soldCopies;

/*Calculatetheoption2royalitiesamount*/

option_two_royalties=(bookCost*CHOICE_TWO_ROYALTY_RATE)*soldCopies;

/*Calculatetheoptionthreeroyalitiesamountbelow4000soldcopies*/

if(soldCopies

option_three_royalties=bookCost*soldCopies*CHOICE_THREE_ROYALTY_RATE_UNDER_4000;

/*Calculatetheoptionthreeroyalitiesamountabove4000soldcopies*/

elseif(soldCopies>4000)

option_three_royalties=((bookCost*soldCopies*CHOICE_THREE_ROYALTY_RATE_UNDER_4000)

+bookCost*(soldCopies-4000)*CHOICE_THREE_ROYALTY_RATE_OVER_4000);

/*checkingthebestoption

Checkifroyaltiesfromchoiceoneismorethan

otpion2andoption3

*/

if((CHOICE_ONE_ROYALTIES>option_two_royalties)&&

(CHOICE_ONE_ROYALTIES>option_three_royalties))

bestoption="Option1";

/*Otherwisecheckifoption2royaltiesismorethanchoce1andoption2royalties*/

elseif(option_two_royalties>CHOICE_ONE_ROYALTIES&&option_two_royalties>option_three_royalties)

bestoption="Option2";

else

/*Otherwiseoption3issetasbestoption*/

bestoption="Option3";

cout

//printthethreeroyalites

cout

cout

cout

//printthebestoption

cout

return0;

}

InstructionsRedo Programming Exercise 16 of Chapter 4 so that all the namedconstants are defined in a namespace royaltyRates.Instructions for Programming Exercise 16 ofChapter 4 have been posted below for your convenience.Exercise 16A new author

M4 Programming Assignment 7-2 Royalty Rates D Tasks main.cpp + 1 / /main . cpp O out of 3 checks passed. Review the results below for more details. 2 / /include header files 3 #include Checks 4 #include 5 #include > Test Case . Incomplete 6 using namespace std; Successful Output 7 int main( ) 8 5 Test Case . Incomplete V 9 //declare variables 10 Successful Output II double bookCost; 11 double soldCopies; Input 12 double option_two_royalties; 13 double option_three_royalties; 14 string bestoption; 123456789 15 50 16 / /Set constant for royalties 17 const double CHOICE_ONE_ROYALTIES = 25000; Output 18 const double CHOICE_TWO_ROYALTY_RATE = 0. 125; 19 const double CHOICE_THREE_ROYALTY_RATE_UNDER_4000 20 const double CHOICE_THREE_ROYALTY_RATE_OVER_4000 Enter the price of a book : $123456789 21 Enter number of copies expected to be sold : 50 22 / /Read cost of book Total royalties for OPTION 1 : $25000.00 23 cout > bookCost; Total royalties for OPTION 3 : $617283945.00 25 / /Read number of copies sold Option 2 is best Option. 26 cout > soldCopies; 28 Results 29 30 Royalty optionl: 25000.00 Royalty option2: 771604931.25 Royalty option3: 864189523.00 /*Calculate the option 2 royalities amount*/ 31 option_two_royalties = (bookCost * CHOICE_TWO_ROYA Show Details * soldCopies; 32 33 /*Calculate the option three royalities amount bel Code Pattern . Incomplete sold copies*/ Check for constant declaration in namespace 34 if (soldCopies out of 10.00 4 #include 5 #include O out of 3 checks passed. Review the results below for more details. 6 using namespace std; 7 int main( ) 8 { Checks 9 //declare variables 10 double bookCost ; Test Case . Incomplete 11 double soldCopies; Successful Output 12 double option_two_royalties; 13 double option_three_royalties; Test Case . Incomplete 14 string bestoption; Successful Output II 15 16 / /Set constant for royalties Code Pattern . Incomplete 17 const double CHOICE_ONE_ROYALTIES = 25000; Check for constant declaration in namespace 18 const double CHOICE_TWO_ROYALTY_RATE = 0.125; 19 const double CHOICE_THREE_ROYALTY_RATE_UNDER_4000 Description 20 const double CHOICE_THREE_ROYALTY_RATE_OVER_4000 Searched your code for a specific pattern: 21 namespace . +royaltyRates 22 / /Read cost of book 23 cout > bookCost; You can learn more about regular expressions [here ] (https://ruby-doc. org, 25 / /Read number of copies sold 26 cout > soldCopies; 28 29 30 /*Calculate the option 2 royalities amount*/ 31 option_two_royalties = (bookCost * CHOICE_TWO_ROYA * soldCopies; 32 33 /*Calculate the option three royalities amount bel sold copies*/ 34 if (soldCopies 4 #include Test Case . Incomplete 5 #include > Successful Output 6 using namespace std; 7 int main( ) Input 8 { 9 / /declare variables 20 10 double bookCost ; 5 11 double soldCopies; 12 double option_two_royalties; 13 double option_three_royalties; Output 14 string bestoption; 15 Enter the price of a book : $20 16 / /Set constant for royalties Enter number of copies expected to be sold : 5 17 const double CHOICE_ONE_ROYALTIES = 25000; Total royalties for OPTION 1 : $25000.00 18 const double CHOICE_TWO_ROYALTY_RATE = 0. 125; Total royalties for OPTION 2 : $12.50 19 const double CHOICE_THREE_ROYALTY_RATE_UNDER_4000 Total royalties for OPTION 3 : $10.00 20 const double CHOICE_THREE_ROYALTY_RATE_OVER_4000 Option 1 is best Option. 21 22 / /Read cost of book 23 cout > bookCost; 25 / /Read number of copies sold Royalty optionl: 25000.00 Royalty option2: 12.50|Royalty option3: 10.00 26 cout > soldCopies; 28 29 Test Case . Incomplete > 30 /*Calculate the option 2 royalities amount*/ Successful Output II 31 option_two_royalties = (bookCost * CHOICE_TWO_ROYA * soldCopies; Code Pattern . Incomplete 32 Check for constant declaration in namespace 33 /*Calculate the option three royalities amount bel sold copies*/ 34 if (soldCopies

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!