
-
Текст программы на языке программирования с#.
Программа реализована в двух формах.
Текст программы Form1:
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 WindowsFormsApplication49
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Переход на новую форму для представления комплексного числа на плоскости
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button7_Click(object sender, EventArgs e)
{
Form2 f1 = new Form2();
f1.Show();
}
private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Программа предназначена для работы с комплексными числами. Возможно реализовать сложение, вычитание, умножение и деление числа, представленного в алгебраической форме, а также перевод результата арифметических действий в показательную форму, нахождение модуля и аргумента комплексного числа. В программе также имеется возможность изображения комплексного числа на плоскости.");
}
/// <summary>
/// Обработка события "нажатие на кнопку"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true) //Сложение
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = Convert.ToInt32(textBox3.Text);
int d = Convert.ToInt32(textBox4.Text);
int x = a + c;
int y = b + d;
textBox5.Text = x.ToString();
textBox6.Text = y.ToString();
}
if (checkBox2.Checked == true) //Вычитание
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = Convert.ToInt32(textBox3.Text);
int d = Convert.ToInt32(textBox4.Text);
int x = a - c;
int y = b - d;
textBox5.Text = x.ToString();
textBox6.Text = y.ToString();
}
if (checkBox3.Checked == true) // Умножение
{
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c = Convert.ToInt32(textBox3.Text);
int d = Convert.ToInt32(textBox4.Text);
int x = a * c - b * d;
int y = a * d + b * c;
textBox5.Text = x.ToString();
textBox6.Text = y.ToString();
}
if (checkBox4.Checked == true) // Деление
{
double a = Convert.ToDouble(textBox1.Text);
double b = Convert.ToDouble(textBox2.Text);
double c = Convert.ToDouble(textBox3.Text);
double d = Convert.ToDouble(textBox4.Text);
double x = (a * c + b * d) / (Math.Pow(c, 2) + Math.Pow(d, 2));
double y = (b * c - a * d) / (Math.Pow(c, 2) + Math.Pow(d, 2));
textBox5.Text = x.ToString();
textBox6.Text = y.ToString();
}
if (checkBox5.Checked == true) // Модуль
{
int a = Convert.ToInt32(textBox5.Text);
int b = Convert.ToInt32(textBox6.Text);
double mod = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
textBox7.Text = mod.ToString();
}
if (checkBox6.Checked == true) // Аргумент
{
double a = Convert.ToDouble(textBox5.Text);
double b = Convert.ToDouble(textBox6.Text);
double KSI = (Math.Atan(b / a) * 180) / Math.PI;
textBox10.Text = KSI.ToString();
}
}
/// <summary>
/// Очистка
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox8.Clear();
textBox9.Clear();
textBox7.Clear();
textBox10.Clear();
}
/// <summary>
/// Представление результата вычислений в показательной форме
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
double a = Convert.ToDouble(textBox5.Text);
double b = Convert.ToDouble(textBox6.Text);
double A = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
textBox8.Text = A.ToString();
double KSI = (Math.Atan(b / a) * 180) / Math.PI;
textBox9.Text = KSI.ToString();
}
/// <summary>
/// Выход из программы (кнопка на форме)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Хотите выйти из программы?",
"Завершение", MessageBoxButtons.YesNo) == DialogResult.Yes)
Application.Exit();
}
/// <summary>
/// Выход из программы (в меню)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void выходToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Хотите выйти из программы?",
"Завершение", MessageBoxButtons.YesNo) == DialogResult.Yes)
Application.Exit();
}
}
}
Текст программы Form2:
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 WindowsFormsApplication49
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
/// <summary>
/// Представление комплексного числа на комплексной плоскости
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
double a = Convert.ToDouble(textBox1.Text);
double b = Convert.ToDouble(textBox2.Text);
double A = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
textBox3.Text = A.ToString();
double KSI = (Math.Atan(b / a) * 180) / Math.PI;
textBox4.Text = KSI.ToString();
double x, y, k=0, f1 = 0;
double f0 = Convert.ToDouble(textBox4.Text);
if (f0 > 0 && f0 < 90)
{
f1 = f0 * Math.PI / 180;
k = Math.Tan(f1);
for (x = 0; x <= 180; x += 0.01)
{
y = k * x;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
if (f0 > 90 && f0 < 180)
{
f1 = f0 * Math.PI / 180;
k = Math.Tan(f1);
for (x = -180; x <= 0; x += 0.01)
{
y = k * x;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
if (f0 > 180 && f0 < 270)
{
f1 = f0 * Math.PI / 180;
k = Math.Tan(f1);
for (x = -180; x <= 0; x += 0.01)
{
y = k * x;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
if (f0 > 270 && f0 < 360)
{
f1 = f0 * Math.PI / 180;
k = Math.Tan(f1);
for (x = 0; x <= 180; x += 0.01)
{
y = k * x;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
if (f0 > 89 && f0<91)
{
for (y = 0; y <= 180; y += 0.01)
{
x = 1;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
if (f0 > 179 && f0 < 181)
{
for (x = -180; x <=0 ; x += 0.01)
{
y = 1;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
if (f0 > 269 && f0 < 271)
{
for (y = -180; y <= 0; y += 0.01)
{
x = 1;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
if (f0 > 359 && f0 < 361)
{
for (x = 0; x <= 180; x += 0.01)
{
y = 1;
chart2.Series["Series1"].Points.AddXY(x, y);
}
}
}
/// <summary>
/// Очистка графика
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
chart2.Series[0].Points.Clear();
}
/// <summary>
/// Очистка TextBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
}
}
}