Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.)
Task #01: Program Executes Correctly
This is the code i have so far:
#include
#include
#include
using namespace std;
// Define the namespace royaltyRates
namespace royaltyRates {
const double CHOICE_ONE_ROYALTIES =25000.0;
const double CHOICE_TWO_ROYALTY_RATE =0.125;
const double CHOICE_THREE_ROYALTY_RATE_UNDER_4000=0.10;
const double CHOICE_THREE_ROYALTY_RATE_OVER_4000=0.14;
const int CHOICE_THREE_THRESHOLD =4000;
}
int main(){
// Declare variables
double bookCost;
int soldCopies;
double option_two_royalties;
double option_three_royalties;
string bestoption;
// Read cost of book
cout << "Enter the net price of each copy of the novel: ";
cin >> bookCost;
// Read number of copies sold
cout << "Enter the estimated number of copies that will be sold: ";
cin >> soldCopies;
// Calculate the option 2 royalties amount
option_two_royalties =(bookCost * royaltyRates::CHOICE_TWO_ROYALTY_RATE)* soldCopies;
// Calculate the option 3 royalties amount
if (soldCopies <= royaltyRates::CHOICE_THREE_THRESHOLD){
option_three_royalties = bookCost * soldCopies * royaltyRates::CHOICE_THREE_ROYALTY_RATE_UNDER_4000;
} else {
option_three_royalties =(bookCost * royaltyRates::CHOICE_THREE_THRESHOLD * royaltyRates::CHOICE_THREE_ROYALTY_RATE_UNDER_4000)+
(bookCost *(soldCopies - royaltyRates::CHOICE_THREE_THRESHOLD)* royaltyRates::CHOICE_THREE_ROYALTY_RATE_OVER_4000);
}
// Determine the best option
if (royaltyRates::CHOICE_ONE_ROYALTIES > option_two_royalties && royaltyRates::CHOICE_ONE_ROYALTIES > option_three_royalties){
bestoption = "Option 1";
} else if (option_two_royalties > royaltyRates::CHOICE_ONE_ROYALTIES && option_two_royalties > option_three_royalties){
bestoption = "Option 2";
} else {
bestoption = "Option 3";
}
// Print the three royalties
cout << fixed << setprecision(2);
cout <<"['Royalty option1: "<< royaltyRates::CHOICE_ONE_ROYALTIES <<"',";
cout <<"'Royalty option2: "<< option_two_royalties <<"',";
cout <<"'Royalty option3: "<< option_three_royalties <<"']"<< endl;
// Print the best option
cout << "The best option is "<< bestoption <<"."<< endl;
return 0;
}
and these are the objectives within task 1.
Status: PASSED!
Check: 1
Test: Successful Output
Reason: None
Timestamp: 2024-07-0313:57:12.343892
Status: FAILED!
Check: 2
Test: Successful Output II
Reason: Unable to find '['Royalty option1: 25000.00', 'Royalty option2: 771604931.25', 'Royalty option3: 864189523.00']' in the program's output.
Enter the net price of each copy of the novel: Enter the estimated number of copies that will be sold: ['Royalty option1: 25000.00', 'Royalty option2: 771604931.25', 'Royalty option3: 617283945.00']
The best option is Option 2.
.
Error : AssertionError - Unable to find Royalty option3: 864189523.00 in the program's output.
Timestamp: 2024-07-0313:57:12.346166
Status: PASSED!
Check: 3
Test: Check for constant declaration in`namespace`
Reason: namespace royaltyRates +` was found in the program.None
as you can see i have two out of three but cant figure out why task 2 keeps failing and when i put it in visual studios i have no errors. very confused and need help please!
this is the full set of information including the error i keep getting, i have no idea what extra details i can offer.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions