Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# visual studio: Create an application with four classes. Three of the classes

ID: 3683596 • Letter: C

Question

C# visual studio: Create an application with four classes. Three of the classes should contain data and behavior characteristics for circle, rectangle, and cylinder. You could extend your solution to problem number 6 and provide behaviors based on the type of object instantiated. For example, in addition to calculating the area of a circle, also provide methods to calculate circumference or radius. For the rectangle, consider providing behaviors to calculate perimeter and or the polygon diagonals. For cylinder, consider providing behaviors to calculate the volume and or surface area for a closed cylinder. The fourth class should allow the user to input a figure type from a menu of options. Prompt for appropriate values based on the inputted figure type, instantiate an object of the type entered, and display characteristics about the object.

Explanation / Answer

using System.IO;
using System;

class Circle
{
float radius;
double area;
public
void getdata()
{
Console.WriteLine("Enter the radius");
radius=Int32.Parse(Console.ReadLine());
Console.ReadLine();
}
void calculate_area()
{
area=radius*radius*3.14;
Console.WriteLine("Area : {0}", area);
Console.ReadLine();
}
};

class Rectangle
{
int length;
int breadth;
int perimeter;
public
void getdata()
{
Console.WriteLine("Enter the length");
length=Int32.Parse(Console.ReadLine());
Console.ReadLine();
Console.WriteLine("Enter the breadth");
breadth=Int32.Parse(Console.ReadLine());
Console.ReadLine();
}
void calculate_perimeter()
{
perimeter=2*(length + breadth);
Console.WriteLine("perimeter : {0}", perimeter);
Console.ReadLine();
}
};
class Cylinder
{
int radius;
int height;
double volume;
public
void getdata()
{
Console.WriteLine("Enter the radius");
radius=Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the height");
height=Int32.Parse(Console.ReadLine());   
Console.ReadLine();
}
void calculate_volume()
{
volume=3.14*radius*radius *height;
Console.WriteLine("volume : {0}", volume);
Console.ReadLine();
}
};

class Program
{
static void Main()
{
int opt;
Console.WriteLine("1. CIRCLE");
Console.ReadLine();
Console.WriteLine("2. RECTANGLE");
Console.ReadLine();
Console.WriteLine("3. CYLINDER");
Console.ReadLine();
opt=Int32.Parse(Console.ReadLine());
switch(opt)
{
case 1:Circle c=new Circle();
c.getdata();
c.calculate_radius();
break;
case 2: Rectangle r=new Rectangle();
r.getdata();
r.calculate_perimeter();
break;
case 3: Cylinder c1=new Cylinder();
c1.getdata();
c1.calculate_volume();
break;
default:
Console.WriteLine("Invalid entry");
break;
}
  

  
}
}