Thread: Quadrtic equation solver with graphics.

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    91

    Quadrtic equation solver with graphics.

    Hello,

    I want to make a Quadratic equation aolver with Graphics and am wondering the best way to go about it?

    I have written the programme in C++ but want to add graphical display, i.e. display the output in a windows style box, add colour, and make add some buttons.

    Would visual basic be the best thing, or, could you use say c++ and opengl or directx,

    I dont have Viusal C++. Well i've been looking everywhere for the answer but still havent found one. Thanks.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Depends what you want to do really. If you just want to draw a quadratic in a Window, and add a few controls, C/C++ and the Win32 API is far easier than DX or OpenGL. For both, an understanding of the API would be a pre-requisite anyway.

    Without more of a spec, it's difficult to advise further.

    You don't need VC to write graphical Windows programs. Try to copile this and see what happens.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Okay, so it didn't take the attactment, try again...

    I've moved this to the Windows board as it is Windows specific.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    Ok heres my programme, it factors quadratic equations.

    But displaying it in a DOS box isnt that interesting for school kids so i want to run this programme in a fancy window with button options etc... I still have no idea how i'm going to do this.


    #include <iostream>
    #include <conio.h>
    #include <cmath>
    #include <ctime>

    using namespace std;

    int gcd (int d, int e) { // defining the greatest common factor function
    int temp;
    while (e != 0) {
    temp = d % e;
    d = e;
    e = temp;
    }
    return d;
    }

    int main ()

    {

    time_t mytime;
    struct tm *times;
    times = localtime(&mytime);
    time (&mytime);
    cout << "Current date and time is: " << ctime(&mytime) << endl;
    cout<<""<<endl;
    cout<<"This program returns the factors for any quadratic equation whose discriminant is a perfect square"<<endl;
    cout<<""<<endl;
    cout<<""<<endl;
    cout<<"press any key to continue........";
    getch();

    int a=0,b=0,c=0;
    int p=0,i=0,r=0,x=0;



    char key='Y';
    while (key=='Y' || key=='y' )
    {
    int root=0;
    system("cls");


    cout<<"Enter coefficients a , b , c for ax^2 + bx + c"<<endl;
    cout<<""<<endl;
    cout<<"a = ";cin>>a;
    cout<<"b = ";cin>>b;
    cout<<"c = ";cin>>c;
    cout<<""<<endl;

    if(b*b-4*a*c<0){ // condition for imaginary roots

    cout<<"The roots are undefined"<<endl;
    cout<<""<<endl;
    cout<<"Do you want to try again y/n ?"<<endl;
    cout<<""<<endl;
    cin>>key;
    }

    else{

    root = (b*b-4*a*c);

    if(root==4){root=root/2;} if(root==9){root=root/3;}if(root==16){root=root/4;}if(root==25) {root=root/5;}if(root==36) {root=root/6;} if(root==49) { root=root/7;}
    if(root==64) {root=root/8;} if(root==81) { root=root/9;} if(root==100) {root=root/10;}if(root==121){ root=root/11;}if(root==144) {root=root/12;}if(root==169) {root=root/13;}
    if(root==196) {root=root/14;} if(root==225) { root=root/15;} if(root==256) {root=root/16;}if(root==289) {root=root/17;}if(root==324) {root=root/18;}if(root==361) {root=root/19;}if(root==400) {root=root/20;}
    if(root==441) {root=root/21;}if(root==484) {root=root/22;}if(root==529) {root=root/23;}if(root==576) {root=root/24;}
    if(root==625) {root=root/25;}if(root==676) {root=root/26;}if(root==729) {root=root/27;}if(root==784) {root=root/28;}
    if(root==841) {root=root/29;}if(root==900) {root=root/30;}



    p = (2*a);
    i = -(-b-((root)));
    r = -(-b+((root)));

    if (i>0 && r>0){
    cout<<"The factors are ("<<p/gcd((i),p)<<"x + "<<i/gcd(i,p)<<")"<<"("<<p/gcd(r,p)<<"x + "<<r/gcd(r,p)<<")"<<endl;
    cout<<""<<endl;
    }
    else if(i<0 && r<0){
    cout<<"The factors are ("<<p/gcd((i),p)<<"x "<<i/gcd(i,p)<<")"<<"("<<p/gcd(r,p)<<"x "<<r/gcd(r,p)<<")"<<endl;
    cout<<""<<endl;
    }
    else if(i<0 && r>0){
    cout<<"The factors are ("<<p/gcd((i),p)<<"x "<<i/gcd(i,p)<<")"<<"("<<p/gcd(r,p)<<"x + "<<r/gcd(r,p)<<")"<<endl;
    cout<<""<<endl;
    }
    else if(i>0 && r<0){
    cout<<"The factors are ("<<p/gcd((i),p)<<"x + "<<i/gcd(i,p)<<")"<<"("<<p/gcd(r,p)<<"x + "<<r/gcd(r,p)<<")"<<endl;
    cout<<""<<endl;
    cout<<i<<" "<<r;
    }

    cout<<""<<endl;
    cout<<"Do you want to try again y/n ?"<<endl;
    cout<<""<<endl;
    cin>>key;


    }
    }
    return 0;

    }

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Fine, but the first thing we need to do is be sure you are able to build a Win32 Application. Compile the source I gave you and tell me if it works, then we can try to decide how to approach your design..

    There is absolutely no point discussing the details of a Win32 program if you can't compile one!

    When posting code use code tags, there is a sticky at the top of the forum that tells you how to do that.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    You know that C includes a square root function, right?

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    Yes the win32 source works fine, displays a blank window.

    And yes i know theres a square root function, but i get errors because i've got this GCD function in there. It gets very messy when you add the SQRT function.

    This programme is aimed at kids who need to learn the basics of solving quadratics into 2 brackets. Hopefully they will find it a bit more interesting than reading from a book.

    thanks .

  8. #8
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Take a look at this win32 tutorial:
    http://www.sunlightd.com/Windows/GUI/

    The third section shows how to make a dialog box program that solve quadratic equations, without showing a graph, though. Thought you may be interested.

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    OK, i get most of that apart from the 'resource editor' part .What is that is he talknig about something like visual basic ?

    cheers.

  10. #10
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    The resource editor he is talking about is a GUI that is included with the Visual C++ IDE. Instead of typing out the resource files manually, you can use the GUI as a WYSIWYG editor, and it makes the code for you.

  11. #11
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    ok im strating to make some progress here, im using the
    lcc-win32 IDE <-- ?? to create a dialogue box.

    Only problem is i cant work out how to save this box as an exe, it isnt in the manual i it doesnt seem obvious.
    any ideas.??

  12. #12
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I am not familiar with any resource editor other than the one that comes with MSVC++. Resources are normally saved as text files with the name programname.rc Try downloading an example win32 application that uses resources, and look at the resource files in a text editor.

  13. #13
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    If you are using lcc-win32 all you have to do is create a new project. When given the option select dialog application and ask for a skeleton app to be created. Then you will get the code automatically entered and the resource for a dialog box.

    All you have to do is compile the project and run it. Next, go to the resource editor and you may add buttons and controls to the dialog box. The manual has more information if you need it.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  14. #14
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    ok ive done all that , one last problem , how this dialogue box i created as an exe file, i cant seem to work it out, its not in the manual?

  15. #15
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    ok forget that about the exe,

    fixed this one as well.

    lol...the problems just keep a coming, now when i add the code to call the box up nothing happens ?

    nearly there
    Last edited by joeyzt; 07-17-2003 at 04:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  2. Linear Equation Solver
    By EvilGuru in forum C++ Programming
    Replies: 7
    Last Post: 10-22-2005, 10:10 AM
  3. IDEA: Equation solver
    By Magos in forum Contests Board
    Replies: 2
    Last Post: 01-07-2003, 11:46 AM