Your cousins Jimmy and Jenna (JJ) and studying geometry in school and need some help understanding the relationship between geometric shapes. You’ve offered to help with your newfound C# skills. Write a program that implements programmer defined methods for the following geometric functions – use double variables for all your calculations. a. Compute the area of a circle – method should have one parameter, the radius, and return the area b. Compute the circumference of a circle – method should have one parameter, the radius, and return the circumference c. Compute the area of a square – method should have one parameter, length of a side, and return the area d. Compute the perimeter of a square – method should have one parameter, length of a side, and return the perimeter e. Compute the area of a triangle – method should have two parameters, the base and height, and return the area Your program should use FIVE programmer‐defined methods (one for each of the calculations). Each method should have parameters and return the desired calculation. Your program should ask for values in Main(), call the procedures, and then output the returned value in Main().
Code
class GeometryShape
{
static void Main(string[] args)
{
string userChoice;
while(true)
{
menu();
userChoice = Console.ReadLine();
Console.WriteLine();
if (userChoice == "a" || userChoice == "b")
{
double radius;
Console.Write("Enter the radius of the circle: ");
radius = Convert.ToDouble(Console.ReadLine());
if (userChoice == "a")
{
Console.WriteLine("Area of the circle :" +
calculateCircleArea(radius));
}
else
{
Console.WriteLine("Circumference of the circle :" +
calculateCirclecircumference(radius));
}
}
else if (userChoice == "c" || userChoice == "d")
{
double length;
Console.Write("Enter the length of the square: ");
length = Convert.ToDouble(Console.ReadLine());
if (userChoice == "c")
{
Console.WriteLine("Area of the square :" +
calculateSquareArea(length));
}
else
{
Console.WriteLine("Perimeter of the square :" +
calculateSquareperimeter(length));
}
}
else if (userChoice == "e")
{
double b, h;
Console.Write("Enter base of the triangle: ");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter height of the triangle: ");
h = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Area of the triangle :" +
calculateTriangleArea(b, h));
}
else if (userChoice == "q")
break;
else
Console.WriteLine("Invalid choice!");
Console.WriteLine();
}
}
private static double calculateTriangleArea(double b, double
h)
{
return (b * h) / 2;
}
private static double calculateSquareperimeter(double
length)
{
return 4 * (length);
}
private static double calculateSquareArea(double length)
{
return length * length;
}
private static double calculateCirclecircumference(double
radius)
{
return 2 * Math.PI * radius;
}
private static double calculateCircleArea(double radius)
{
return Math.PI * radius*radius;
}
private static void menu()
{
Console.WriteLine("a. Compute the area of a circle");
Console.WriteLine("b. Compute the circumference of a
circle");
Console.WriteLine("c. Compute the area of a square");
Console.WriteLine("d. Compute the perimeter of a square");
Console.WriteLine("e. Compute the area of a triangle");
Console.WriteLine("q. Quit");
Console.Write("Enter you choice: ");
}
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
Your cousins Jimmy and Jenna (JJ) and studying geometry in school and need some help understanding...
Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....
You will be creating a driver class and 5 class files for this assignment. The classes are Shape2D (the parent class), Circle, Triangle, and Rectangle (all children of Shape2D) and Square (child of Rectangle). Be sure to include a message to the user explaining the purpose of the program before any other printing to the screen. Within the driver class, please complete the following tasks: Instantiate a Circle object with 1 side and a radius of 4; print it Update...
Java... Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: • circles -- area = π*radius^2 (format the answer to have two decimal places) • rectangles -- area = width * length • trapezoid -- area = (base1 + base2) * height/2 Because the three methods are to be overloaded, they should each have the same name, but different parameters (for example, the method to be used with circles should only...
C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
Please show all work and answer all parts using python, thanks! Instructions You will need to create four files: • Shape2D.py - file containing a class definition containing properties all Shapes could possibly have. • Circle.py - file containing a class definition of a Circle that inherits from the Shape2D class. Square.py - file containing a class definition of a Square that inherits from the Shape2D class. • testFile.py - file containing pytest functions testing the Shape2D, Circle, and Square...
A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...
Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Instructions Ensure the class file named Rectangle.cpp is open in your editor. In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double. Write public set methods to set the values for lengthand width. Write public...
Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...
Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { } //get method (Accessor Methods ) public double getRadius (...