Question

In: Computer Science

(C++) Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined...

(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:

Royalty option1: 25000.00
Royalty option2: 12.50
Royalty option3: 10.00

Solutions

Expert Solution

#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


Related Solutions

C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and implementation file from Exercise 1 have been provided. Write a test program that tests various operations on the class rectangleType. I need a main.cpp file Given: **************rectangleType.cpp******************** #include <iostream> #include <cassert> #include "rectangleType.h" using namespace std; void rectangleType::setDimension(double l, double w) { if (l >= 0) length = l; else length =...
c++ Redo Programming Exercise 14 by first sorting the array before determining the array elements that...
c++ Redo Programming Exercise 14 by first sorting the array before determining the array elements that are the sum of two other elements. Use a selection sort algorithm, discussed in this chapter to sort the array. Instructions and code for Programming Exercise 14 have been included for your convenience. Exercise 14 Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program prompts a user for the number of contestants entered in this year’s and last year’s Greenville Idol competition, and then it displays the revenue expected for this year’s competition if each contestant pays a $25 entrance fee. The programs also display a statement that compares the number of contestants each year. Now, replace that statement with one of the following messages: If the competition...
Chapter 2, Problem 4E in An Introduction to Programming with C++ All of the employees at...
Chapter 2, Problem 4E in An Introduction to Programming with C++ All of the employees at Merks Sales are paid based on an annual salary rather than an hourly wage. However, some employees are paid weekly while others are paid every other week (biweekly). Weekly employees receive 52 paychecks; biweekly employees receive 26 paychecks. The payroll manager wants a program that displays two amounts: an employee’s weekly gross pay and his or her biweekly gross pay. Complete an IPO chart...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11 in Chapter 6 asked you to design a program that plays the Rock, Paper, Scissors game. In the program, the user enters one of the three strings—"rock", "paper", or "scissors"—at the keyboard. Add input validation (with a case-insensitive comparison) to make sure the user enters one of those strings only. Modifications: Allow the user to input "r", "p", "s" or the full strings "Rock",...
C++ Programming Chapter 7 Assignment: Assignment #4 – Student Ranking : In this assignment you are...
C++ Programming Chapter 7 Assignment: Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display...
In this exercise, find the values of the unknown constants so that the indicated conditions are met for each function:
In this exercise, find the values of the unknown constants so that the indicated conditions are met for each function: (a) f(t) = At2 + B; given f(0) = 2 and f(−2) = −10. (b) f(t) = Ct3 + D; given f(0) = −5 and f(3) = 49. (c) f(t) = A t 2 + B , given f(0) = 3 and f(−2) = 1.5 (d) f(t) = A t + B , given f(2) = 0.4 and f(8) =...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However,...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However, in that exercise, the program could add only integers of, at most, 20 digits. This chapter explains how to work with dynamic integers. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects...
afe Rational Fractions In week 4 we completed Chapter 13 Programming Exercise #10 Page 974. Make...
afe Rational Fractions In week 4 we completed Chapter 13 Programming Exercise #10 Page 974. Make sure you have a working fractionType class before starting this assignment. The template requirement from week 4 is not required for this assignment. Your assignment this week is to make your fractionType class safe by using exception handling. Use exceptions so that your program handles the exceptions division by zero and invalid input. An example of invalid input would be entering a fraction such...
Using C Programming. Put all of these 4 things in one source file and attach to...
Using C Programming. Put all of these 4 things in one source file and attach to this question. Put #1 in main. Put all the others into separate function functions but in the same file.   1)   Put this code in main. You are writing a program for Bowl Me Over, a local bowling alley. The program will allow staff to enter any number of bowling scores. Scores in a standard game range between 0 to 300, with being a perfect...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT