S
sox123
Guest
Hi all, I'm currently working on a 2 part homework assignment - first part being writing a program that generates values based on functions and then displays them in a table. The second part being taking these generated values and drawing them in a separate 'Form2' that displays it on an X/Y axis.
Now, the first part is complete but I really cant figure out how to get the second part done and was hoping someone could point me in the right direction.
The form1 code:
namespace MD2._5
{
public partial class Form1 : Form
{
int step;
int xEnd, xBegin;
double a, b, c;
public delegate double DY(double a, double b, double c, int x); //declares delegate
public static double Y0(double a, double b, double c, int x) //Functions that do the calculations
{
return Math.Round(a * (x * x) + (b * x + c), 2);
}
public static double Y1(double a, double b, double c, int x)
{
return Math.Round((a / (x * x)) + (b / x + c), 2);
}
public static double Y2(double a, double b, double c, int x)
{
return Math.Round(((a * x) + b) / ((a * x) + c), 2);
}
public DY[] Y = new DY[3] { Y0, Y1, Y2 }; //New array of the above functions
private void radioButton1_Click(object sender, EventArgs e)
{
int buttonPressed = Convert.ToInt32(((RadioButton)sender).Tag);
DoTable(Y[buttonPressed]);
}
private void DoTable(DY y) //Prints the table
{
richTextBox1.Clear();
richTextBox1.AppendText(" X Y \n");
c = Convert.ToInt32(textBoxC.Text);
b = Convert.ToInt32(textBoxB.Text);
a = Convert.ToInt32(textBoxA.Text);
step = Convert.ToInt32(stepText.Text);
xEnd = Convert.ToInt32(x_end.Text);
xBegin = Convert.ToInt32(x_begin.Text);
for (int x = xBegin; x <= xEnd; x += step)
{
richTextBox1.AppendText("\n " + x.ToString() + "\t " + y(a, b, c, x).ToString());
}
}
Form2 f2; //creates an instance of form2
private void button2_Click(object sender, EventArgs e) //Graphics button that generates a new form
{
f2 = new Form2();
f2.ShowDialog();
}
}
}
And that generates this:
And when you click on the 'Graphics' button it comes up with:
But the end result should be something like this (the dots representing the values in Y column on the first pic):
Sorry its a bit long, but thought its necessary to really encapsulate the whole thing.
Now im struggling with understanding how I would translate the whole thing to a drawn picture - keeping in mind that this code should be on Form2.
Can anyone point me in the right direction?
Thank you
Continue reading...
Now, the first part is complete but I really cant figure out how to get the second part done and was hoping someone could point me in the right direction.
The form1 code:
namespace MD2._5
{
public partial class Form1 : Form
{
int step;
int xEnd, xBegin;
double a, b, c;
public delegate double DY(double a, double b, double c, int x); //declares delegate
public static double Y0(double a, double b, double c, int x) //Functions that do the calculations
{
return Math.Round(a * (x * x) + (b * x + c), 2);
}
public static double Y1(double a, double b, double c, int x)
{
return Math.Round((a / (x * x)) + (b / x + c), 2);
}
public static double Y2(double a, double b, double c, int x)
{
return Math.Round(((a * x) + b) / ((a * x) + c), 2);
}
public DY[] Y = new DY[3] { Y0, Y1, Y2 }; //New array of the above functions
private void radioButton1_Click(object sender, EventArgs e)
{
int buttonPressed = Convert.ToInt32(((RadioButton)sender).Tag);
DoTable(Y[buttonPressed]);
}
private void DoTable(DY y) //Prints the table
{
richTextBox1.Clear();
richTextBox1.AppendText(" X Y \n");
c = Convert.ToInt32(textBoxC.Text);
b = Convert.ToInt32(textBoxB.Text);
a = Convert.ToInt32(textBoxA.Text);
step = Convert.ToInt32(stepText.Text);
xEnd = Convert.ToInt32(x_end.Text);
xBegin = Convert.ToInt32(x_begin.Text);
for (int x = xBegin; x <= xEnd; x += step)
{
richTextBox1.AppendText("\n " + x.ToString() + "\t " + y(a, b, c, x).ToString());
}
}
Form2 f2; //creates an instance of form2
private void button2_Click(object sender, EventArgs e) //Graphics button that generates a new form
{
f2 = new Form2();
f2.ShowDialog();
}
}
}
And that generates this:
And when you click on the 'Graphics' button it comes up with:
But the end result should be something like this (the dots representing the values in Y column on the first pic):
Sorry its a bit long, but thought its necessary to really encapsulate the whole thing.
Now im struggling with understanding how I would translate the whole thing to a drawn picture - keeping in mind that this code should be on Form2.
Can anyone point me in the right direction?
Thank you
Continue reading...