vb绘制一元二次函数图形
求高手帮帮忙做一个绘制一元二次函数图形的程序,非常感谢!!!
Private Sub Form_Load() Dim i As Long, j As Long, k As Long, m As Long 'y = ax^2+bx+c 'Sample Function Do While i < 3 '依序輸入a,b,c的值~~若輸入錯誤則該項會一直跳出~直到正確輸入為止~ a = Val(InputBox("", "第 " & i + 1 & " 個字")) If a <> 0 Then ReDim Preserve Conster(i) Conster(i) = a i = i + 1 End If Loop If Conster(0) <> 0 And Conster(1) <> 0 Then a = Conster(0) '通過驗證後開始賦值~ b = Conster(1) c = Conster(2) 'x=(-b+√b^2-4ac/2a) and x=(-b-√b^2-4ac/2a) 再来算X值 End If
//方程 #include<cmath>//定义sqrt()函数 #include<iostream> using namespace std; int main() { float a,b,c; cout<<"Enter the coefficients of a quadratic equation:"<<endl; cin>>a>>b>>c; if (fabs(a)<=1e-6) { cout<<"This is not a quadratic equation: a==0\n"; return 0; } else cout<<"The equation is:"<<a<<"*x*x+"<<b<<"*x+"<<c<<"=0"<<endl; double d=b*b-4*a*c;//判别式 if (fabs(d)<=1e-6) { cout<<"This equation has no real solutions: d<0\n"; return 0; } else //double sqrtd=sqrt(d); double x1=(-b+sqrt(d))/(2*a); double x2=(-b-sqrt(d))/(2*a); cout<<"The solution are:"<<endl; cout<<"x1="<<x1<<endl; cout<<"x2="<<x2<<endl; cout<<"check:"<<endl; cout<<"\ta*x1*x1+b*x1+c="<<a*x1*x1+b*x1+c<<endl; cout<<"\ta*x2*x2+b*x2+c="<<a*x2*x2+b*x2+c<<endl; return 0; }