Graphing Calculator..

This is a discussion on Graphing Calculator.. within the Windows Programming forums, part of the Platform Specific Boards category; hey..i was wondering how hard it would be to write a graphing calculator. like, what kind of understanding would it ...

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    Graphing Calculator..

    hey..i was wondering how hard it would be to write a graphing calculator. like, what kind of understanding would it take to make such a thing? and how would dealing with variables (such as: Y1 = 3x-2) work? is anyone aware of a tutorial dealing with the knowledge needed? i did a search on google but i'm unsure what to search for and the one i did didn't come up with anything..

    thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You're probably not going to find a tutorial on "How to make a graphing calculator program". If there were tutorials for every kind of program, we wouldn't need programmers, now would we?

    You'd need to be pretty good at parsing strings (dealing with variables...). You'd need to know the math itself, obviously, and you'd also need to know some basic graphics.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    You would need to convert the equation from infix to postfix. You would then need to solve the postfix expression for incremental values of the independent variable. Once you have a sufficient number of graph points, then you can plot them on your graph window.

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    >> You're probably not going to find a tutorial on "How to make a graphing calculator program".
    hmm...
    is anyone aware of a tutorial dealing with the knowledge needed?
    lol i wouldn't like that kind of tutorial, i'd like a tutorial that will drill into my brain the individual steps of the different functions needed so that i can combine them and make the final product.
    i'm also quite glad there isn't such a tutorial as it would make the task much more dull and typical.


    pretty good at parsing strings.. i'd say i'm not bad. i like math i've written a hangman program..? lol its fun but i'm guessing by dealing with graphics you mean something less bitmap related..?

    infix? postfix? mm..i'll look these up. what should i use for making the graph window?
    Last edited by willc0de4food; 09-25-2005 at 09:58 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    what should i use for making the graph window?
    You could always use the GDI draw functions. If you already know how to use a graphics API like OpenGL, then you could use that as well.

    If you are not already experienced with using the Windows API, then using GDI to create a graph may be a little too ambitous for you. On the other hand, attempting overly abitious projects can lead to a massive growth in your programming expertise.

    At any rate, good luck to you.

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    I've made a few programs using thw Win API.. i'll look up the GDI draw functions.

    but i agree, overambition usually generates much learning. hence the reason i'm here. lol but i've never written anything in OpenGL...or DirectX. i've check out some tutorials on OpenGL but thats about as far as that went. lol
    Registered Linux User #380033. Be counted: http://counter.li.org

  7. #7
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    mm...k so its really sad that i can't even get the window made but i keep getting error code 1813 which according to MSDN is
    ERROR_RESOURCE_TYPE_NOT_FOUND
    1813 The specified resource type cannot be found in the image file.
    i have no clue why..i've tried having the defaults for the icons, having no menu, yeaihavenoclue...here's my WinMain
    Code:
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG msg;
        LONG errorcode;
        char error[20] = {0};
        
        g_hInst = hInstance;
        
        wc.cbSize         = sizeof(WNDCLASSEX);
        wc.style          = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc    = WndProc;
        wc.cbClsExtra     = 0;
        wc.cbWndExtra     = 0;
        wc.hInstance      = hInstance;
        wc.hIcon          = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(ID_GRAPHICO));
        wc.hIconSm        = (HICON)LoadImage (GetModuleHandle(NULL), MAKEINTRESOURCE(ID_GRAPHICO), IMAGE_ICON, 16, 16, 0);
        wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wc.lpszMenuName   = MAKEINTRESOURCE(ID_GRAPH_MENU);
        wc.lpszClassName  = g_szClassName;
        wc.hbrBackground  = (HBRUSH)(COLOR_BTNFACE+1);
        
        if (!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "There was a problem registering the window class.\nProgram creation has failed.", 
                "Error!", MB_OK | MB_ICONERROR);
            errorcode = GetLastError();
            _itoa(errorcode, error, 10);
            MessageBox(NULL, error, "Error code", MB_OK);
            return (0);
        }
        
        hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "Graphing Calculator - Shibby Inc. ", 
           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 325, 475, HWND_DESKTOP, NULL, hInstance, NULL);
        
        if (hwnd == NULL)
        {
            MessageBox(NULL, "There was a problem creating the window.\nProgram creation has failed.", 
                "Error!", MB_OK | MB_ICONERROR);
            errorcode = GetLastError();
            _itoa(errorcode, error, 10);
            MessageBox(NULL, error, "Error code", MB_OK);
            return (0);
        }
        
        ShowWindow(hwnd, iCmdShow);
        UpdateWindow(hwnd);
        
        // The Great and Mighty Message Loop
        while (GetMessage(&msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        
        return msg.wParam;
    }
    ? any ideas ?


    ..i even get the error when using the code from winprog.net so i'm thinking its my compiler... ? I'm using Dev-C++ 4.9.9.2, Windows XP Pro SP2, and i haven't changed anything since the last time i compiled something.
    I also have Dev-C++ installed to my flash drive and i have Visual C++ 2005 Express Edition Beta 2 installed on my pc and i get the same error with all of the above, "There was a problem creating the window. Program creation has failed."

    Last edited by willc0de4food; 09-25-2005 at 11:49 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    First of all, you should zero out your WNDCLASSEX structure before you fill it. If you are still having a problem with CreateWindow() returning NULL, then make sure your resource IDs are valid. Consider using some defaults instead:
    Code:
        wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor        = LoadCursor(NULL, IDC_ARROW);

  9. #9
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    i have used those defaults.
    i have no clue why..i've tried having the defaults for the icons, having no menu,...



    there was still problem 1813 creating the window. >:O arg.
    Registered Linux User #380033. Be counted: http://counter.li.org

  10. #10
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    To avoid excessively coding and re-coding a window I just made one file that was a blank window. I use that as a template when I make other programs using windows similar to that, otherwise I rewrite the whole thing. If you want here it is attached:
    Attached Files Attached Files
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  11. #11
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    hmm....a good idea. lol
    Registered Linux User #380033. Be counted: http://counter.li.org

  12. #12
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Just a tip:

    You have this:

    Code:
     
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	 HDC		 hdc ;
    	 PAINTSTRUCT ps ;
    	 RECT		rect ;
     
    	 switch (message)
    	 {
    	 case WM_DESTROY:
    		 PostQuitMessage (0) ;
    		 return 0 ;
    	 }
    	 return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    If you had this:

    Code:
     
    HDC		 hdc ;
    PAINTSTRUCT ps ;
    RECT		rect ;
     
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	 switch (message)
    	 {
    	 case WM_DESTROY:
    		 PostQuitMessage (0) ;
    		 return 0 ;
    	 }
    	 return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    It wouldn't be as hard on the memory.

    The reason for this is because if the way you have it, it would have to declare all three of those vars every time the window calls that function. Which would be a lot of times.
    Last edited by Queatrix; 09-26-2005 at 05:17 PM.

  13. #13
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    It wouldn't be as hard on the memory.

    The reason for this is because if the way you have it, it would have to declare all three of those vars every time the window calls that function. Which would be a lot of times.
    I'm not sure what you mean by "hard on the memory" and I doubt that making those variables global is worthwhile . Even if there is some slight performance boost (it might translate to a few less assembly instructions, I guess), you now have three global variables that stay in memory as long as the application is running. And besides that, they retain their values each time the function is called. If someone needs that, they can always use static variables.

    In any case, it just seems like bad style to me. If you don't need variables outside of a function, don't declare them outside of a function.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help modifying my calculator!!
    By Matus in forum C Programming
    Replies: 5
    Last Post: 03-25-2008, 12:03 PM
  2. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 03:39 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 09:48 AM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21