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
Halp Computer Science
AleksandrR [38]

1st one: is memory

2nd one: is 8

8 0
3 years ago
Read 2 more answers
3.5 Lesson practice quiz: Edhesive Question 5
Fed [463]

Answer:

There is an error, the else should be after the elif

Explanation:

5 0
2 years ago
Demographics and psychographics influence database marketing.<br><br><br> False<br><br> True
Kamila [148]

Answer:

true is the correct answer

5 0
2 years ago
A network technician configures a firewall’s ACL to allow outgoing traffic for several popular services such as email and web br
Cerrena [4.2K]

Answer: (B) Allow the firewall to accept inbound traffic to ports 80, 110, 143, and 443

Explanation:

Port 80 is used by HTTP, 110 by pop3 to retrieve emails from web servers, 143 by imap for internet messaging and 443 is used for TCP for websites using SSL. So if the firewall is allowed to accept inbound traffic to these ports 80,110,143 and 443 then it would be possible to retrieve emails.

3 0
3 years ago
What are the six external part of a computer
pashok25 [27]
I'm guessing you mean the six external parts as in input and output devices

Here are the six external parts:

>Keyboard

>Mouse

>Monitor

>Speakers

>Printer

>Microphone or USB...I think you can choose either one as they are components outside of the computer/external/ -I/O devices
5 0
3 years ago
Read 2 more answers
Other questions:
  • What are the two most important network-layer functions in a datagram network? what are the three most important network-layer f
    7·1 answer
  • Company policies require that all network infrastructure devices send system level information to a centralized server. Which of
    6·1 answer
  • Recovery after a disaster involves installing the most recent ________ backup copy.
    15·1 answer
  • The graph shows that sixty-eight percent of students think cyberbullying is a problem. One hundred human stick figures are shown
    14·2 answers
  • What type of memory or storage device is prone to losing data if the power goes out?
    5·1 answer
  • Translate the following C program into an assembly program. The C program finds the minimal value of three signed integers. Assu
    13·1 answer
  • The Open Systems Interconnection (OSI) is a conceptual model whose purpose is to make networks more manageable. Its objectives i
    15·1 answer
  • Please help it’s timed
    5·1 answer
  • 1.Which one of the following buttons returns a window to its original size?
    11·1 answer
  • You ping a host on the internet to check for connectivity. Your ping times out, and you get no response. What is most likely the
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!