C + + window design attempt

Source: Internet
Author: User
Tags cmath

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?
  1. #include <iostream>   
  2. #include <cmath>   
  3. UsingNamespace std;
  4. int Main ()
  5. {
  6. float a,b,c,x1,x2;
  7. cin>>a>>b>>c;
  8. if ((b*b-4*a*c) >=0)
  9. {
  10. if((b*b-4*a*c) >0)
  11. {
  12. X1= (-b+sqrt (B*b-4*a*c))/(2*A);
  13. X2= (-b-sqrt (B*b-4*a*c))/(2*A);
  14. cout<< "Two unequal real roots, respectively: x1=" <<x1<< "," "x2="  <<x2<<endl;
  15. }
  16. Else
  17. {
  18. x1=-b/(2*a);
  19. cout<< "Two equal real roots, x1=x2="  <<x1<<endl;
  20. }
  21. }
  22. Else
  23. cout<< "Equation without real roots"  <<endl;
  24. return 0;
  25. }
#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.