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
Select the correct answer. What has enabled engineers to design slim and sleek television sets? A. using Nipkow disks B. increas
kykrilka [37]

Answer:

D. replacing cathode ray tube technology

Explanation:

In past few years traditional TV set are being replaced by LCD and LED tv technology. In Traditional TV sets, cathode ray tube is used that is large in size and heavy in weight. Due to this reason, the size of the TV set is too large.

The cathode ray technology is replaced with liquid crystal display (LCD) which may use plasma and Light emitting diode (LED) technology that are smaller in size that make TV sets slim and sleek. This the reason, that the size of TV is reduced significantly.

8 0
4 years ago
How do you close a document but keep the word processing program open?
Zielflug [23.3K]

You open a new tab for word then close a other document

7 0
3 years ago
Read 2 more answers
(will give brainleist) Which image type changes the total number of pixels in an image?
Leokris [45]

Answer:

vector

Explanation:

8 0
3 years ago
Which of the following is not a barrier to corporate control?​ a. ​antitakeover amendments b. ​proxy contests c. ​poison pills d
Elan Coil [88]

Answer: Proxy contest.

Explanation:

In corporate control it is the authority of the corporate organisation to take all the major decision. It takes decisions on matters related to marketing, investment, new project sanctioning, new fund raising, policy of the corporate and etc.

Among all the options we have proxy contest enable to secure enough votes in the corporate to win over the governance in the corporate. It is more over like an unfriendly war between the corporate allies. It garners support from stakeholders to gain corporate vote.

However, all the other options such as golden parachutes whereby an employee can get certain benefits if its employments is terminated and antitakeover amendments or poison pills serve as barrier to corporate control as these benefits and amendments causes barriers to making laws and governing them in a corporate. So proxy contest itself being a support mechanism to garner votes in the corporate mechanism do not form a barrier in corporate control.

5 0
4 years ago
A previously saved labels report can be accessed from the
Tcecarenko [31]

C. is the answer to that question

6 0
3 years ago
Other questions:
  • Xanadu was to be a full-blown multimedia computer that could embody any medium.a. Trueb. False
    6·1 answer
  • Why do you need to back up important data?
    5·2 answers
  • Write a program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as wel
    15·1 answer
  • An employment situation that pays bills but is largely unfilling is
    13·1 answer
  • Write a program to help a travelling sales person keep up with their daily mileage driven for business. In your main method, the
    12·1 answer
  • Convert each number into scientific notation.
    6·1 answer
  • Assume your sketch has a variable named silo, which stores an object that is defined by a class you have created. The name of th
    15·1 answer
  • Test if the word mold is stored in the variable word. Computer science.
    9·1 answer
  • 2. Which pattern microphone should Jennifer take to the press conference? Jennifer is a journalist with one of the leading newsp
    14·1 answer
  • How do i work this out? does anyone do programming?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!