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]
4 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]4 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
What are the benefits of using disk cleanup as part of regular maintenance on a computer​
Morgarella [4.7K]

Your computer will absolutely benefit. Disk Cleanup is a Windows tool that lets you clean junk files and temporary files that are no longer needed, thus increasing space and performance.

4 0
3 years ago
The it department is reporting that a company web server is receiving an abnormally high number of web page requests from differ
Talja [164]
<span>In the scenario in which the IT department is reporting that a company web server is receiving an abnormally high number of web page requests from different locations simultaneously the DDoS security attack is occurring.
</span>DDos stands for Distributed Denial of Service<span> . This </span><span>attack is an attempt to make an online service unavailable by overwhelming it with traffic from multiple sources.</span>
8 0
3 years ago
Suppose your name was George Gershwin. Write a complete program that would print your last name, followed by a comma, followed b
NNADVOKAT [17]

Answer:

I will write the code in C++ and JAVA      

Explanation:

<h2>JAVA CODE</h2>

public class Main

{ public static void main(String[] args) {

       // displays Gershwin,George

     System.out.println("Gershwin,George"); }  }

<h2>C++ Code:</h2>

#include <iostream>

using namespace std;  

int main()

{  cout<<"Gershwin,George"; }    

// displays last name Gershwin followed by , followed by first name George

//displays Gershwin,George as output.

6 0
4 years ago
Read 2 more answers
Write a program that accepts inputs, outputs them and exits correctly when - 1<br> is pressed
dolphi86 [110]

Answer:

Explanation:

The following program is written in Python. It simply creates an endless loop that continously asks the user for an input. If the input is not -1 then it outputs the same input, otherwise it exists the program correctly. A test output can be seen in the attached image below.

while True:

   answer = input("Enter a value: ")  

   if answer != "-1":

       print(answer)

   else:

       break

7 0
3 years ago
According to peacemaking criminology, our society denying a citizen's basic rights is another dimension of
katovenus [111]

Answer:

Violence.

Explanation:

Peacemaking criminology believes that our justice system it's just using a different form of violence to deal with violence.

This movement states that we need to re-enter violent individuals into society, and sees crime as a direct result of a determinate social structure, such as extreme poverty, violent environments, racial hate, etc.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Assume you're using a three button mouse. to access shortcut menus you would
    10·1 answer
  • Copyrighted software that is distributed at no cost for a trial period is called?
    12·1 answer
  • Neighbor discovery performs many of the functions that icmp router discovery and icmp ____ handled in ipv4.
    13·1 answer
  • Using the drop-down menus, correctly complete the sentences.
    5·2 answers
  • A customer reports that recently several files cannot be accessed. The service technician decides to check the hard disk status
    11·1 answer
  • Use the Law of Sines to solve the triangle. Round your answers to two decimal places.
    6·1 answer
  • In addition to regular watch features, which two features are often found on smart watches?
    10·1 answer
  • Question 8 of 10
    12·1 answer
  • I'm working on an assignment for my computer science class (Edhesive) and when I run the code, there are no errors. But when I t
    11·1 answer
  • which of the following is a scenario in which an it support technician would most likely be required to implement the alternate
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!