.NET 4.x Выделить отдельный класс двоичных чисел - C#
Формулировка задачи:
Здравствуйте, нужна помощь, в программировании полный ноль, написал кое-как простенький калькулятор, дали задание "выделить отдельный класс двоичных чисел; вызываем объект класса из формы", скажите, как это сделать?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace calcul
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static double sum(double a, double b)
{
return a + b;
}
public static double razn(double a, double b)
{
return a - b;
}
public static double umnog(double a, double b)
{
return a * b;
}
public static double del(double a, double b)
{
return a / b;
}
public static double step(double a, double b)
{
return Math.Pow(a, b);
}
public static double koren(double a, double b)
{
return Math.Pow(a, 1/b);
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = button1.Text;
textBox3.Text = Convert.ToString(sum(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)));
}
private void button2_Click(object sender, EventArgs e)
{
label1.Text = button2.Text;
textBox3.Text = Convert.ToString(razn(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)));
}
private void button3_Click(object sender, EventArgs e)
{
label1.Text = button3.Text;
textBox3.Text = Convert.ToString(umnog(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)));
}
private void button4_Click(object sender, EventArgs e)
{
label1.Text = button4.Text;
textBox3.Text = Convert.ToString(del(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)));
}
private void button5_Click(object sender, EventArgs e)
{
label1.Text = button5.Text;
textBox3.Text = Convert.ToString(step(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)));
}
private void button6_Click(object sender, EventArgs e)
{
label1.Text = button6.Text;
textBox3.Text = Convert.ToString(koren(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)));
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
int i = Convert.ToInt32(textBox3.Text);
if (radioButton1.Checked == true)
{
textBox4.Text = Convert.ToString(i, 2);
}
else if (radioButton2.Checked == true)
{
textBox4.Text = Convert.ToString(i, 16);
}
else if (radioButton3.Checked == true)
{
textBox4.Text = Convert.ToString(i, 8);
}
}
//перевод в двоичную систему счисления
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
int i = Convert.ToInt32(textBox3.Text);
textBox4.Text = Convert.ToString(i, 2);
}
//перевод в шестнадцатеричную систему счисления
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
int i = Convert.ToInt32(textBox3.Text);
textBox4.Text = Convert.ToString(i, 16);
}
//перевод в восьмеричную систему счисления
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
int i = Convert.ToInt32(textBox3.Text);
textBox4.Text = Convert.ToString(i, 8);
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}Решение задачи: «.NET 4.x Выделить отдельный класс двоичных чисел»
textual
Листинг программы
public class OtdelnyKlassDvoichnyhChisel
{
public string ConvertToBinary(int x)
{
return Convert.ToString(x, 2);
}
}
public partial class Form1 : Form
{
private OtdelnyKlassDvoichnyhChisel _myObject;
public Form1 ()
{
InitializeComponent();
_myObject = new OtdelnyKlassDvoichnyhChisel ();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
int i = Convert.ToInt32(textBox3.Text);
textBox4.Text = _myObject.ConvertToBinary(i);
}
}