First, problem: find the root of the equation ax2+bx+c=0 two times. The value of A,b,c is entered at run time by the keyboard.
You can write the following program to complete the solution:
[CPP]View Plaincopyprint?
- #include <iostream>
- #include <cmath>
- UsingNamespace std;
- int Main ()
- {
- float a,b,c,x1,x2;
- cin>>a>>b>>c;
- if ((b*b-4*a*c) >=0)
- {
- if((b*b-4*a*c) >0)
- {
- X1= (-b+sqrt (B*b-4*a*c))/(2*A);
- X2= (-b-sqrt (B*b-4*a*c))/(2*A);
- cout<< "Two unequal real roots, respectively: x1=" <<x1<< "," "x2=" <<x2<<endl;
- }
- Else
- {
- x1=-b/(2*a);
- cout<< "Two equal real roots, x1=x2=" <<x1<<endl;
- }
- }
- Else
- cout<< "Equation without real roots" <<endl;
- return 0;
- }
#include <iostream> #include <cmath> usingnamespace std;int Main () { float a,b,c,x1,x2; cin>>a>>b>>c; if ((b*b-4*a*c) >=0) { if ((b*b-4*a*c) >0) { x1= (-b+sqrt (B*b-4*a*c))/(2*a); X2= (-b-sqrt (B*b-4*a*c))/(2*a); cout<< "Two unequal real roots are: x1=" <<x1<< "," "X2=" <<x2<<endl; } else { x1=-b/(2*a); cout<< "Two equal real roots, x1=x2=" <<x1<<endl; } else cout<< "equation no real Roots" <<endl;
Second, the development of Windows version of the program
Started my own window,
It is important to associate
Here is the graphical interface:
Key code:
void Cmy321dlg::onbutton1 () {//Todo:add your control notification handler code heredouble Delat; UpdateData ();d elat=m_b*m_b-4*m_a*m_c;if (delat>=0) {m_x1= (-m_b+sqrt (Delat))/(2*m_a); M_x2= (-m_b-sqrt (Delat))/(2*m_a);} Elsemessagebox ("Equation without real roots"); UpdateData (FALSE);}
Knowledge point application and experience:
This knowledge point is only now complete, found himself also pretty rotten.
C + + window design attempt