You are using a version without Ads of this website. Please, consider donating:

### Functional decomposition - radius, height and volume for cylinder

How is functional decomposition different than doing it "normally"? Anyways, I don't know how to start.

Question 1
Use functional decomposition, write C++ program that will prompt user to enter
the radius and height for a cylinder and then calculate the volume for the
cylinder and then display the height, radius and volume.
Use π = 3.14 and the formula for volume is : volume = π radius2
*height
You must use pass-by-reference mechanism to get the value for radius and height
using a single function, say getRadiusHeight().
Remember to add documentation for your function; what it does, preconditions and
postconditions.
I think that by "normally" your teacher means write everything in the main function -bad idea but works-
Using functional decomposition you can easily change the behavior of your program, because you have modules, where you can implement changes, instead of a fat main function.
This approach is based on dividing a problem in smaller subproblems.

for example:

 ``` Eyenrique-MacBook-Pro:Study Eyenrique\$ ./example2 Enter a number: 4 4 is even ```

 ``12345678910111213141516171819202122`` ``````//example.cpp //no functions. #include using std::cout; using std::cin; using std::endl; int main(){ int number; cout<<"Enter a number: "; cin>>number; if(number%2==0) cout<

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445`` ``````//example2.cpp //divide and conquer. #include using std::cout; using std::cin; using std::endl; bool isEven(int number); //function prototypes int setNumber(); int main(){ int number; number=setNumber(); if(!isEven(number)) //if is not even cout<>number; return number; }//end function setNumber bool isEven(int number){ //if you want to verify if some number is even or odd //twice or more //you only have to call isEven function //instead of repeat the code needed. if(number%2==0) return true; else return false; }//end function isEven ``````
Last edited on
I've seen this a lot:

using std::cout;
using std::cin;
using std::endl;

but I don't think it is used in any of the class examples. What are those?
I believe you were probably taught

#include<iostream>
using namespace std;

it's the equivalent.
Topic archived. No new replies allowed.