Question

In: Computer Science

Write a defining table and a computer program that computes and outputs the volume of a...

Write a defining table and a computer program that computes and outputs the volume of a torus with inner radius a and outer radius b. A doughnut is an example of a torus. Your program must read the inner radius and outer radius from two text fields and display the volume in a div. The formula for the volume of a torus is

v =  π2(a + b)(a - b)2

4

where v is the volume, π is the constant pi, a is the inner radius, and b is the outer radius. Your program should allow a user to enter real numbers such as 7.54. If you wish, you may use the following HTML code in your program.

<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Volume of a Torus</title>
<script>

// Your JavaScript function belongs here.

</script>
</head>

<body>
    <h1>Volume of a Torus</h1>
    Inner radius <input type="text" id="inner"><br>
    Outer radius <input type="text" id="outer"><br>
    <button type="button" onclick="computeVolume()">Volume</button><br>
    Volume <div id="volume"></div>
</body>
</html>
Test Cases
Inputs Output
inner outer
2.8 3.1 1.31
14.6 17.1 488.85

Solutions

Expert Solution

<!DOCTYPE HTML>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <title>Volume of a Torus</title>
    <script>
        function computeVolume() {
            var a = Number(document.getElementById("outer").value);
            var b = Number(document.getElementById("inner").value);
            var vol = Math.pow(Math.PI, 2) * (a + b) * Math.pow(a - b, 2) / 4;
            document.getElementById("volume").innerHTML = vol.toFixed(2);
        }
    </script>
</head>

<body>
<h1>Volume of a Torus</h1>
Inner radius <input type="text" id="inner"><br>
Outer radius <input type="text" id="outer"><br>
<button type="button" onclick="computeVolume()">Volume</button>
<br>
Volume
<div id="volume"></div>
</body>
</html>


Related Solutions

Write a defining table and a JavaScript program that computes and outputs the rate of change...
Write a defining table and a JavaScript program that computes and outputs the rate of change of a price. The program must allow the user to enter a previous price and a current price. The formula for the rate of change is rateOfChange =  currPrice - prevPrice prevPrice Your program should allow a user to enter real numbers such as 7.54. If you wish, you may use the following HTML code in your program. <!DOCTYPE HTML> <html lang="en-us"> <head> <meta charset="utf-8">...
Write a JavaScript program that computes the average of a collection of numbers and then outputs...
Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write a program that reads in the radius and length of a cylinder and computes volume...
Write a program that reads in the radius and length of a cylinder and computes volume using the following formulas: area = radius * radius * PI volume = area * length
Write a computer program using C++ that computes the value of a Lagrange Polynomial and accepts,...
Write a computer program using C++ that computes the value of a Lagrange Polynomial and accepts, as input: (n+1) data points (x0, f(x0)), (x1, f(x1)),...(xn, f(xn)).. at value x, which the polynomial is to evaluated. As output, the program should produce a statement that reads, "f(x) = (the value of f(x))". As a test, use the data values (1,2);(-1,1);(0,0);(2,4);(-2,3)
Using the MARIE computer assembly language, write a program that computes the following expression: z =...
Using the MARIE computer assembly language, write a program that computes the following expression: z = a * b * c. The computer will read in the input values a, b, and c from the keyboard and the final result (z) have to be displayed. In addition, every time an input value is read in, it must be displayed on the screen. Remember that the instruction set does not have an instruction to execute multiplication. Note: If any of the...
For Humming code H(15,11), write a computer program for decoding, which outputs an error correction dictionary...
For Humming code H(15,11), write a computer program for decoding, which outputs an error correction dictionary from received 15bits to corrected 11bits data or maps from input as the received 15bits to output as the corrected 11bits data. Demonstration outputs of the running program with explanation are required to show its correctness. Any computer programming language is acceptable. DETAILED DESCRIPTIONS MUST BE INCLUDED FOR THE CODE
Write the following java program. Desc: The program computes the cost of parking a car in...
Write the following java program. Desc: The program computes the cost of parking a car in a public garage at the rate $5.00/hour. The client will always be charged for whole hours. For example, if a car parked for 2 hours and 1 minute, the client will be charged for 3 hours. Input: User inputs the entry time and exit time in 24-hr clock format (hh:mm) Output: The enter and exit times, the length of time the car is parked...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT