عند اختيار أحد التوابع المثلثية Sin(x) / Cos(x) / Tan(x) من القائمة المنسدلة comboBox1 تُحسب قيمته حسب قيمة الزاوية المدخلة في مربع النص textBox1 (بعد تحويلها إلى راديان) وتضاف النتيجة إلى لائحة البنود listBox1، مع معالجة أخطاء الإدخال. اكتب التعليمات.
أظهر إجابة سلّم التصحيح
try
{
double x, r;
x = double.Parse(textBox1.Text);
r = x * (Math.PI / 180);
string Cos = "Cos(" + x + ")=";
string Tan = "Tan(" + x + ")=";
string Sin = "Sin(" + x + ")=";
switch (comboBox1.SelectedItem.ToString())
{
case "Sin(x)":
listBox1.Items.Add(Sin + Math.Sin(r));
break;
case "Cos(x)":
listBox1.Items.Add(Cos + Math.Cos(r));
break;
case "Tan(x)":
listBox1.Items.Add(Tan + Math.Tan(r));
break;
}
}
catch
{
MessageBox.Show("ادخل رقم","خطأ ادخال",MessageBoxButtons.YesNo,MessageBoxIcon.Error);
}
{
double x, r;
x = double.Parse(textBox1.Text);
r = x * (Math.PI / 180);
string Cos = "Cos(" + x + ")=";
string Tan = "Tan(" + x + ")=";
string Sin = "Sin(" + x + ")=";
switch (comboBox1.SelectedItem.ToString())
{
case "Sin(x)":
listBox1.Items.Add(Sin + Math.Sin(r));
break;
case "Cos(x)":
listBox1.Items.Add(Cos + Math.Cos(r));
break;
case "Tan(x)":
listBox1.Items.Add(Tan + Math.Tan(r));
break;
}
}
catch
{
MessageBox.Show("ادخل رقم","خطأ ادخال",MessageBoxButtons.YesNo,MessageBoxIcon.Error);
}