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
Which is the another name of automatic sequence control calculator​
Alla [95]

Answer:

IBM Automatic Sequence Controlled Calculator (ASCC)

3 0
2 years ago
The readline method reads text until an end of line symbol is encountered, how is an end of line character represented
zhannawk [14.2K]

Answer:

\n

Explanation:

readline() method is used to read one line from a file. It returns that line from the file.    

This line from the file is returned as a string. This string contains a \n at the end which is called a new line character.

So the readline method reads text until an end of line symbol is encountered, and this end of line character is represented by \n.

For example if the file "abc.txt" contains the lines:

Welcome to abc file.

This file is for demonstrating how read line works.

Consider the following code:

f = open("abc.txt", "r")  #opens the file in read mode

print(f.readline()) # read one line from file and displays it

The output is:

Welcome to abc file.    

The readline() method reads one line and the print method displays that line.                        

3 0
3 years ago
To test for the current date in a query, type ____ in the criteria row of the appropriate column.
lyudmila [28]

Answer:

zxc

Explanation:

zc

6 0
3 years ago
Do you think privacy policies are effective in social networking sites?
Kamila [148]

Answer:

When that information gets posted online, it is no longer private, and may end up falling into wrong hands. Even if you have put in place the highest possible security measures, some of your friends, colleagues and companies you interact with on social media, can end up leaking your personal information.

4 0
2 years ago
What are comments meant to do?
docker41 [41]
Comment<span> (computer programming) ... In computer programming, a </span>comment<span> is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.</span>
8 0
3 years ago
Other questions:
  • The last 64 bits of an ipv6 address are the interface identifier. what is frequently used to specify the interface identifier?
    14·1 answer
  • The data in a data warehouse have which of the following characteristics?
    13·1 answer
  • Which statement outputs a double value in a field of nine characters with three digits after the decimal point?
    13·1 answer
  • A technician has been given a PC that is not powering up. After brief troubleshooting, the technician comes to the conclusion th
    14·1 answer
  • ______ is the ability of a system to do more than one thing at a time. A. Multibusing c. online processing b. Multiprocessing d.
    13·1 answer
  • Picture question please help me
    8·2 answers
  • What is the missing line of code? &gt;&gt;&gt; &gt;&gt;&gt; math.sqrt(16) 4.0 &gt;&gt;&gt; math.ceil(5.20) 6
    14·2 answers
  • What are some ways you can use the Effect Options dialog box to customize animations in a presentation? Check all
    6·2 answers
  • Compare the graphs. Find the value of h, k, or a.
    7·1 answer
  • A __________ attack is a bot attack on a computer system or network that causes a loss of service to users.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!