- 积分
- -9884
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
[code=csharp]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 triArea3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class Triangle
{
private double sideA;
private double sideB;
private double sideC;
public Triangle()
{
}
public Triangle(double sA)
{
sideA = sideB = sideC = sA;
}
public double SideA
{
get
{
return sideA;
}
set
{
sideA = value;
}
}
public double SideB
{
get
{
return sideB;
}
set
{
sideB = value;
}
}
public double SideC
{
get
{
return sideC;
}
set
{
sideC = value;
}
}
public bool test()
{
if ((sideA + sideB > sideC) && (sideB + sideC > sideA) && (sideC + sideA > sideB))
return true;
else
return false;
}
public double triCir()
{
double tCir = sideA + sideB + sideC;
return tCir;
}
public double triArea()
{
double p = (sideA + sideB + sideC) / 2;
double tarea = Math.Sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
return tarea;
}
}
private void button1_Click(object sender, EventArgs e)
{
Triangle tri1 = new Triangle(0);
double s1, s2, s3, trcir, trarea;
bool t;
s1 = double.Parse(textBox1.Text);
s2 = double.Parse(textBox2.Text);
s3 = double.Parse(textBox3.Text);
tri1.SideA = s1;
tri1.SideB = s2;
tri1.SideC = s3;
t = tri1.test();
if (!t)
{
MessageBox.Show("不能构造成三角形请重新输入");
textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = textBox5.Text = string.Empty;
return;
}
trcir = tri1.triCir();
trarea = tri1.triArea();
textBox4.Text = trcir.ToString();
textBox5.Text = trarea.ToString();
if (tri1.SideA == tri1.SideB && tri1.SideB == tri1.SideC)
textBox6.Text = "等边三角形边长为:" + tri1.SideA + "厘米";
else
textBox6.Text = "三角形三边长分别为:" + tri1.SideA + "厘米" + tri1.SideB + "厘米" + tri1.SideC + "厘米";
}
private void frmTriangle_Load(object sender, EventArgs e)
{
double s1, s2, s3, trcir, trarea;
Triangle tri1 = new Triangle(0);
s1 = double.Parse(textBox1.Text);
s2 = double.Parse(textBox2.Text);
s3 = double.Parse(textBox3.Text);
textBox1.Text = s1.ToString();
textBox2.Text = s3.ToString();
textBox3.Text = s3.ToString();
trcir = tri1.triCir();
trarea = tri1.triArea();
textBox4.Text = trcir.ToString();
textBox5.Text = trcir.ToString();
if (tri1.SideA == tri1.SideB && tri1.SideB == tri1.SideC)
textBox6.Text = "等边三角形边长为:" + tri1.SideA + "厘米";
else
textBox6.Text = "三角形三边长分别为:" + tri1.SideA + "厘米" + tri1.SideB + "厘米" + tri1.SideC + "厘米";
}
}
}
[/code] |
|