1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
valkas [14]
3 years ago
6

Copy the following code and run it. You should break it into the following 3 functions

Computers and Technology
1 answer:
Darya [45]3 years ago
6 0

Answer:

The solution code is as follows:

  1. #include <iostream>
  2. using namespace() std;
  3. const double PI = 3.14159;
  4. int getValidInput() {
  5.    int radius;
  6.    cout << "Type a -1 for radius to exit" << endl;
  7.    cout << "Enter the radius: ";
  8.    cin >> radius;
  9.    
  10.    while(radius < 0){
  11.        cout << "Type a -1 for radius to exit" << endl;
  12.        cout << "Enter the radius: ";
  13.        cin >> radius;
  14.    }
  15.    return radius;
  16. }
  17. double circleCalculations(int r){
  18.    
  19.        double circ = 2 * PI * r;
  20.        double area = PI * pow(r, 2);
  21.        return area;
  22. }
  23. void printResults(int r, double a){
  24.    
  25.    cout.setf(ios::fixed);
  26.    cout.precision(1);
  27.    cout << "A circle with radius " << r << " has a circumference of "
  28.    << circ << " and an area of " << a << endl << endl;  
  29. }
  30. int main()
  31. {
  32.    int radius;
  33.    double area;
  34.    double circ;
  35.    radius = getValidInput();
  36.    area = circleCalculations(radius);
  37.    printResults(radius, area);
  38. }

Explanation:

In this question, we can identify three main functional blocks from the original codes. We cut the block of codes that ask for user input radius and paste it into the new function getValidInput() (Line 6 - 9). However, we need to add the code in Line 11-15 to ensure only the radius with valid value will be returned.

Next, we can proceed to cut another block of code that calculate the circumference and area and paste it into function circleCalculations (Line 19 -24).

Next, we cut the code that display the radius and area and paste it to function printResults(Line 26-32).

At last, we call all the three functions in the main program (Line 39-41).

You might be interested in
When using social​ media, make sure to provide access to all the information needed to accurately process messages by following
Nataly_w [17]

Answer:

Option E i.e., transparency is the correct option.

Explanation:

When any person using social media networks the he always ensure that he gives all the information related accurately about himself because in the social media network there is the transparency of everything except his chat with other but any person get details of the other person only if he is using social media network.

4 0
3 years ago
here are pros and cons for doing temp work. Please select the best answer from the choices provided T F
Brut [27]

Answer:

Hello! the answer should be true, I hope i got here in time.  

Explanation:

6 0
3 years ago
Read 2 more answers
You company hired you to build a network. List of technical question that you will ask?
vredina [299]

Explanation:

1. How many computers do you want to connect or how big the network should be?

This would tell us what kind of a network need to be built. It can be LAN/MAN/WAN

2. The location where network needs to be built?

We have to check the geographic condition too before creating a network

3. What is the budget?

Based on the budget only, we can decide the wires to be used if require we can negotiate the budget so that we can create effective network

4. Will I get an additional resources to work?

This is essential to estimate the time that is required to complete the task.

5. When the project needs to be completed?

This is crucial because a business might be planned thereafter.

6 0
3 years ago
Which type of firewall policy calls for a firewall to deny all traffic by default?
charle [14.2K]
Restrictive policy is a kind of policy calls for a firewall to contradict all traffic by default. The first rule denies all traffic on any service and using any port. To permit a specific type of traffic, a new rule must be placed ahead of the deny all rule. A firewall should enforce the overall policy recognized by the network administrator. Enforcement is controlled mainly over setting up packet filtering rules which is a rule base comprises a set of these rules. 
3 0
3 years ago
I couldn't log in cuz I was banned but here I am with the same username again lol hi
rodikova [14]

Answer:

hi how are you......

Explanation:

6 0
3 years ago
Other questions:
  • Which agricultural CTSO has programs for middle-school and high-school students, as well as college students?
    13·2 answers
  • Households pay taxes to the government and receive public services. Which of the following is a public service?
    8·1 answer
  • A motherboard uses dual channeling, but you have four DIMMs available that differ in size. The motherboard supports all four siz
    7·1 answer
  • Elizabeth works for a local restaurant at the end of her shift she read she’s required to write in the time that she arrived in
    9·1 answer
  • If you have a long title for a table and need it to span several cells, you can use A. Merge Cells. B. Split Cells. C. Insert Co
    5·1 answer
  • Please Help!!!<br> I keep getting this answer wrong
    10·1 answer
  • Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the bool variabl
    6·1 answer
  • Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. End with a n
    7·2 answers
  • Explain the consequences of using bits to represent data.
    10·1 answer
  • What is Selection statement?​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!