Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 4.4, Problem 19STE

Explanation of Solution

The function “unitPrice()” with “static_cast<double>(2)” is executed in the C++ language which gives the output as follows,

// Include required header files

#include <iostream>

using namespace std;

// Declaration of unitPrice() function

double unitPrice(int diameter, double price);

// Definition of unitPrice() function

double unitPrice(int diameter, double price){

  // Define a constant value for PI

  const double PI = 3.14159;

  // Declare the variables

  double radius, area;

  // Compute radius

  radius = diameter/static_cast<double>(2);

  // Compute area

  area = PI * radius * radius;

  // Compute the unit price and return the result

  return (price/area);

}

// Definition of main() function

int main() {

// Call the unitPrice() function and display the result

  cout << "Price: " << unitPrice(13, 14) <<"\n";

  // Return 0

  return 0;

}

Output for the above function is as follows,

Price: 0.105476

The function “unitPrice()” with the constant “2...

Blurred answer
Students have asked these similar questions
Using c++ Rolling for a pair   Given two GVDie objects that represent 2 six-sided dice and an integer that represents a desired value as parameters, complete the function RollingForPair() in the main class. The main class rolls the dice until a pair with the desired value is rolled. The function RollingForPair() then returns the number of rolls thrown to achieve the result. Assume the desired value received from input is within the appropriate range, 1-6. Note: For testing purposes, the GVDie objects are created in the main() function using a pseudo-random number generator with a fixed seed value. The program uses a seed value of 15 during development, but when submitted, a different seed value will be used for each test case. Refer to the textbook section on random numbers to learn more about pseudo-random numbers. Ex: If the GVDie objects are created with a seed value of 15 and the input of the program is: 2 the output is: It took 82 rolls to get a pair of 2's.   #include…
Add 3 parameters to each function in the code below.  ********************************************* Code starts here ************************************************** Module.py    #Defination to sort the list def sort(listNum):     sortedList = []     #While loop will run until the listNum don't get null     while(len(listNum) != 0 ):         #Set the min as first element in list         min = listNum[0]         #iterate over the list to compare every element with num             for ele in listNum:             #If element is less than min             if ele < min:                 #Then set min as element                 min = ele         #append the sorted element in list         sortedList.append(min)         #Remove the sorted element from the list         listNum.remove(min)         return sortedList #Function to find the sum of all elements in list def SumOfList(listNum):     #Set the sum as zero     sum =0     #Iterate over the list to get every element     for ele in…
Write a function calculateProduct that has two formal parameters int num1, and int num2. The function will return the positive value of the calculation of the product of num1 and num2. Use the predefined function to convert a negative product value to a positive one.

Chapter 4 Solutions

Problem Solving with C++ (9th Edition)

Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function isDigit...Ch. 4.3 - Write a function definition for a function...Ch. 4.4 - What is the purpose of the comment that...Ch. 4.4 - Prob. 16STECh. 4.4 - Prob. 17STECh. 4.4 - Carefully describe the process of program testing.Ch. 4.4 - Prob. 19STECh. 4.5 - If you use a variable in a function definition,...Ch. 4.5 - Suppose a function named Function1 has a variable...Ch. 4.5 - The following function is supposed to take as...Ch. 4.5 - Prob. 23STECh. 4.6 - Prob. 24STECh. 4.6 - Prob. 25STECh. 4.6 - Prob. 26STECh. 4.6 - Suppose you have two function definitions with the...Ch. 4.6 - This question has to do with the Programming...Ch. 4.6 - Prob. 29STECh. 4 - A liter is 0.264179 gallons. Write a program that...Ch. 4 - Modify your program from Practice Program 1 so...Ch. 4 - The price of stocks is sometimes given to the...Ch. 4 - Write a program to gauge the rate of inflation for...Ch. 4 - Enhance your program from the previous Practice...Ch. 4 - Write a function declaration for a function that...Ch. 4 - The gravitational attractive force between two...Ch. 4 - Prob. 8PCh. 4 - Prob. 9PCh. 4 - Write a program that computes the annual after-tax...Ch. 4 - Write a program that asks for the users height,...Ch. 4 - Modify your program from Programming Project 2 so...Ch. 4 - Write a program that outputs the lyrics for the...Ch. 4 - To maintain ones body weight, an adult human needs...Ch. 4 - You have invented a vending machine capable of...Ch. 4 - Your time machine is capable of going forward in...Ch. 4 - Do Programming Project 11 from Chapter 3 except...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning