Help i am under tremendous pressure to program

This is a discussion on Help i am under tremendous pressure to program within the C++ Programming forums, part of the General Programming Boards category; Hi I am a second year IT student and i hav an assignment that requires me to use visual c++ ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    1

    Thumbs down Help i am under tremendous pressure to program

    Hi
    I am a second year IT student and i hav an assignment that requires me to use visual c++ i need to program a calculator extra marks will be given for the sqrt and other extra functions please help coz i am so stuck its scary
    P.S. We are using Borland C++ Builder 4 please this assignment is due on Thursday!!!

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Post what you've got and then we'll help you fix it. We're not gonna write the assignment for you.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Quote Originally Posted by Nokubonga
    Hi
    I am a second year IT student and i hav an assignment that requires me to use visual c++ i need to program a calculator extra marks will be given for the sqrt and other extra functions please help coz i am so stuck its scary
    P.S. We are using Borland C++ Builder 4 please this assignment is due on Thursday!!!
    Too easy:
    Code:
    #include <cstdlib>
    
    int main()
    {
      std::system ( "calc" );
    }
    Now, running that program I find that at my consulting fee of $250US per hour, for 5 seconds of effort you owe me .35 cents.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    Quote Originally Posted by Prelude
    Too easy:
    Code:
    #include <cstdlib>
    
    int main()
    {
      std::system ( "calc" );
    }
    Prelude is that really a calculator? holy jesus lol damn im shocked!

    where does it come from, i mean, i dont know what i mean lol.

    edit: ok i tested that just out of curiosity and it doesnt work lol i get a error message and a warning message.
    Code:
    C:\Program Files\DevStudio\MyProjects\calc\calcu.cpp(6) : error C2653: 'std' : is not a class or namespace name
    C:\Program Files\DevStudio\MyProjects\calc\calcu.cpp(7) : warning C4508: 'main' : function should return a value; 'void' return type assumed
    Error executing cl.exe.
    if i use
    Code:
     using namespace std;
    i get 2 errors and 1 warning
    Code:
    C:\Program Files\DevStudio\MyProjects\calc\calcu.cpp(2) : error C2871: 'std' : does not exist or is not a namespace
    C:\Program Files\DevStudio\MyProjects\calc\calcu.cpp(6) : error C2653: 'std' : is not a class or namespace name
    C:\Program Files\DevStudio\MyProjects\calc\calcu.cpp(7) : warning C4508: 'main' : function should return a value; 'void' return type assumed
    Error executing cl.exe.
    this computer im using right now has visual c++ 5.0 but ill test it again when i go home cuz i got 6.0 . but wow thats so simple, lol
    Last edited by InvariantLoop; 04-19-2004 at 09:04 AM.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Prelude is that really a calculator?
    It is on my system.

    >where does it come from
    I just asked system to query Windows (because the OP mentioned Borland which is a Windows compiler) and open the built in calculator program.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    edit lol im still in shock, u got 6.0?

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    i did 1 change on ur prog Prelude, dont know if u misstyped it or anything but on visual c++ 5.0 the following code is correct
    Code:
    #include <cstdlib>
    
    
    int main()
    {
      std:system ( "calc" );
    }
    it does give the systems calc lmao holy jesus!

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Anything older than Visual Studio .NET has awful namespace conformance. In particular, VS 6.0 doesn't recognize that the C standard library is also in the std namespace. This should work for you:
    Code:
    #include <cstdlib> // Or <stdlib.h> if it still doesn't work
    
    int main()
    {
      system ( "calc" );
      return 0;
    }
    My best code is written with the delete key.

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    hehe that also works, is this an example of orthogonality?

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >is this an example of orthogonality?
    No, it's an example of a poor compiler developed before the standard was finalized.
    My best code is written with the delete key.

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    ooooh that makes sense eheheh

  12. #12
    Registered User
    Join Date
    Apr 2004
    Posts
    19
    or you could

    Code:
    #include <windows.h>  //You need shell32.lib for this one 
    
    int main(void)
    {
      char szPath[] = "C:\\WINDOWS\\system32\\Calc.exe";
    
      HINSTANCE hRet = ShellExecute(
            HWND_DESKTOP, //Parent window
            "open",       //Operation to perform
            szPath,       //Path to program
            NULL,         //Parameters
            NULL,         //Default directory
            SW_SHOW);     //How to open
    
      /*
      The function returns a HINSTANCE (not really useful in this case)
      So therefore, to test its result, we cast it to a LONG.
      Any value over 32 represents success!
      */
    
      if((LONG)hRet <= 32)
      {
        MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
        return 1;
      }
    
      return 0;
    }
    jotun

    n : (Norse mythology) one of a race of giants often in conflict with the Aesir [syn: Jotun, Jotunn]

  13. #13
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Talking Back to Reality...

    Welcome Nokubonga,

    You are NOT going to get credit for a program that opens the Windows calculator!!!!

    I'm not sure what you're supposed to do. I can't tell if you are supposed to write a full-Windows GUI program, or a Windows Console (text-based) program.

    Borland Builder makes it "easy" to do the GUI stuff... Well, it's supposed to... I've never actually done it the "easy way".

    Visual C++ is a different compiler from a different company!!! It has MFC (Microsoft Foundation Classes) that also make it "easy" to write GUI programs.

    In any case, you program is going to need some "if statements", some statements or functions to do the actual calculations, and some input & output statements (cin & cout if you're writing a console program.)

    You should have enough information from your class notes and reading assignment to complete your homework, unless you signed-up for a class without having the prerequisites. (GUI programming in C/C++ is generally an advanced topic.)

    Like, XSquared said, make an attempt. Show what you've done so far, and you'll get much more help here! See the announcements about homework, and board guidelines.

    Hint - The <cmath> header includes a square root function.

  14. #14
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Remember that the new headers such as <cmath> have all their elements in the std namespace which means you mean to do:
    Code:
    #include <cmath>
    
    // A)
    y = std::sqrt(x);
    
    // B)
    using std::sqrt;
    y = sqrt(x);
    
    // C)
    using namespace std;
    y = sqrt(x);
    The last one (C) will include everything in the std namespace which includes all the math functions included in cmath.

    If your compiler does not include the new standard headers, use math.h and don't worry about namespaces.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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