C++ භාවිතා කරලා සරල Calculator එකක් හදමු

maleesha udan

Well-known member
  • Jan 23, 2019
    206
    436
    63
    හරි අපි බලමු කොහොමද C ++ භාවිතා කරලා සරල / මුලික (Basic) Calculator එකක් හදා ගන්නේ කියලා

    මේ Calculator එක භාවිතා කරලා ඔයාලට Basic Arithmatic Operations වන

    1) එකතු කිරීම
    2) අඩුකිරීම
    3) ගුණකිරීම
    4) බෙදීම

    කියන ගණනයන් කරගන්න පුළුවන් . ඒවගේම මේකට cmath library එක එකතු කරලා නිසා ඔයාලට පුළුවන් යම් සංඛ්‍යාවක බලයක් හොයන්නත්.
    මේ cal එකේ source code පහලින් දාලා තියෙනවා.ඔයාලත් කැමතිනම් මේ source code, Codeblocks වගේ IDE එකක දාල run කරලා බලන්න

    (මේක Basic calculator එකක් විතරයි )


    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
    double num1,num2;
    int op;
    cout<<"Enter the first number"<<endl;
    cin>>num1;
    cout<<"Enter the second number"<<endl;
    cin>>num2;
    cout<<"Enter the arithmetic operation"<<endl;
    cout<<"1 Addition"<<endl;
    cout<<"2 Subtraction"<<endl;
    cout<<"3 Multiplication"<<endl;
    cout<<"4 Division"<<endl;
    cout<<"5 Power"<<endl;
    cout<<"Enter the number"<<endl;
    cin>>op;
    cout<<" "<<endl;
    switch(op){
    case 1: cout<<(num1+num2)<<endl;
    break;
    case 2: cout<<(num1-num2)<<endl;
    break;
    case 3: cout<<(num1*num2)<<endl;
    break;
    case 4:{
    if(num2==0)cout<<0<<endl;
    else cout<<(num1/num2)<<endl;
    }
    break;
    case 5:cout<<pow(num1,num2)<<endl;
    break;
    default :cout<<"Invalid operation"<<endl;
    }
    return 0;
    }




    Thank you! 😉
     

    AnuradhaRa

    Well-known member
  • Dec 25, 2010
    62,022
    1
    43,431
    113
    ඇත්තටම එකතු කිරීම අඩු කිරීම වෙන්නෙ අපි ලියන ප්‍රෝග්‍රෑම් එකෙන් නෙමේ
    ඒක වෙන්නෙ ‌ප්‍රොසෙසර් එකේ add කමාන්ඩ් එකෙන්
    අපිට පුලුවන් add function එක අවශ්‍ය විදියට පාවිච්චි කරන්ඩ විතරයි

    Capture.JPG


    Full-Adder-Circuit.png
     

    SagaxConatusV

    Well-known member
  • Oct 1, 2014
    1,268
    208
    63
    Gedara
    C++:
    #include<iostream>
    
    #include<cmath>
    
    using namespace std;
    int main() {
      double num1, num2;
      int op;
      cout << "Enter the first number" << endl;
      cin >> num1;
      cout << "Enter the second number" << endl;
      cin >> num2;
      cout << "Enter the arithmetic operation" << endl;
      cout << "1 Addition" << endl;
      cout << "2 Subtraction" << endl;
      cout << "3 Multiplication" << endl;
      cout << "4 Division" << endl;
      cout << "5 Power" << endl;
      cout << "Enter the number" << endl;
      cin >> op;
      cout << " " << endl;
      switch (op) {
      case 1:
        cout << (num1 + num2) << endl;
        break;
      case 2:
        cout << (num1 - num2) << endl;
        break;
      case 3:
        cout << (num1 * num2) << endl;
        break;
      case 4: {
        if (num2 == 0) cout << 0 << endl;
        else cout << (num1 / num2) << endl;
      }
      break;
      case 5:
        cout << pow(num1, num2) << endl;
        break;
      default:
        cout << "Invalid operation" << endl;
      }
      return 0;
    }

    Mehema format karanna puluwan syntax highlighting ekka aluth ek eke. indenting nm kalin karala tiyenne one mng hitanne.
    Anyway good post keep it up!
     

    Error365!

    Well-known member
  • Jun 27, 2012
    13,011
    9,604
    113
    එක තැනක නෑ
    ඇත්තටම එකතු කිරීම අඩු කිරීම වෙන්නෙ අපි ලියන ප්‍රෝග්‍රෑම් එකෙන් නෙමේ
    ඒක වෙන්නෙ ‌ප්‍රොසෙසර් එකේ add කමාන්ඩ් එකෙන්
    අපිට පුලුවන් add function එක අවශ්‍ය විදියට පාවිච්චි කරන්ඩ විතරයි

    View attachment 132692

    Full-Adder-Circuit.png

    @salitha22 @PrasangaSPerera :dull:
     

    kaviranga_ou

    Junior member
  • Jun 26, 2016
    84
    69
    18
    බොහොම හොදයි :yes: (y) !

    මේකේ තියෙන්නේ මම ටික කාලයකට කලින් හහපු C++ calculator එකක් අලුත් කරලා . ඒකේ calculations case statements වලින් නැතිව function වලින් වැඩ කරන විදිහට තම හදලා තියෙන්නේ :yes: !







    Linux පාවිච්චි කරනවානම් g++ (gcc තියෙන්නේ c programming compiler එක විදිහට) :yes:. g++ ANSI C++ standards අලුත් version ඒවා ගොඩකට compatible :yes: .
    ------ Post added on Jun 26, 2021 at 8:15 PM
     
    Last edited:

    maleesha udan

    Well-known member
  • Jan 23, 2019
    206
    436
    63
    machan c++ code karanna visual studio daganna onida opengl ekka c++ use karana widiha poddak kiya denna pluwanda visual studio nathuwa mokada visual studio dapuwama lap eka slow wenwa ekai machan
    CodeBlocks IDE eka recommend krnna puluwan mcn

    C++:
    #include<iostream>
    
    #include<cmath>
    
    using namespace std;
    int main() {
      double num1, num2;
      int op;
      cout << "Enter the first number" << endl;
      cin >> num1;
      cout << "Enter the second number" << endl;
      cin >> num2;
      cout << "Enter the arithmetic operation" << endl;
      cout << "1 Addition" << endl;
      cout << "2 Subtraction" << endl;
      cout << "3 Multiplication" << endl;
      cout << "4 Division" << endl;
      cout << "5 Power" << endl;
      cout << "Enter the number" << endl;
      cin >> op;
      cout << " " << endl;
      switch (op) {
      case 1:
        cout << (num1 + num2) << endl;
        break;
      case 2:
        cout << (num1 - num2) << endl;
        break;
      case 3:
        cout << (num1 * num2) << endl;
        break;
      case 4: {
        if (num2 == 0) cout << 0 << endl;
        else cout << (num1 / num2) << endl;
      }
      break;
      case 5:
        cout << pow(num1, num2) << endl;
        break;
      default:
        cout << "Invalid operation" << endl;
      }
      return 0;
    }

    Mehema format karanna puluwan syntax highlighting ekka aluth ek eke. indenting nm kalin karala tiyenne one mng hitanne.
    Anyway good post keep it up!
    Thank you!
    ------ Post added on Jun 26, 2021 at 10:31 PM
     

    kingcharith

    Well-known member
  • Aug 18, 2018
    611
    681
    93
    Ela Ela. igena gannakota OOP concept widihata code karala unit testing liyana eka puruddak kara ganna. mata nam patta complex high performance code walata wada saralawa liyala thiyena coding standard follow karala hariyata unit test karala thiyena code seeyata dahak hodai
     

    imhotep

    Well-known member
  • Mar 29, 2017
    14,858
    8
    35,447
    113
    machan c++ code karanna visual studio daganna onida opengl ekka c++ use karana widiha poddak kiya denna pluwanda visual studio nathuwa mokada visual studio dapuwama lap eka slow wenwa ekai machan
    Just use Bloodshed C++
    https://www.bloodshed.net/

    You can use the original Dev C++ 5.0 or the later fork sponsored by Embarcadero.

    Embarcadero Dev-C++ is a new and improved fork of Bloodshed Dev-C++ and Orwell Dev-C++. It is a full-featured Integrated Development Environment (IDE) and code editor for the C/C++ programming language. It uses Mingw port of GCC (GNU Compiler Collection) as its compiler. Embarcadero Dev-C++ can also be used in combination with Cygwin or any other GCC based compiler. Embarcadero Dev-C++ is built using the latest version of Embarcadero Delphi. Embarcadero Dev-C++ has a low memory footprint because it is a native Windows application and does not use Electron.

    https://ftp.embarcadero.com/free-tools/dev-cpp
     

    Honey Bunch

    Well-known member
  • Nov 24, 2018
    17,264
    26,729
    113
    Kandy
    Just use Bloodshed C++
    https://www.bloodshed.net/

    You can use the original Dev C++ 5.0 or the later fork sponsored by Embarcadero.

    Embarcadero Dev-C++ is a new and improved fork of Bloodshed Dev-C++ and Orwell Dev-C++. It is a full-featured Integrated Development Environment (IDE) and code editor for the C/C++ programming language. It uses Mingw port of GCC (GNU Compiler Collection) as its compiler. Embarcadero Dev-C++ can also be used in combination with Cygwin or any other GCC based compiler. Embarcadero Dev-C++ is built using the latest version of Embarcadero Delphi. Embarcadero Dev-C++ has a low memory footprint because it is a native Windows application and does not use Electron.

    https://ftp.embarcadero.com/free-tools/dev-cpp
    Thank you verymuch