Hi, this project is for C# programming in Microsoft Visual Studio. I would great
ID: 3791269 • Letter: H
Question
Hi, this project is for C# programming in Microsoft Visual Studio. I would greatly appreciate any help!! I attached the code I have so far however, I dont know if any of it is correct.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project2
{
class shapecalc
{
static void Main(string[] args)
{
int choice, l, h, s, w, d1, d2, b, r, lb, sb;
double area=0;
Console.WriteLine(" ");
Console.WriteLine("Shape Area Calculator: ");
Console.WriteLine("*****************************************************************");
Console.WriteLine(" ");
Console.WriteLine("Please select the number of the operation you would like to perform:");
Console.WriteLine("1. Circle");
Console.WriteLine("2. Square");
Console.WriteLine("3. Rectangle");
Console.WriteLine("4. Rhombus");
Console.WriteLine("5. Parallelogram");
Console.WriteLine("6. Trapezoid");
Console.WriteLine("7. Exit");
Console.WriteLine(" ");
Console.WriteLine("********************************************************************");
Console.WriteLine("Select a shape type to calculate : ");
choice = Convert.ToInt32(Console.ReadLine());
switch(choice)
static private void CalculateCircle()
{
Console.WriteLine("Enter the length of the radius of the Circle (-1 to exit back to menu) : ");
r = double.Parse(Console.ReadLine());
Console.WriteLine("Area of Circle is:{0}", 3.14 * r * r);
}
static private void CalculateRectangle()
{
Console.WriteLine("Enter the length of on side of the rectangle (-1to exit back to menu) : ");
l = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the width of the Rectangle");
w = double.Parse(Console.ReadLine());
Console.WriteLine("Area of rectangle is :{0}", l * w);
}
static private void CalculateSquare()
{
Console.WriteLine("Enter the length of one side of the square (-1 to exit back to menu) : ");
s = double.Parse(Console.ReadLine());
Console.WriteLine("Area of Square is:{0}", s * s);
}
static private void CalculateRhombus()
{
Console.WriteLine("Enter the length of one diagonal of the rhombus (-1 to exit back to menu) : ");
d1 = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the length of the other diagonal of the rhombus (-1 to exit back to menu : ");
d2 = double.Parse(Console.ReadLine());
Console.WriteLine("Area of the Rhombus is : {0}", (d1 * d2) / 2);
}
static private void CalculateParallelogram()
{
Console.WriteLine("Enter the length of the base of the parallelogram (-1 to exit back to menu) : ");
b = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the height of the parallelogram (-1 to exit back to menu) : ");
h = double.Parse(Console.ReadLine());
Console.WriteLine("Area of the Parallelogram is : {0}", b * h);
}
static private void CalculateTrapezoid()
{
Console.WriteLine("Enter the length of the large base of the trapezoid (-1 to exit back to menu) : ");
lb = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the length of the small base of the trapezoid (-1 to exit back to menu) : ");
sb = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the height of the trapezoid (-1 to exit back to menu) : ");
h = double.Parse(Console.ReadLine());
Console.WriteLine("Area of the Parallelogram is : {0}", (lb + sb) * (h / 2));
}
}
}
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project2
{
class shapecalc
{
public float l, h, s, w, d1, d2, b, r, lb, sb;
static void Main(string[] args)
{
shapecalc a = new shapecalc();
Console.WriteLine(" ");
Console.WriteLine("Shape Area Calculator: ");
Console.WriteLine("*****************************************************************");
Console.WriteLine(" ");
Console.WriteLine("Please select the number of the operation you would like to perform:");
Console.WriteLine("1. Circle");
Console.WriteLine("2. Square");
Console.WriteLine("3. Rectangle");
Console.WriteLine("4. Rhombus");
Console.WriteLine("5. Parallelogram");
Console.WriteLine("6. Trapezoid");
Console.WriteLine("7. Exit");
Console.WriteLine(" ");
Console.WriteLine("********************************************************************");
Console.WriteLine("Select a shape type to calculate : ");
choice = Convert.ToInt32(Console.ReadLine());
switch(choice)
{
case1:
{
a.circle();
break;
}
case2:
{
a.square();
break;
}
case3:
{
a.rectangle();
break;
}
case4:
{
a.rhombus();
break;
}
case5:
{
a.parallelogram();
break;
}
case6:
{
a.trapezoid();
break;
}
case7:
break;
console.ReadKey();
}
}
}
}
public void circle()
{
console.WriteLine("enter the radius of the circle");
radius = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Area of Circle is:{0}", 3.14 * radius * radius);
}
public void Square()
{
Console.WriteLine("Enter the side of a square");
side = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Area of Square is:{0}", side * side);
}
public void rectangle()
{
Console.WriteLine("Enter the length of the rectangle");
l = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Enter the width of the rectangle");
w = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Area of rectangle is :{0}", l * w);
}
public void rhombus()
{
Console.WriteLine("Enter thelength of one diagonal of the rhombus");
d1 = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Enter thelength of other diagonal of the rhombus");
d2 = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Area of the Rhombus is : {0}", (d1 * d2) / 2 );
}
public void parallelogram()
{
Console.WriteLine("Enter the length of the base of the parallelogram");
b = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Enter the height of the base of the parallelogram");
h = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Area of the Parallelogram is : {0}", b * h );
}
public void Trapezoid()
{
Console.WriteLine("Enter the length of the large base of the trapezoid");
lb = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Enter the length of the small base of the trapezoid");
sb = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Enter the height of the trapezoid");
h = float.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Area of parallelogram is:{0}",(lb + sb) * (h / 2));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.