Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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
Define a function CalcPyramidVolume with double data type parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations:Volume = base area x height x 1/3Base area = base length x base width.(Watch out for integer division). #include <iostream>using namespace std; /* Your solution goes here  */ int main() {   double userLength;   double userWidth;   double userHeight;    cin >> userLength;   cin >> userWidth;   cin >> userHeight;    cout << "Volume: " << CalcPyramidVolume(userLength, userWidth, userHeight) << endl;    return 0;}
Given the Class Definition for ClockType discussed  extensively  in class, write what                   would have to be added to the FUNCTION DEFINITION for the Class ClockType to                     overload the “= =”, i.e., the comparison “equal-equal sign,” here:                NOTE: In other words, WHAT WOULD BE ADDED TO THE CLASS DEFINITION ONLY?                    Note:   ThePrivate Members are:                     int hr;    //  contains the hours int min;  //  contains the minutes int sec;   //  contains the seconds
Write a C# program which uses the concept of function overloading to write the following functions a function named perimeter to calculate the  perimeter of a rectangle perimeter = 2 x length + 2 x width b.    a function named perimeter to calculate the perimeter of a square perimeter = 4 x length

Chapter 4 Solutions

Problem Solving with C++ (10th 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...Ch. 4 - Your sports league uses the following lottery...Ch. 4 - Do Programming Project 14 from Chapter 3, the Edoc...
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