In: Computer Science
Create a working C# Program that will accept an input and has the following class.
areaCircle – computes the area of the circle
volumeCube – computes the volume of a cube
perimeterTraingle – computes the perimeter of a triangle
surfaceAreaRect – computes the surface area of a rectangle
*You may usePass by Value and/or Pass by Reference
*Using ConsoleApp
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShapeApp
{
class Program
{
public static double areaCircle(double radius)
{
return (Math.PI * radius * radius);
}
public static double volumeCube(double a)
{
return a * a * a ;
}
public static double perimeterTriangle(double a, double b,
double c)
{
return (a + b + c);
}
public static double surefaceAreaRect(double length, double
breadth)
{
return (length * breadth);
}
static void Main(string[] args)
{
//using Math.Round() - to get two decimal places
//area of circle
Console.Write("Enter a radius: ");
double radius = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area of a Circle:
"+Math.Round(areaCircle(radius),2));
//volume of a cube
Console.Write("\nEnter a length of the edge of a cube: ");
double a= Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The volume of Cube:
"+Math.Round(volumeCube(a),2));
//perimeter of a triangle
Console.Write("\nEnter value of Side1: ");
double side1= Convert.ToDouble(Console.ReadLine());
Console.Write("Enter value of Side2: ");
double side2 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter value of Side3: ");
double side3 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The perimeter of a Triangle:
"+Math.Round(perimeterTriangle(side1,side2,side3)),2);
//surface area of a rectangle
Console.Write("\nEnter the length of a rectangle: ");
double l = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the breadth of a rectangle: ");
double w = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The surface area of a rectangle:
"+Math.Round(surefaceAreaRect(l,w)),2);
Console.ReadKey();
}
}
}
Output: