Изменить программу так чтобы класс был отдельно - 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;
using System.Windows.Forms;
namespace lab71
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double f(double x)
{
double f;
if (x <= 0) f = x * x - 1;
else if (x > 1.5) f = Math.Sin(x - 1);
else f = Math.Cos(x);
return f;
}
void regclick(double a, double b, double h)
{
double y, x = a;
listBox1.Items.Clear();
listBox2.Items.Clear();
int n = Convert.ToInt32(Math.Floor((b - a) / h))+1;
for (int i = 1; i <= n; i++)
{
y = f(x);
listBox1.Items.Add(x);
listBox2.Items.Add(y);
x = x + h;
}
}
private void button1_Click(object sender, EventArgs e)
{
double a, b, h;
a = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);
h = Convert.ToDouble(textBox3.Text);
regclick(a, b, h);
}
}
}Решение задачи: «Изменить программу так чтобы класс был отдельно»
textual
Листинг программы
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double a, b, h;
a = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);
h = Convert.ToDouble(textBox3.Text);
var lst = Myclass.regclick(a, b, h);
listBox1.Items.Clear();
listBox2.Items.Clear();
foreach (var v in lst)
{
listBox1.Items.Add(v.X);
listBox2.Items.Add(v.Y);
}
}
}
class Myclass
{
private static double f(double x)
{
double f;
if (x <= 0) f = x * x - 1;
else if (x > 1.5) f = Math.Sin(x - 1);
else f = Math.Cos(x);
return f;
}
public static List<PointF> regclick(double a, double b, double h)
{
double y, x = a;
var lst = new List<PointF>();
int n = Convert.ToInt32(Math.Floor((b - a) / h)) + 1;
for (int i = 1; i <= n; i++)
{
y = f(x);
lst.Add(new PointF((float)x, (float)y));
x = x + h;
}
return lst;
}
}
}