228k views
5 votes
Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. PLEASE DONT FORGET THIS PART- it makes me confused.Instructions for Programming Exercise 16 of Chapter 4 have been posted below for your convenience.Exercise 16A 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.)

2 Answers

5 votes

Here is a Python program that meets your requirements:

Python Code

# Define constants

FIXED_ROYALTY_1 = 5000

FIXED_ROYALTY_2 = 20000

ROYALTY_RATE_1 = 0.125

ROYALTY_RATE_2_LOW = 0.1

ROYALTY_RATE_2_HIGH = 0.14

COPY_THRESHOLD = 4000

# Get user input

net_price = float(input("Enter the net price of each copy of the novel: "))

estimated_sales = int(input("Enter the estimated number of copies sold: "))

# Calculate royalties for each option

option_1_royalty = FIXED_ROYALTY_1 + FIXED_ROYALTY_2

option_2_royalty = net_price * ROYALTY_RATE_1 * estimated_sales

option_3_royalty_low = net_price * ROYALTY_RATE_2_LOW * COPY_THRESHOLD

option_3_royalty_high = net_price * ROYALTY_RATE_2_HIGH * (estimated_sales - COPY_THRESHOLD)

option_3_royalty = option_3_royalty_low + option_3_royalty_high

# Determine the best option

best_option = 1

highest_royalty = option_1_royalty

if option_2_royalty > highest_royalty:

best_option = 2

highest_royalty = option_2_royalty

if option_3_royalty > highest_royalty:

best_option = 3

highest_royalty = option_3_royalty

# Output results

print(f"Option 1: ${option_1_royalty:.2f}")

print(f"Option 2: ${option_2_royalty:.2f}")

print(f"Option 3: ${option_3_royalty:.2f}")

print(f"Best option: Option {best_option} with a royalty of ${highest_royalty:.2f}")

This program uses named constants for royalty rates and fixed royalties. It prompts the user for the net price and estimated sales, calculates the royalties for each option, determines the best option, and outputs the results

User Alex Lobakov
by
3.6k points
1 vote

Answer:

Code is given below and output is attached in the diagram:

Step-by-step explanation:

//Use this header file while using visual studio.

#include "stdafx.h"

//Include the required header files.

#include<iostream>

//Use the standard naming convention.

using namespace std;

//Define a namespace royaltyRates.

namespace royaltyRates

{

//Declare and initialize required named 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;

};

//Start the execution of main() method.

int main()

{

//Declare and initialize the required variables

//which are going to be used to calculate

//royalities under each option.

float net_price;

int num_copies;

float royaltyUnderOption1, royaltyUnderOption2,

royaltyUnderOption3;

royaltyUnderOption1 = royaltyUnderOption2

= royaltyUnderOption3 = 0;

//Prompt the user to enter the net price of each

//novel.

cout << "Please enter the net price for each ";

cout << "copy of the novel : ";

cin >> net_price;

//Prompt the user to enter the estimated number

//of copies of the novels to be sold.

cout << "Please enter the estimated number ";

cout << "of copies to be sold : ";

cin >> num_copies;

//Display the required details and royalty

//calculated under option 1.

cout << "\\*** 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 author for the delivery of ";

cout << "the final manuscript and $";

cout << royaltyRates::PAY_ON_PUBLISH_OF_NOVAL;

cout << " is paid for the publication of ";

cout << "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;

//Display the required details and royalty

//calculated under option 2.

cout << "\\*** 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;

//Display the required details and royalty

//calculated under option 3.

cout << "\\*** 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 the number of copies is greater than 4000.

if (num_copies > 4000)

{

//Total amount of royalty will be 10% of net

//price of first 4000 copies and 14 % of net

//price of copies sold over 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

{

//Total amount of royalty will be 10% of net

//price of 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 the royalty under option 1 is greater than

//royalty under option 2 and 3, then option 1 is

//best option.

if (royaltyUnderOption1 > royaltyUnderOption2 &&

royaltyUnderOption1 > royaltyUnderOption3)

{

cout << "\\Option 1 is the best option that ";

cout << "author can choose." << endl;

}

//If the royalty under option 2 is greater than

//royalty under option 1 and 3, then option 2 is

//best option.

else if (royaltyUnderOption2 > royaltyUnderOption1

&& royaltyUnderOption2 > royaltyUnderOption3)

{

cout << "\\Option 2 is the best option that ";

cout << "author can choose." << endl;

}

//If the royalty under option 3 is greater than

//royalty under option 1 and 2, then option 3 is

//best option.

else

{

cout << "\\Option 3 is the best option that ";

cout << "author can choose." << endl;

}

//Use this command while using visual studio.

system("pause");

return 0;

}

Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined-example-1
User Parveen Verma
by
4.6k points