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
Suppose that you are asked to modify the Stack class to add a new operation max() that returns the current maximum of the stack
Advocard [28]

Answer:

Following are the code to the given points:

Explanation:

For point 8.1:

public String max()//defining a method max

{

   String maxVal=null;//defining a string variable that holds a value

   for(int x=0;x<n;x++)

   {

       if(maxVal==null || a[i].compareTo(maxVal)>0)//defining if blok to comare the value

       {

           maxVal=a[i];//holding value in maxVal variable

       }

   }

   return maxVal;//return maxVal variable value

}

For point 8.2:

public void push(String item)//defining a method push that accepts item value in a parameter

{

       a[n]=item;//defining an array to hold item value

       if(n==0 || item.compareTo(maxVals[n-1])>0)//use if to comare item value

       {

               maxVals[n]=item;//holding item value in maxVals variable

       }

       else

       {

               maxVals[n]=maxVals[n-1];//decreasing the maxVals value

       }

       n++;//incrementing n value

}

public String pop()//defining a method pop

{

       return a[--n];//use return value

}

public String max()//defining a method max

{

       return maxVals[n-1];//return max value

}

  • In the first point, the max method is declared that compares the string and returns its max value.
  • In the second point, the push, pop, and max method are declared that works with their respective names like insert, remove and find max and after that, they return its value.
7 0
3 years ago
The set of instructions given to a computer is called _____________________.
adell [148]

Answer:  c) a program.

Explanation:

A computer, is a hardware device, that differs from those with dedicated hardware (like a TV set, a radio, or an old phone) , in that it can be used for different purposes, due to it's a programmable device.

The way in which the computer is instructed to do anything, is by means of a set of instructions to  be read and executed sequentially, which is called a program.

The set of the different programs stored in the computer is which is known as the computer software.

4 0
3 years ago
Virus infections often disable antivirus programs and prevent them from being enabled
SCORPION-xisa [38]
Some of the advanced viruses do this. So it would be true.
3 0
3 years ago
A router receives a packet and determines the outbound link for the packet. When the packet arrives, 2/3 of one other packet is
vlada-n [284]

Answer:

Queuing Delay is 0.08 seconds

Explanation:

The answer follows a formula that is relatively easy to use and is detailed below.

Queuing Delay = [(L - x) + (nL)] / R

where,

L is packet length given as 3,000 bytes

x is the currently transmitted packet given as 2/3 * 3,000 = 2,000

n is the number of packets waiting in the Que given as 5

R is the rate of transmission given as 4 Mbps (4 * 10^6 Bps)

We can simply plug in the above information in the equation for computing Queuing Delay.

Lets take the numerator first which would be [(3000 - 2000) + (5 * 3000)]

The numerator would be 16000 bytes. These are being transmitted at 4Mbps. So, 16000*4*5 = 320,000 "bits"

Queuing Delay= 320,000/4000000

Queuing Delay = 0.08 seconds.

As we can see, the formula is quite intuitive to use. You are simply taking the number of packets to be transmitting, incorporating the partially transmitted packet, multiplying by the number of packets and the rate of transmission and then dividing the product by the rate of transmission to compute what the delay in the Que is.

6 0
3 years ago
Find the simple interest Jay owes on a five-year student loan of $48,000 with an annual interest rate of 5%.
borishaifa [10]
Use the equation I=prt where interest = principal times rate times time.

Fill it out, it becomes I= 48000(.05)(5)

I= 12000
3 0
3 years ago
Other questions:
  • Tommy has hired a marketing company to create a billboard advertisement
    11·2 answers
  • Client computers cannot function unless they are connected to the network because they cannot access an operating system.
    7·1 answer
  • Drag each label to the correct location on the image.
    10·1 answer
  • How do you check how much space is left in current drive?
    9·1 answer
  • Describe the basic features of the relational data model and discuss their importance to the end user and the designer. Describe
    9·1 answer
  • Which fund classification would a focus on only stocks of technology companies match?
    10·1 answer
  • Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shi
    9·1 answer
  • Finish the program by choosing the correct terms.
    7·2 answers
  • Viruses which activate themselves after a specific time is called
    10·2 answers
  • Help me please, I'm attempting a test<br>​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!