![Problem Solving with C++ (9th Edition)](https://www.bartleby.com/isbn_cover_images/9780133591743/9780133591743_largeCoverImage.gif)
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...
![Check Mark](/static/check-mark.png)
Want to see the full answer?
Check out a sample textbook solution![Blurred answer](/static/blurred-answer.jpg)
Chapter 4 Solutions
Problem Solving with C++ (9th Edition)
- In C/C++, Function overloading is the process of creating several functions that have exactly the same name. In order to overload successfully, each function must have: A. A different parameter list B. A different number of parameters and a different return type C. An integer on the end of the function name, such as func1()and func2() D. Either A or B E. Both A and Carrow_forwardUsing c++ In main.cpp, complete the function RollSpecificNumber() that takes in three parameters: a GVDie object, an integer representing a desired face number of a die, and an integer representing the goal amount of times to roll the desired face number. The function RollSpecificNumber() then rolls the die until the desired face number is rolled the goal amount of times and returns the number of rolls required. 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 used during development uses a seed value of 15, but when submitted, different seed values 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: 3 20 the output is: It took 140 rolls to get a "3" 20 times. #include <iostream>#include "GVDie.h"using…arrow_forwardpython Define stubs for the functions get_user_num() and compute_avg(). Each stub should print "FIXME: Finish function_name()" followed by a newline, and should return -1. Each stub must also contain the function's parameters.Sample output with two calls to get_user_num() and one call to compute_avg():FIXME: Finish get_user_num() FIXME: Finish get_user_num() FIXME: Finish compute_avg() Avg: -1 i keep getting errors on this onearrow_forward
- Consider the function definition: void Demo (int intVal, float& floatVal ) { intVal = intVal * 2; floatVal = float(intVal) + 3.5; } a. Suppose that the caller has variables int myInt and float myFloat whose values are 20 and 4.8, respectively. What are the values of myInt and myFloat after return from the following function call? Demo(myInt, myFloat); myInt: myFloat: b. Also, describe what happens in MEMORY when the Demo function is called. Think about the by reference and by value parameters.arrow_forwardIn c++, write a function Circle::intersect(Circle c) where class is defined below, for the funtion it returns bool values, true if two circle outline intersect each other and false if not. Circle::intersect(Circle c) { // example double X = x - c.getX(); double Y = y - c.getY(); double rad = radius + c.getRadius(); } class Circle { private: double x; double y; double radius; public: bool intersect(Circle c); }arrow_forwardimplement pass-by-value parameter passing method.USE C LANGUAGEarrow_forward
- Abstracting Calculations. We can use functions to hide the complexity of a calculation away from the main part of a program. You will design a new version of the program you created below. In this new version, you will create a function for the formula used in that program. Your program shall: Define a function for the formula used in the program with the appropriate parameters, and return value. Use a meaningful name for this function. Call the function in the main part of the program. Run and test the program to make sure it works correctly SummaryThe program is to take the number of miles driven and the gallons of gas usedand then calculate the car's miles-per-gallon using the formula:MPG = Miles driven / Gallons of gas used ''' #variables total_miles_driven = float(input("Enter the no of miles driven: "))time_driven = float(input("Enter how many hours did it driven: "))gallon_gas = float(input("Enter the gallons of gas used: ")) #Speed equation speed =…arrow_forwardSelect all possible error free overloads of the function declaration, void convert_temperature(int fahrenheit); Hint: try these out with a simple function body. int convert_temperature(int temp); std::string convert_temperature(std::string fahrenheit); int convert_temperature(int fahrenheit); void convert_temperature(int temp_fahrenheit ); double convert_temperature(double fahrenheit);arrow_forwarduse c++ programming language to create a derived, or child class for Cylinder, that is, a Cone class. The same function, with the same parameters, is used. However, the formula is different for a cone. // The formula is: V = (1/3) * pi * (r^2) * harrow_forward
- using c++ Develop a class called Point with two data members: x and y. Here you are dealing with a point in planar (2D) Cartesian coordinates with two integer values (x and y). Here are what you need to do: • Define a print function that returns the coordinates of a Point object. • Define a function to find the distance between two points. • Define a function to move a point to the specified location (x’, y’). • Define a function to translate a point by (dx, dy): the new location will be (x+dx, y+dy). • Define functions to tell the user if a point is on the left side, right side, above, or below another point (it can be the combination of some of these or exactly on the same spot). You also need to implement proper constructors (default and parameter constructors), a copy constructor, a destructor, getters, and setters for the data members. Implement the program with separate files: an interface file, an implementation file, and an application file (driver program). Your driver program…arrow_forwardLanguage is Carrow_forwardWrite a C++ program that: | • Implements a class with three datamembers (szum (int), count (int), avg (float)}. • Implement the following 3 member functions: • The first function is a default constructor which initializes sum and count to zero. The second function is named add which receives an integer number as input parameter and add it to sum and increment count by 1. The third function is named output which divides the sum over count and save it to avg then print the avg value). • Then, write a program to read numbers from the user until entering zero. The program uses the previous class to calculate and print average of (positive, negative) numbers.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)