Question

The volume of a cylinder can be computed as: v = π * r * r...

The volume of a cylinder can be computed as: v = π * r * r * h Write a C++ function that computes the volume of a cylinder given r and h. Assume that the calling function passes the values of r and h by value and v by reference, i.e. v is declared in calling function and is passed by reference. The function just updates the volume v declared in calling function. The function prototype is given by: void vol_cyl(float r, float h, float& v); Write a main program that prompts the user to enter the values of r and h. It then calls the function vol_cyl to compute the value of volume and update its value in the main program. It then prints out the values of radius, height and volume on the screen.

Homework Answers

Answer #1

#include <iostream>

using namespace std;

void vol_cyl(float r,float h,float &v)
{
v=3.14*r*r*h;
}

int main()
{
float v;
vol_cyl(2.3,4.5,v);
cout<<"volume is :"<<v;

return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Suppose the radius, height and volume of a right circular cylinder are denoted as r, h,...
Suppose the radius, height and volume of a right circular cylinder are denoted as r, h, and V . The radius and height of this cylinder are increasing as a function of time. If dr/dt = 2 and dV/dt = 10π when r = 1, h = 2, what is the value of dh/dt at this time?
The volume of a right circular cylinder is given by V= πr2h, where r is the...
The volume of a right circular cylinder is given by V= πr2h, where r is the radius of its circular base and h is its height. Differentiate the volume formula with respect to t to determine an equation relating the rates of change dV/dt , dr/dt , dh/dt.   At a certain instant, the height is 6 inches and increasing at 1 in/sec and the radius is 10 inches and decreasing at 1 in/sec. How fast is the volume changing at...
Let V be the volume of a cylinder having height h and radius r, and assume...
Let V be the volume of a cylinder having height h and radius r, and assume that h and r vary with time. (a) How are dV /dt, dh/dt, and dr/dt related? (b) At a certain instant, the height is 18 cm and increasing at 3 cm/s, while the radius is 30 cm and decreasing at 3 cm/s. How fast is the volume changing at that instant? Is the volume increasing or decreasing at that instant?
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits from base class Account and include an additional data member of type double that represents the fee charged per transaction (transactionFee). Write Checking- Account’s constructor that receives the initial balance, as well as a parameter indicating a transaction fee amount. If transaction fee is less than zero, the transactionFee will be set to zero. Write the chargeFee member function that updates the balance by...
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...