answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
8090
11 days ago
14

Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. PLEASE DONT F

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

Computers and Technology
1 answer:
maria [879]11 days ago
5 0

Response:

The following code is provided along with the corresponding output in the diagram:

Description:

//Use this header file for visual studio.

#include "stdafx.h"

//Include requisite header files.

#include<iostream>

//Adhere to standard naming conventions.

using namespace std;

//Set up a namespace for royalty rates.

namespace royaltyRates

{

    //Declare and set the necessary 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;

};

//Begin the execution of the main() function.

int main()

{

    //Declare and initialize necessary variables.

    //These will be utilized to compute

    //the royalties for each option.

    float net_price;

    int num_copies;

    float royaltyUnderOption1, royaltyUnderOption2,

    royaltyUnderOption3;

    royaltyUnderOption1 = royaltyUnderOption2

    = royaltyUnderOption3 = 0;

    //Ask the user for the net price of each

    //novel copy.

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

    cout << "copy of the novel: ";

    cin >> net_price;

    //Request the user to provide the estimated quantity

    //of copies likely to be sold.

    cout << "Please enter the estimated number ";

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

    cin >> num_copies;

    //Output the necessary details and the royalty

    //calculated for the first option.

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

    cout << "the completed manuscript and $";

    cout << royaltyRates::PAY_ON_PUBLISH_OF_NOVAL;

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

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

    //Output the necessary details and the royalty

    //calculated for option 2.

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

    //Output the necessary details and royalty

    //calculated for option 3.

    cout << "\n*** 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 copies sold exceed 4000.

    if (num_copies > 4000)

    {

         //The total royalty is 10% for net

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

         //price for those sold beyond 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

    {

         //The royalty will amount to 10% of the net

         //price of the 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 royalty from option 1 surpasses

    //that from options 2 and 3, option 1 is

    //the optimal choice.

    if (royaltyUnderOption1 > royaltyUnderOption2 &&

    royaltyUnderOption1 > royaltyUnderOption3)

    {

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

         cout << "the author can select." << endl;

    }

    //If the royalty under option 2 exceeds

    //royalties from options 1 and 3, option 2 is

    //the best choice.

    else if (royaltyUnderOption2 > royaltyUnderOption1

    && royaltyUnderOption2 > royaltyUnderOption3)

    {

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

         cout << "the author can select." << endl;

    }

    //If the royalty from option 3 is superior to

    //the royalties from options 1 and 2, then option 3 is

    //the ideal choice.

    else

    {

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

         cout << "the author can select." << endl;

    }

    //Use this command when utilizing visual studio.

    system("pause");

    return 0;

}

You might be interested in
Given main(), define the Team class (in file Team.java). For class method getWinPercentage(), the formula is:teamWins / (teamWin
amid [800]

Answer:

Explanation:

public class Team {

   private String teamName;

   private int teamWins;

   private int teamLosses;

   public String getTeamName() {

       return teamName;

   }

   public void setTeamName(String teamName) {

       this.teamName = teamName;

   }

   public int getTeamWins() {

       return teamWins;

   }

   public void setTeamWins(int teamWins) {

       this.teamWins = teamWins;

   }

   public int getTeamLosses() {

       return teamLosses;

   }

   public void setTeamLosses(int teamLosses) {

       this.teamLosses = teamLosses;

   }

   public double getWinPercentage() {

       return teamWins / (double) (teamWins + teamLosses);

   }

}

7 0
13 days ago
Complete the function definition to output the hours given minutes. Output for sample program: 3.5
Harlamova29_29 [932]

#include <iostream>

using namespace std;


void OutputMinutesAsHours(double origMinutes) {

double hours = origMinutes / 60.0;

cout << hours;

}


int main() {

OutputMinutesAsHours(210.0); // This function will also be called with 3600.0 and 0.0.

cout << endl;

return 0;

}


The lines highlighted in bold perform the conversion from minutes to hours by dividing the input minutes by 60, since there are 60 minutes in one hour. The parameter origMinutes is a double, so the division uses 60.0 to keep consistent data types. Running this code with 210.0 will output 3.5.

4 0
1 month ago
Henry is working from a USDA office. He has several tasks to perform today: 1) he logs onto his USDA computer to get started; 2)
8_murik_8 [892]

Answer:

A. Discussing confidential matters over a mobile phone

Explanation:

In general, the signals from mobile phones are not secure. Sensitive discussions should never occur on phones that lack the necessary encryption.

3 0
1 month ago
A common fallacy is to use MIPS (millions of instructions per second) to compare the performance of two different processors, an
amid [800]

The provided question is lacking details. It can be retrieved from search engines. However, please see the full question below:

Question

It points out a mistake in using a part of the performance equation as a measure of performance. For example, examine these two processors. P1 operates at a clock frequency of 4 GHz, has an average CPI of 0.9, and needs to execute 5.0E9 instructions. P2 runs at 3 GHz, with an average CPI of 0.75, needing to execute 1.0E9 instructions. 1. A common misunderstanding is assuming that the processor with the highest clock rate has the best performance. Determine if this holds true for P1 and P2. 2. Another misconception is that the processor with the greater number of executed instructions necessarily has a longer CPU time. If processor P1 processes 1.0E9 instructions and both processors have unchanged CPI values, calculate how many instructions P2 can complete in the same duration that P1 uses to execute 1.0E9 instructions. 3. A frequent error is to use MIPS (millions of instructions per second) to evaluate the performance of different processors, believing that the one with the highest MIPS is the best. Verify whether this applies to P1 and P2. 4. MFLOPS (millions of floating-point operations per second) is another common metric, defined as MFLOPS = No. FP operations / (execution time x 1E6), but it suffers from the same issues as MIPS. Assuming 40% of the instructions executed on both P1 and P2 are floating-point instructions, calculate the MFLOPS values for the programs.

Answer:

(1) We apply the following formula:

                                         CPU time = number of instructions x CPI / Clock rate

By substituting 1 GHz = 10⁹ Hz, we find:

CPU time₁ = 5 x 10⁹ x 0.9 / 4 GHz

              = 4.5 x 10⁹ / 4 x 10⁹ Hz = 1.125 s

and,

CPU time₂ = 1 x 10⁹ x 0.75 / 3 GHz

                    = 0.75 x 10⁹ / 3 x 10⁹ Hz = 0.25 s

This shows that P2 is significantly faster than P1 because CPU₂ is shorter than CPU₁

(2)

Determine the CPU time of P1 using (*)

CPU time₁ = 1 x 10⁹ x 0.9 / 4 GHz

                  = 0.9 x 10⁹ / 4 x 10⁹ Hz = 0.225 s

Next, we need the count of instructions₂ so that CPU time₂ = 0.225 s, applying (*) with clock rate₂ = 3 GHz and CPI₂ = 0.75

Thus, instruction count₂ x 0.75 / 3 GHz = 0.225 s

Consequently, instruction count₂ = 0.225 x 3 x 10⁹ / 0.75 = 9 x 10⁸

Thus, P1 can handle more instructions than P2 within the same time frame.

(3)

We remember that:

MIPS = Clock rate / CPI x 10⁶

 So, MIPS₁ = 4 GHz / 0.9 x 10⁶ = 4 x 10⁹ Hz / 0.9 x 10⁶ = 4444

MIPS₂ = 3 GHz / 0.75 x 10⁶ = 3 x 10⁹ / 0.75 x 10⁶ = 4000

This indicates that P1 has a higher MIPS

(4)

 Now we note that:

MFLOPS = FLOPS Instructions / time x 10⁶

              = 0.4 x instructions / time x 10⁶ = 0.4 MIPS

Accordingly,

                    MFLOPS₁ = 1777.6

                    MFLOPS₂ = 1600

Again, P1 boasts a greater MFLOPS

3 0
1 month ago
There are N bulbs numbered from 1 to N, arranged in a row. The first bulb is plugged into the power socket and each successive b
ivann1987 [930]

Answer:

The code example provided has relevant comments included.

Explanation:

// Implementation of the TestSolution class

import java.util.Arrays;

public class TestSolution

{

  // Implementing the solution function

  public static int solution(int[] arr)

  {

      // Define local variables

      int i, j, count = 0;

      boolean shines;

     

      // Using nested loops to tally the instances where every lit bulb shines

      for (i = 0; i < arr.length; i++)

      {

          shines = true;

          for (j = i + 1; j < arr.length && shines; j++)

          {

              if (arr[i] > arr[j])

                  shines = false;

          }

          if (shines)

              count++;

      }

      // Return the count of instances where every lit bulb shines

      return count;

  } // End of solution function


  // Main function begins

  public static void main(String[] args)

  {

      // Arrays A, B, and C are created

      int[] A = {2, 1, 3, 5, 4};

      int[] B = {2, 3, 4, 1, 5};

      int[] C = {1, 3, 4, 2, 5};

     

      // Generate a random number N in the range of [1..100000]

      int N = 1 + (int)(Math.random() * 100000);

     

      // Create an array D of size N

      int[] D = new int[N];

     

      // Fill array D with distinct random numbers in the [1..N] range

      int i = 0;

      while(i < N)

      {

          int num = 1 + (int)(Math.random() * N);

          boolean found = false;

          for(int j = 0; j < i && !found; j++)

          {

              if(D[j] == num)

                  found = true;

          }

         

          if(!found)

          {

              D[i] = num;

              i++;

          }

      }          

     

      // Display elements and moments of arrays A, B, and C

      System.out.println("Array A: " + Arrays.toString(A) + " and Moments: " + solution(A));

      System.out.println("Array B: " + Arrays.toString(B) + " and Moments: " + solution(B));

      System.out.println("Array C: " + Arrays.toString(C) + " and Moments: " + solution(C));

     

      // Output the size and moments of array D

      System.out.println("Size(N) of Array D: " + N + " and Moments: " + solution(D));

     

  } // End of main function

} // End of TestSolution class

3 0
1 month ago
Other questions:
  • Which of these is an example of the integrity principle that can ensure your data is accurate and untampered with?
    10·2 answers
  • Why computer is known as versatile and diligent device ?explain​
    14·1 answer
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • Write a statement that reads a floating point value from standard input into temperature. Assume that temperature. has already b
    6·1 answer
  • FOREACH, EXPLODE and MAIL are examples of crazy functions.
    13·1 answer
  • Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is
    5·1 answer
  • The president of the company wants a list of all orders ever taken. He wants to see the customer name, the last name of the empl
    15·1 answer
  • Assume that the following variables have been properly declared and initialized.
    12·1 answer
  • In a survey of 7200 T.V. viewers, 40% said they watch network news programs. Find the margin of error for this survey if we want
    6·1 answer
  • Write a program in pascal to find the area of a circle
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!