This Python program takes two numbers from the user representing the lengths of two sides of a right triangle, squares each number using a function, and calculates the length of the hypotenuse using the Pythagorean theorem and another function. The program outputs the squares of the two sides and the calculated length of the hypotenuse.
Need to revise working code below,A good design means the applicat.pdfarchgeetsenterprises
Need to revise working code below,
A good design means the application should scale easily -- that is, the application should be
designed so that additional processing requirements can be added without making having to
rewrite the application each time. Revise code below to add the following design features:
Move the code to display the menu to it\'s own method.
Create a method to handle capturing the shape dimensions. One approach may be to pass to the
method the dimension to enter (\"base\", \"height\", \"side\" or \"radius\") as a String.
Processing for each of the shapes matched in the switch statement should also be moved to their
own methods.
Notes -
The program should \"look and feel\" like the code below.
The program should display the menu and prompt the user for a shape (or an exit).
If the user enters a value that corresponds to a shape, program control (via the switch statement)
should transfer control to a method specific to the shape that will pass control to prompt for the
appropriate dimensions to another method, then calculate the area and perimeter (circumference)
as directed in PLP06, and display the result.
The program should repeat from step 1 above.
import java.util.Scanner;
public class Pickashape {
//Declaring constant
public static final double PI = 3.14159;
public static void main(String[] args) {
//Declaring variable
int choice;
//Scanner class Obejct is used to read the inputs entered by the user
Scanner sc = new Scanner(System.in);
//This loop continues to execute until user enters choice \'5\'
do {
//Displaying the menu
System.out.println(\"\ \ Choose the shape\");
System.out.println(\"1. Square\");
System.out.println(\"2. Rectangle\");
System.out.println(\"3. Circle\");
System.out.println(\"4. Triangle\");
System.out.println(\"5. Quit\");
System.out.print(\"Enter your choice:\");
choice = sc.nextInt();
//Based on the User selection the corresponding case will be executed
switch (choice) {
//This case will calculate the area and perimeter of the square
case 1: {
//Declaring variables
double side, area, perimeter;
//Getting the side of the square entered by the user
System.out.print(\"Enter the side (as a decimal):\");
side = sc.nextDouble();
//calculating the area of the square
area = side * side;
//calculating the perimeter of the square
perimeter = 4 * side;
//Displaying the area of the square
System.out.println(\"The area is \" + area);
//Displaying the perimeter of the square;
System.out.println(\"The perimeter is \" + perimeter);
break;
}
case 2: {
//Declaring variables
double firstside, secondside, area, perimeter;
//Getting the first side of the rectangle
System.out.print(\"Enter the first side (as a decimal):\");
firstside = sc.nextDouble();
//Getting the second side of the rectangle
System.out.print(\"Enter the second side (as a decimal):\");
secondside = sc.nextDouble();
//Calculating the area of the rectangle
area = firstside * secondside;
//Calculating the perimeter of the rectangle
perimeter = 2 * fi.
I worte the code according to the requirement.And also I wrote the c.pdfsudhinjv
I worte the code according to the requirement.And also I wrote the code to continue the program
until user enters 4 to quit the program.
If you want me to do any modifications other than these I will modify.
________________________________________
GeometricShape.java
public class GeometricShape
{
private double side1, side2, side3; //These are the variables necessary to calculat the perimeter
of a triangle
private double radius; //Radius is needed to calculate the perimeter of a circle
private double length, width; //Length and Width are needed to calculate the perimeter of a
rectangle
private boolean isTriangle = false;
private boolean isRectangle = false;
private boolean isCircle = false;
//Constructor for a triangle
public GeometricShape(double aSide1, double aSide2, double aSide3)
{
side1 = aSide1;
side2 = aSide2;
side3 = aSide3;
isTriangle = true;
}
//Task #1a - Finish writing an Overloaded Constructor for a rectangle here: (don\'t forget to set
isRectangle to true)
public GeometricShape(double aLength, double aWidth)
{
this.length=aLength;
this.width=aWidth;
isRectangle=true;
}
//Task #1b - Write an Overloaded Constructor for a circle here: (don\'t forget to set isCircle to
true)
public GeometricShape(double radius)
{
this.radius=radius;
isCircle=true;
}
public double getRadius()
{
return radius;
}
public double getSide1()
{
return side1;
}
public double getSide2()
{
return side2;
}
public double getSide3()
{
return side3;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public void setRadius(double aRadius)
{
radius = aRadius;
}
public void setSide1(double aSide1)
{
side1 = aSide1;
}
public void setSide2(double aSide2)
{
side2 = aSide2;
}
public void setSide3(double aSide3)
{
side3 = aSide3;
}
public void setLength(double aLength)
{
length = aLength;
}
public void setWidth(double aWidth)
{
width = aWidth;
}
public double getPerimeter()
{
double perimeter =0;
//Calculate the perimeter of the Geometric object depending on what the object is.
//Remember the following formulas:
//Perimeter of a Triangle = Side1 + Side2+ Side3
//Perimeter of a Rectangle = (2 * length) + (2 * width)
//Perimeter of a Circle = 2 * Math.PI * radius
if (isTriangle == true)
{
//Complete formula for triangle perimeter
perimeter = side1 + side2 + side3;
}
else if (isRectangle == true)
{
//Task 2a: Complete formula for rectangle perimeter
perimeter= (2 * length) + (2 * width);
}
else if (isCircle == true)
{
//Task 2b: Complete formula for circle perimeter
perimeter=2 * Math.PI * radius;
}
//Continue with the rest of the else if logic here.
//change return statement to match the perimeter of the shape
return perimeter;
}
public String toString()
{
if (isTriangle == true)
{
//Return \"It\'s a Triangle: \" and concatenate all the attributes of a triangle
return \"It\'s a Triangle, with side1 = \" + side1 + \" side2 = \" + side2 + \" side3 = \"+ side3;
}
else if (isRectangle == true)
{
//Task 3a: return \"It\'s a Rectangle: \" a.
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition pg. 25
An Introduction to
Computer Science with Java, Python and C++
Community College of Philadelphia edition
Copyright 2017 by C.W. Herbert, all rights reserved.
Last edited October 8, 28, 2019 by C. W. Herbert
This document is a draft of a chapter from An Introduction to Computer Science with Java, Python and C++, written by Charles Herbert. It is available free of charge for students in Computer Science courses at Community College of Philadelphia during the Fall 2019 semester. It may not be reproduced or distributed for any other purposes without proper prior permission.
Please report any typos, other errors, or suggestions for improving the text to [email protected]
Chapter 5 – Python Functions and Modular Programming
Contents
Lesson 5.1User Created Functions in Python2
Python Function Parameters2
Value returning functions3
Example – Methods and Parameter Passing5
9
Lesson 5.2Top-Down Design and Modular Development10
Chapter Exercises13
User Created Functions in Python
So far we have only created software with one continuous Python script. We have used functions from other python modules, such as the square root method from the math class math.sqrt(n). Now we will begin to create our own functions of our own.
A Python function is a block of code that can be used to perform a specific task within a larger computer program. It can be called as needed from other Python software. Most programming languages have similar features, such as methods in Java or subroutines in system software.
The code for user-defined functions in Python is contained in a function definition. A Python function definition is a software unit with a header and a block of Python statements. The header starts with the keyword def followed by the name of the function, then a set parenthesis with any parameters for the function. A colon is used after the parentheses to indicate a block of code follows, just as with the if and while statements. The block of code to be included within the function is indented.
Here is an example of a Python function:
# firstFunction.py
# first demonstration of the use of a function for CSCI 111
# last edited 10/08/2o19 by C. Herbert
function
definition
def myFunction():
print ( "This line being printed by the function MyFunction.\n")
# end myFunction()
### main program ###
function used by the main part of the script
print("Beginning\n")
myFunction()
print("End\n")
# end main program
Functions can used for code that will be repeated within a program, or for modular development, in which long programs are broken into parts and the parts are developed independently. The parts can be developed as Python functions, then integrated to work together by being called from other software.
Python Function Parameters
Data can be passed to a Python function as a parameter of the function. Function parameters are variables listed in parentheses foll ...
Dealing with Python Reactively - PyCon Korea 2017Kenneth Ceyer
More sample code is available at:
https://github.com/KennethanCeyer/pycon-kr-2017
When developing with Python
Do you have any memory overflows, or the order of the process is in the wrong order?
Reactive programming helps you easily define and recycle complex data flows from a new perspective.
The Generators and Coroutines are designed to light up a huge stream of data and handle it the way you want. Of course, the processing time does not increase!
We will share to you how to make your code more efficient by using about the mentioned features for lunch at the upcoming FICON Korea 2017, Sunday 13th.
TOPIC:-
SCIENTIFIC CALCULATOR
PURPOSE:-
To create scientific calculator class to perform the task related to scientific calculations. Which include finding square or cube etc.
The scientific calculator perform following task:-
1. Determine the square of the number.
2. Determine the square root of the number
3. Determine the first number power of the second number
4. Determine the factorial of a number
5. Determine the sin, cos and tan value of the number.
6. Determine the logarithm, natural logarithm and exponential of the number.
Create the equivalent of a four function calculator. The program should request the user to enter a number, an operator, and another number. carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. (Using switch statement ).ThesisScientist.com
can someone fix the errors in this code- the name needs to be Fraction.pdfvinaythemodel
can someone fix the errors in this code? the name needs to be FractionDemo.java
//author: Jazmine Tapia
//date: 20 February 2023
//file: FractionDemo.java
/*
Lab 13 will also be using demonstation the
the multiplication of two factors.
*/
//import statements for Scanner class
import java.util.Scanner;
// Define a public class called Fraction
public class FractionDemo
{
// Define private instance variables for the numerator and denominator
private int numerator;
private int denominator;
// Define a constructor for the Fraction class that takes a numerator and denominator as
arguments
public FractionDemo(int numerator, int denominator)
{
// Set the denominator using the setDenominator() method defined below
setDenominator(denominator);
// Set the numerator
this.numerator = numerator;
// Reduce the fraction
reduce();
// Adjust the signs of the numerator and denominator if necessary
adjustSigns();
}
// Define a getter method for the numerator
public int getNumerator()
{
return numerator;
}
// Define a setter method for the numerator
public void setNumerator(int numerator)
{
this.numerator = numerator;
}
// Define a getter method for the denominator
public int getDenominator()
{
return denominator;
}
// Define a setter method for the denominator
public void setDenominator(int denominator)
{
// Set the denominator using the setDenominator() method defined below
setDenominator(denominator);
// Reduce the fraction
reduce();
// Adjust the signs of the numerator and denominator if necessary
adjustSigns();
}
// Define a private method to set the denominator
private void setDenominator(int denominator)
{
// If the denominator is zero, throw an exception
if (denominator == 0)
{
throw new IllegalArgumentException("Denominator cannot be zero");
}
// Set the denominator
this.denominator = denominator;
}
// Define a private method to calculate the greatest common divisor of two integers
private int gcd(int a, int b)
{
if (b == 0)
{
return a;
} else {
return gcd(b, a % b);
}
}
// Define a public method to reduce the fraction
public void reduce()
{
// Calculate the greatest common divisor of the numerator and denominator
int gcd = gcd(numerator, denominator);
// Divide both the numerator and denominator by the greatest common divisor to reduce the
fraction
numerator /= gcd;
denominator /= gcd;
}
// Define a private method to adjust the signs of the numerator and denominator if necessary
private void adjustSigns()
{
// If the denominator is negative, multiply both the numerator and denominator by -1 to adjust
the signs
if (denominator < 0)
{
numerator *= -1;
denominator *= -1;
}
}
// Define a public method to add two fractions
public FractionDemo add(FractionDemo other)
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
// Get the numerator and denominator for the first fraction
System.out.print("Enter the numerator of the first fraction: ");
int num1 = input.nextInt();
System.out.print("Enter the denominator of the first fraction.
Write a Function procedure to calculate the surface area of a right ci.docxlez31palka
Write a Function procedure to calculate the surface area of a right circular cone, given its side dimension, s, and bottom radius, r: A = pir^2s On a worksheet, enter a radius and side length into labeled input cells, and use your function procedure in a labeled output cell. Pass the inputs as arguments to your function. Be sure to show the units of your inputs and outputs.
Solution
import java.util.Scanner;
public class SurfaceArea //function to calculate surface area of right circular cone
{
public static void main(String[] args)
{
float r, h;
Scanner s = new Scanner(System.in);
System.out.print(\"Enter the side of cone:\");
h = s.nextInt(); //side of a cone
System.out.print(\"Enter the radius of cone:\");
r = s.nextInt(); //bottom radius of cone
SurfaceArea b=new SurfaceArea(); //object to invoke the function called
b.compute(h,r); //calling function and passing arguements
}
void compute(float h,float r)
{
double area, pi = 3.14;
area = (pi * r * h) + (pi * r * r);
System.out.println(\"Surface Area of cone:\"+area);
}
}
.
Need to revise working code below,A good design means the applicat.pdfarchgeetsenterprises
Need to revise working code below,
A good design means the application should scale easily -- that is, the application should be
designed so that additional processing requirements can be added without making having to
rewrite the application each time. Revise code below to add the following design features:
Move the code to display the menu to it\'s own method.
Create a method to handle capturing the shape dimensions. One approach may be to pass to the
method the dimension to enter (\"base\", \"height\", \"side\" or \"radius\") as a String.
Processing for each of the shapes matched in the switch statement should also be moved to their
own methods.
Notes -
The program should \"look and feel\" like the code below.
The program should display the menu and prompt the user for a shape (or an exit).
If the user enters a value that corresponds to a shape, program control (via the switch statement)
should transfer control to a method specific to the shape that will pass control to prompt for the
appropriate dimensions to another method, then calculate the area and perimeter (circumference)
as directed in PLP06, and display the result.
The program should repeat from step 1 above.
import java.util.Scanner;
public class Pickashape {
//Declaring constant
public static final double PI = 3.14159;
public static void main(String[] args) {
//Declaring variable
int choice;
//Scanner class Obejct is used to read the inputs entered by the user
Scanner sc = new Scanner(System.in);
//This loop continues to execute until user enters choice \'5\'
do {
//Displaying the menu
System.out.println(\"\ \ Choose the shape\");
System.out.println(\"1. Square\");
System.out.println(\"2. Rectangle\");
System.out.println(\"3. Circle\");
System.out.println(\"4. Triangle\");
System.out.println(\"5. Quit\");
System.out.print(\"Enter your choice:\");
choice = sc.nextInt();
//Based on the User selection the corresponding case will be executed
switch (choice) {
//This case will calculate the area and perimeter of the square
case 1: {
//Declaring variables
double side, area, perimeter;
//Getting the side of the square entered by the user
System.out.print(\"Enter the side (as a decimal):\");
side = sc.nextDouble();
//calculating the area of the square
area = side * side;
//calculating the perimeter of the square
perimeter = 4 * side;
//Displaying the area of the square
System.out.println(\"The area is \" + area);
//Displaying the perimeter of the square;
System.out.println(\"The perimeter is \" + perimeter);
break;
}
case 2: {
//Declaring variables
double firstside, secondside, area, perimeter;
//Getting the first side of the rectangle
System.out.print(\"Enter the first side (as a decimal):\");
firstside = sc.nextDouble();
//Getting the second side of the rectangle
System.out.print(\"Enter the second side (as a decimal):\");
secondside = sc.nextDouble();
//Calculating the area of the rectangle
area = firstside * secondside;
//Calculating the perimeter of the rectangle
perimeter = 2 * fi.
I worte the code according to the requirement.And also I wrote the c.pdfsudhinjv
I worte the code according to the requirement.And also I wrote the code to continue the program
until user enters 4 to quit the program.
If you want me to do any modifications other than these I will modify.
________________________________________
GeometricShape.java
public class GeometricShape
{
private double side1, side2, side3; //These are the variables necessary to calculat the perimeter
of a triangle
private double radius; //Radius is needed to calculate the perimeter of a circle
private double length, width; //Length and Width are needed to calculate the perimeter of a
rectangle
private boolean isTriangle = false;
private boolean isRectangle = false;
private boolean isCircle = false;
//Constructor for a triangle
public GeometricShape(double aSide1, double aSide2, double aSide3)
{
side1 = aSide1;
side2 = aSide2;
side3 = aSide3;
isTriangle = true;
}
//Task #1a - Finish writing an Overloaded Constructor for a rectangle here: (don\'t forget to set
isRectangle to true)
public GeometricShape(double aLength, double aWidth)
{
this.length=aLength;
this.width=aWidth;
isRectangle=true;
}
//Task #1b - Write an Overloaded Constructor for a circle here: (don\'t forget to set isCircle to
true)
public GeometricShape(double radius)
{
this.radius=radius;
isCircle=true;
}
public double getRadius()
{
return radius;
}
public double getSide1()
{
return side1;
}
public double getSide2()
{
return side2;
}
public double getSide3()
{
return side3;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public void setRadius(double aRadius)
{
radius = aRadius;
}
public void setSide1(double aSide1)
{
side1 = aSide1;
}
public void setSide2(double aSide2)
{
side2 = aSide2;
}
public void setSide3(double aSide3)
{
side3 = aSide3;
}
public void setLength(double aLength)
{
length = aLength;
}
public void setWidth(double aWidth)
{
width = aWidth;
}
public double getPerimeter()
{
double perimeter =0;
//Calculate the perimeter of the Geometric object depending on what the object is.
//Remember the following formulas:
//Perimeter of a Triangle = Side1 + Side2+ Side3
//Perimeter of a Rectangle = (2 * length) + (2 * width)
//Perimeter of a Circle = 2 * Math.PI * radius
if (isTriangle == true)
{
//Complete formula for triangle perimeter
perimeter = side1 + side2 + side3;
}
else if (isRectangle == true)
{
//Task 2a: Complete formula for rectangle perimeter
perimeter= (2 * length) + (2 * width);
}
else if (isCircle == true)
{
//Task 2b: Complete formula for circle perimeter
perimeter=2 * Math.PI * radius;
}
//Continue with the rest of the else if logic here.
//change return statement to match the perimeter of the shape
return perimeter;
}
public String toString()
{
if (isTriangle == true)
{
//Return \"It\'s a Triangle: \" and concatenate all the attributes of a triangle
return \"It\'s a Triangle, with side1 = \" + side1 + \" side2 = \" + side2 + \" side3 = \"+ side3;
}
else if (isRectangle == true)
{
//Task 3a: return \"It\'s a Rectangle: \" a.
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition pg. 25
An Introduction to
Computer Science with Java, Python and C++
Community College of Philadelphia edition
Copyright 2017 by C.W. Herbert, all rights reserved.
Last edited October 8, 28, 2019 by C. W. Herbert
This document is a draft of a chapter from An Introduction to Computer Science with Java, Python and C++, written by Charles Herbert. It is available free of charge for students in Computer Science courses at Community College of Philadelphia during the Fall 2019 semester. It may not be reproduced or distributed for any other purposes without proper prior permission.
Please report any typos, other errors, or suggestions for improving the text to [email protected]
Chapter 5 – Python Functions and Modular Programming
Contents
Lesson 5.1User Created Functions in Python2
Python Function Parameters2
Value returning functions3
Example – Methods and Parameter Passing5
9
Lesson 5.2Top-Down Design and Modular Development10
Chapter Exercises13
User Created Functions in Python
So far we have only created software with one continuous Python script. We have used functions from other python modules, such as the square root method from the math class math.sqrt(n). Now we will begin to create our own functions of our own.
A Python function is a block of code that can be used to perform a specific task within a larger computer program. It can be called as needed from other Python software. Most programming languages have similar features, such as methods in Java or subroutines in system software.
The code for user-defined functions in Python is contained in a function definition. A Python function definition is a software unit with a header and a block of Python statements. The header starts with the keyword def followed by the name of the function, then a set parenthesis with any parameters for the function. A colon is used after the parentheses to indicate a block of code follows, just as with the if and while statements. The block of code to be included within the function is indented.
Here is an example of a Python function:
# firstFunction.py
# first demonstration of the use of a function for CSCI 111
# last edited 10/08/2o19 by C. Herbert
function
definition
def myFunction():
print ( "This line being printed by the function MyFunction.\n")
# end myFunction()
### main program ###
function used by the main part of the script
print("Beginning\n")
myFunction()
print("End\n")
# end main program
Functions can used for code that will be repeated within a program, or for modular development, in which long programs are broken into parts and the parts are developed independently. The parts can be developed as Python functions, then integrated to work together by being called from other software.
Python Function Parameters
Data can be passed to a Python function as a parameter of the function. Function parameters are variables listed in parentheses foll ...
Dealing with Python Reactively - PyCon Korea 2017Kenneth Ceyer
More sample code is available at:
https://github.com/KennethanCeyer/pycon-kr-2017
When developing with Python
Do you have any memory overflows, or the order of the process is in the wrong order?
Reactive programming helps you easily define and recycle complex data flows from a new perspective.
The Generators and Coroutines are designed to light up a huge stream of data and handle it the way you want. Of course, the processing time does not increase!
We will share to you how to make your code more efficient by using about the mentioned features for lunch at the upcoming FICON Korea 2017, Sunday 13th.
TOPIC:-
SCIENTIFIC CALCULATOR
PURPOSE:-
To create scientific calculator class to perform the task related to scientific calculations. Which include finding square or cube etc.
The scientific calculator perform following task:-
1. Determine the square of the number.
2. Determine the square root of the number
3. Determine the first number power of the second number
4. Determine the factorial of a number
5. Determine the sin, cos and tan value of the number.
6. Determine the logarithm, natural logarithm and exponential of the number.
Create the equivalent of a four function calculator. The program should request the user to enter a number, an operator, and another number. carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. (Using switch statement ).ThesisScientist.com
can someone fix the errors in this code- the name needs to be Fraction.pdfvinaythemodel
can someone fix the errors in this code? the name needs to be FractionDemo.java
//author: Jazmine Tapia
//date: 20 February 2023
//file: FractionDemo.java
/*
Lab 13 will also be using demonstation the
the multiplication of two factors.
*/
//import statements for Scanner class
import java.util.Scanner;
// Define a public class called Fraction
public class FractionDemo
{
// Define private instance variables for the numerator and denominator
private int numerator;
private int denominator;
// Define a constructor for the Fraction class that takes a numerator and denominator as
arguments
public FractionDemo(int numerator, int denominator)
{
// Set the denominator using the setDenominator() method defined below
setDenominator(denominator);
// Set the numerator
this.numerator = numerator;
// Reduce the fraction
reduce();
// Adjust the signs of the numerator and denominator if necessary
adjustSigns();
}
// Define a getter method for the numerator
public int getNumerator()
{
return numerator;
}
// Define a setter method for the numerator
public void setNumerator(int numerator)
{
this.numerator = numerator;
}
// Define a getter method for the denominator
public int getDenominator()
{
return denominator;
}
// Define a setter method for the denominator
public void setDenominator(int denominator)
{
// Set the denominator using the setDenominator() method defined below
setDenominator(denominator);
// Reduce the fraction
reduce();
// Adjust the signs of the numerator and denominator if necessary
adjustSigns();
}
// Define a private method to set the denominator
private void setDenominator(int denominator)
{
// If the denominator is zero, throw an exception
if (denominator == 0)
{
throw new IllegalArgumentException("Denominator cannot be zero");
}
// Set the denominator
this.denominator = denominator;
}
// Define a private method to calculate the greatest common divisor of two integers
private int gcd(int a, int b)
{
if (b == 0)
{
return a;
} else {
return gcd(b, a % b);
}
}
// Define a public method to reduce the fraction
public void reduce()
{
// Calculate the greatest common divisor of the numerator and denominator
int gcd = gcd(numerator, denominator);
// Divide both the numerator and denominator by the greatest common divisor to reduce the
fraction
numerator /= gcd;
denominator /= gcd;
}
// Define a private method to adjust the signs of the numerator and denominator if necessary
private void adjustSigns()
{
// If the denominator is negative, multiply both the numerator and denominator by -1 to adjust
the signs
if (denominator < 0)
{
numerator *= -1;
denominator *= -1;
}
}
// Define a public method to add two fractions
public FractionDemo add(FractionDemo other)
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
// Get the numerator and denominator for the first fraction
System.out.print("Enter the numerator of the first fraction: ");
int num1 = input.nextInt();
System.out.print("Enter the denominator of the first fraction.
Write a Function procedure to calculate the surface area of a right ci.docxlez31palka
Write a Function procedure to calculate the surface area of a right circular cone, given its side dimension, s, and bottom radius, r: A = pir^2s On a worksheet, enter a radius and side length into labeled input cells, and use your function procedure in a labeled output cell. Pass the inputs as arguments to your function. Be sure to show the units of your inputs and outputs.
Solution
import java.util.Scanner;
public class SurfaceArea //function to calculate surface area of right circular cone
{
public static void main(String[] args)
{
float r, h;
Scanner s = new Scanner(System.in);
System.out.print(\"Enter the side of cone:\");
h = s.nextInt(); //side of a cone
System.out.print(\"Enter the radius of cone:\");
r = s.nextInt(); //bottom radius of cone
SurfaceArea b=new SurfaceArea(); //object to invoke the function called
b.compute(h,r); //calling function and passing arguements
}
void compute(float h,float r)
{
double area, pi = 3.14;
area = (pi * r * h) + (pi * r * r);
System.out.println(\"Surface Area of cone:\"+area);
}
}
.
1. # This program will take 2 numbers from the user and
# find the hypotenuse using the Pythagorean theorem
import math
# Function to square the numbers
def squarefunction(length):
square = length * length
print "The square of a side is: ", square
return square
# end of function
# Function to calculate Pythagorean theorem
def pythagorean(aside, bside):
HypotenuseSquared = aside + bside
hypotenuse = math.sqrt(HypotenuseSquared)
print "The hypotenuse of the 2 sides is: ", hypotenuse
# end of function
# Get the length of the sides from the user
firstside = input("Enter the first side: ")
secondside = input("Enter the second side: ")
# Get the squares of 2 sides
firstsidesquared = squarefunction(firstside)
secondsidesquared = squarefunction(secondside)
# print "The firstside variable is: ", firstside
# print "The secondside variable is: ", secondside
# Put the squares into the Pythagorean function
pythagorean(firstsidesquared, secondsidesquared)