Thread: Create Scientific Calculator in Visual C++

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Exclamation Create Scientific Calculator in Visual C++

    Hi to all,

    THis is my first post here.

    I have a project to create a scientific calculator.

    i wrote a code and i need some help on how to proceed.
    The code i wrote is for +, - , * , /
    now i want to continue with x^y, arc,tan etc.

    any ideas on how to proceed with these?

    Thanks in advance.

    Code:
        //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    
    BOOL IsNumber(AnsiString s)
    {
    int i;
    BOOL itis=true;
    for (i=1 ; i<=s.Length() ; i++)
    if (!isdigit(s[i]) && s[i]!=',' && s[i]!='-') itis=false;
    return itis;
    }
    
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::Button11Click(TObject *Sender)
    {
    Form1 -> Close();        
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::Button9Click(TObject *Sender)
    {
    Edit1 -> Clear();
    Edit2 -> Clear();
    Edit3 -> Clear();
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::Button10Click(TObject *Sender)
    {
    Form2 -> ShowModal();
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
    Edit3->Text=Edit1->Text.ToDouble() + Edit2->Text.ToDouble();
    else
    MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
    Edit3->Text=Edit1->Text.ToDouble() - Edit2->Text.ToDouble();
    else
    MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button3Click(TObject *Sender)
    {
    if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
    Edit3->Text=Edit1->Text.ToDouble() * Edit2->Text.ToDouble();
    else
    MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button4Click(TObject *Sender)
    {
    if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
    Edit3->Text=Edit1->Text.ToDouble() / Edit2->Text.ToDouble();
    else
    MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
    }
    //---------------------------------------------------------------------------

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Yeah, that's not Visual C++ code...copypasta fail!

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    Quote Originally Posted by rags_to_riches View Post
    Yeah, that's not Visual C++ code...copypasta fail!
    it is .. and it is in Borland.
    i can send you the hole program if you want via e-mail

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by andrew80 View Post
    it is .. and it is in Borland.
    i can send you the hole program if you want via e-mail
    Most likely no one is interested in the whole program. You need to think a little harder about how what you are asking for looks to people who are not you. In other words, provide some more explanation in your own words (it's near impossible to separate intentions from mistakes, etc, when reading beginner code), and ask more specific problems.

    Eg. how to you think you should proceed? What have you tried? Are the any technical issues you want to ask about before you decide? And so on.

    How To Ask Questions The Smart Way

    Ignore at your own risk
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MS Visual C++ 6 wont include vector.h in a header file
    By bardsley99 in forum C++ Programming
    Replies: 9
    Last Post: 11-06-2003, 12:05 PM
  2. Visual C++.net using C# create dll
    By lshome in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2003, 07:13 AM
  3. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM
  4. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 12:06 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM