—-form———–
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cone
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double side, height;
double radius, area;
double volume;
classComputation a = new classComputation();
try
{
side = Convert.ToDouble(txtSide.Text);
height = Convert.ToDouble(txtHeight.Text);
radius = Convert.ToDouble(txtRadius.Text);
area = a.computeArea(radius, side);
txtArea.Text = area.ToString();
volume = a.computeVolume(radius, height);
txtVolume.Text = volume.ToString();
}
catch (FormatException ex){
MessageBox.Show(“Invalid Input!”);
}
}
}
}
—-class———
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cone
{
class classComputation
{
public double computeArea(double r, double s)
{
double pie = 3.1416;
double a;
a = pie * r * s;
return a;
}
public double computeVolume(double r, double h)
{
double pie = 3.1416;
double v;
v = pie * 1/3 * Math.Pow(r, 2) * h;
//nv = Math.PI * 1 / 3 * Math.pow(nr, 2) * nh;
return v;
}
}
}
