Showing posts with label Calculator. Show all posts
Showing posts with label Calculator. Show all posts

Monday, January 25, 2021

How to Create a Calculator in C++🤔🤔 | Explained in English | Less than 100 Lines Code

Macstock

In this Post, I have Managed to Show you how you Can Easily Create Calculator in C++. It is very Simple and Easy to Create Program.

For Better Understanding You Should Watch the Full Video [Explained In Hindi Language] By Clicking the Video Button Given Below


Source Code Here :-


#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int inp_number;
    int while_runner = 0;
    int add_first;
    int add_second;
    int sub_first;
    int sub_second;
    int multi_first;
    int multi_second;
    int div_first;
    int div_second;
    cout<<"Welcome to Calculator. Press Enter to Continue"<<endl;
    getchar();
    while (while_runner==0)
    {       
        cout<<"Use any of the Below Functions."<<endl;
        cout<<"Press 1 For Addition"<<endl;
        cout<<"Press 2 For Substraction"<<endl;
        cout<<"Press 3 For Multiplication"<<endl;
        cout<<"Press 4 For Division"<<endl;
        cin>>inp_number;
        if (inp_number==1)
        {
            cout<<"Enter the first Number to Add:- "<<endl;
            cin>>add_first;
            cout<<"Enter the Second Number to Add:- "<<endl;
            cin>>add_second;
            try
            {
                cout<<add_first+add_second<<endl;
            }
            catch(const std::exception& e)
            {
                cout<<"Enter a Valid Number"<<endl;
                break;
            }
            
        }
        else if (inp_number==2)
        {
            cout<<"Enter the first Number to Substract:- "<<endl;
            cin>>sub_first;
            cout<<"Enter the Second Number to Substract:- "<<endl;
            cin>>sub_second;
            try
            {
                cout<<sub_first-sub_second<<endl;
            }
            catch(const std::exception& e)
            {
                cout<<"Enter a Valid Number"<<endl;
                break;
            }
             
        }
        
        else if (inp_number==3)
        {
            cout<<"Enter the first Number to Multiply:- "<<endl;
            cin>>multi_first;
            cout<<"Enter the Second Number to Multiply:- "<<endl;
            cin>>multi_second;
            try
            {
                cout<<multi_first*multi_second<<endl;
            }
            catch(const std::exception& e)
            {
                cout<<"Enter a Valid Number"<<endl;
                break;
            }
            
            
        }

        else if(inp_number==4)
        {
            cout<<"Enter the first Number to Divide:- "<<endl;
            cin>>div_first;
            cout<<"Enter the Second Number to Divide:- "<<endl;
            cin>>div_second;
            try
            {
                cout<<div_first/div_second<<endl;
            }
            catch(const std::exception& e)
            {
                cout<<"Enter a Valid Number"<<endl;
                break;
            }
        
        }
        else {
            cout<<"Enter a Valid Option";
            break;
        }
        
    }

}
    

Hope you Will Like It😊

Friday, November 6, 2020

Calculator Android App | Android Studio | Full Project With Source Code | Download .apk File on Phone

Macstock

In this Post, I have Managed to Build a Calculator Using Android Studio. This is a Basic Calculator Which Performs Several Function.

It is a little bit comlex, so if you are not a Android Developer then You Should Download the .apk File of this App to Use this in your Android Device

About this App :-

This is a Calculator which is designed and developed by me which performs several Calculations like Addition, Substraction, Multiplication, Division, etc. It has Also a About Page Which Contains an Awesome Audiowide Font Look. I builded the app with a dark theme. So if you want Light theme, then simply change the colours.xml File to Make it light theme. This app also has a menu bar. The buttons of this are modern looking awesome designed buttons. So if you like it, then Please Comment Down Below :)

Want to Install It without Android Studio In your Phone, Download from the link :-

For Those, who want to Build OwnSelf :-

How to Use :-

First of all Open Android Studio and Create a New Empty Project, After that wait for the Gradle to Complete Building. After that, Open your project's res folder manually and then delete all the folders inside it. Now Download the Import Files from the Button Given Below and then Extract it using WinRar. After Extracting, Cut the Folders that are formed after Extracting and Paste them Inside your res Folder. Now Copy the MainActivity.java Code From Below and Open your MainActivity.java file and Paste the Code there.Now Create One More Java File where your MainActivity.java exists, and name the File as About_Us.java. After that, Copy the About_us.java code from below and Paste it inside the About_Us.java file. After that, create a New Java File Where you created the previous one, and name it as About_Us_Info.java. Now Copy the About_Us_Info.java Code from below and Paste it inside your About_Us_Info.java file. Now you can run the App :)

First of all Download The Files Given Below and replace it with the files in the "res" Folder of your Project, Like Shown in the Image Below

[MainActivity.java] Source Code :-


package com.macstockofficial.kunalimagestopdfconv;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;


import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;

import android.text.Layout;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import android.os.Bundle;



public class MainActivity extends AppCompatActivity {
    Button btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0, btnAdd, btnMultiply, btnDiv, btnMinus, btnDot, btnEqual;
    Button btnClear;
    EditText ed1;
    Float result1, result2;
    boolean Add, Sub, Multiply, Divide;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu, menu);
        return true;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);
        btn4 = (Button) findViewById(R.id.btn4);
        btn5 = (Button) findViewById(R.id.btn5);
        btn6 = (Button) findViewById(R.id.btn6);
        btn7 = (Button) findViewById(R.id.btn7);
        btn8 = (Button) findViewById(R.id.btn8);
        btn9 = (Button) findViewById(R.id.btn9);
        btn0 = (Button) findViewById(R.id.btn0);
        btnAdd = (Button) findViewById(R.id.btnAdd);
        btnMinus = (Button) findViewById(R.id.btnMinus);
        btnMultiply = (Button) findViewById(R.id.btnMultiply);
        btnDiv = (Button) findViewById(R.id.btnDiv);
        btnDot = (Button) findViewById(R.id.btnDot);
        btnEqual = (Button) findViewById(R.id.btnEqual);
        btnClear = (Button) findViewById(R.id.btnClear);
        ed1 = (EditText) findViewById(R.id.editTextTextPersonName);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "1");
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "2");
            }
        });

        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "3");
            }
        });

        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "4");
            }
        });

        btn5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "5");
            }
        });

        btn6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "6");
            }
        });

        btn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "7");
            }
        });

        btn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "8");
            }
        });

        btn9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "9");
            }
        });

        btn0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ "0");
            }
        });

        btnDot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText(ed1.getText()+ ".");
            }
        });


        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ed1==null){
                    ed1.setText("");
                }
                else{
                    result1 = Float.parseFloat(ed1.getText() + "");
                    Add = true;
                    ed1.setText(null);
                }
            }
        });
        btnMinus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ed1==null){
                    ed1.setText("");
                }
                else{
                    result1 = Float.parseFloat(ed1.getText() + "");
                    Sub = true;
                    ed1.setText(null);
                }
            }
        });

        btnMultiply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ed1==null){
                    ed1.setText("");
                }
                else{
                    result1 = Float.parseFloat(ed1.getText() + "");
                    Multiply = true;
                    ed1.setText(null);
                }
            }
        });

        btnDiv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ed1==null){
                    ed1.setText("");
                }
                else{
                    result1 = Float.parseFloat(ed1.getText() + "");
                    Divide = true;
                    ed1.setText(null);
                }
            }
        });

        btnEqual.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                result2 = Float.parseFloat(ed1.getText() + "");
                if (Add==true){
                    ed1.setText(result1 + result2 + "");
                    Add = false;
                }
                if (Sub==true){
                    ed1.setText(result1 - result2 + "");
                    Sub = false;
                }
                if (Multiply==true){
                    ed1.setText(result1 * result2 + "");
                    Multiply = false;
                }
                if (Divide==true){
                    ed1.setText(result1 / result2 + "");
                    Divide = false;
                }
            }
        });
        btnClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ed1.setText("");
            }
        });
    }


    public void about_us(MenuItem menuItem){
        Intent intent = new Intent(this, About_us.class);
        startActivity(intent);
    }


    public void about_us_info(MenuItem menuItem){
        Intent intent = new Intent(this, About_Us_info.class);
        startActivity(intent);
    }




}
    

[About_us.java] Source Code :-


package com.macstockofficial.kunalimagestopdfconv;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class About_us extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);
    }

    public void subscribe_youtube(View view) {
        Uri uri = Uri.parse("https://www.youtube.com/channel/UCIXud9Ot8pfDQizzdmQ-FyQ?sub_confirmation=1");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    public void visitweb(View view) {
        Uri uri2 = Uri.parse("https://macstockofficial.blogspot.com/");
        Intent intent2 = new Intent(Intent.ACTION_VIEW, uri2);
        startActivity(intent2);
    }

    public void about_us_info(View view){
        Intent intent = new Intent(this, About_Us_info.class);
        startActivity(intent);
    }
}
    

[About_Us_info.java] Source Code :-


package com.macstockofficial.kunalimagestopdfconv;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class About_Us_info extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about__us_info);
    }

    public void download_app(View view){
        Uri uri = Uri.parse("https://macstockofficial.blogspot.com/p/my-android-app-download-links-full.html");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }
}
    

Hope You Will Like the Project.

Monday, September 7, 2020

Repeating Sum Calculator Using Python | Full Details | Source Code | All About | Simple Code

Macstock

Repeating Sum Calculator Using Python

In This Python Program, You can easily Add Numbers Just By Entering Number and Pressing Enter, You Can Do It As Much as You Want, Coz this is in a While Loop.

You Do not Have To Install any Python Library to Run this Program, Very Simple and Short Codes are Given, Just Copy them and Paste In Your IDE or Python Official IDLE.


sum = 0
while (True):
    userInput = int(input("Enter the Price : \n"))
    if (userInput!='q'):
        sum = sum + int(userInput)
        print("Your Order Total So far : ", sum)
        

    else:
        print("Thanks For Using Our Calculator")
        print("The Total Sum : ", sum )
        break
            

Simple Calculator Using Java | Full Details | Source Code | How to Make

Macstock

Simple Calculator Using Java

In this Java Program You Can Divide, Multiply, Substract Or Add any type of Numbers.

If You are a Advanced Java Programmer, Then It is Not For You. This Program Is Only For Beginners Or InterMediate Java Programmers Because It is Not GUI(Graphical User Interface) Program.

Things to Do Before Copying Codes

1. Make Sure You have Installed Java and Its JDK

2. Create A New Folder WhereEver You Want

3. Create a New File in The Folder Name "Anything.bat"

4. Right Click On the File and Click Edit And Paste the Given Text There.

java -jar JavaCalculator.jar


    import java.util.Scanner;
              
public class Main {
              
                  public static void main(String[] args) throws InterruptedException {
                      for (int i = 0; i < 2000; i++) {
                          Scanner scanner = new Scanner(System.in);
                          double a, b;
                          System.out.print("Enter The First Number : ");
                          a = scanner.nextDouble();
                          System.out.print("Enter the Second Number : ");
                          b = scanner.nextDouble();
                          System.out.println();
                          System.out.println();
                          System.out.println();
                          System.out.print("You have Entered : ");
                          System.out.print(a);
                          System.out.print(" and ");
                          System.out.print(b);
                          System.out.println();
                          System.out.println();
                          System.out.println();
                          System.out.println("Press 1 for Addition");
                          System.out.println();
                          System.out.println("Press 2 For Substraction");
                          System.out.println();
                          System.out.println("Press 3 for Multiplication");
                          System.out.println();
                          System.out.println("Press 4 For Division");
                          
                          
                          int selection = scanner.nextInt();
                          switch (selection) {
                              case 1:
                                  System.out.println("Adding These Numbers ..... Please Wait");
                                  Thread.sleep(3000);
                                  System.out.println();
                                  System.out.println();
                                  System.out.print("The Sum of These Numbers is : ");
                                  System.out.println(a + b);
                                  break;
                              case 2:
                                  System.out.println("Substracting These Numbers ..... Please Wait");
                                  Thread.sleep(3000);
                                  System.out.println();
                                  System.out.println();
                                  System.out.print("The Substraction Of these Two Numbers is : ");
                                  System.out.println(a - b);
                                  break;
                              case 3:
                                  System.out.println("Multiplying These Numbers ..... Please Wait");
                                  Thread.sleep(3000);
                                  System.out.println();
                                  System.out.println();
                                  System.out.print("The Multiplication Of these Two Numbers is : ");
                                  System.out.println(a * b);
                                  break;
                              case 4:
                                  System.out.println("Dividing These Numbers ..... Please Wait");
                                  Thread.sleep(3000);
                                  System.out.println();
                                  System.out.println();
                                  System.out.print("The Division of These two Numbers Is : ");
                                  System.out.println(a / b);
                                  break;
                              default:
                                  System.out.println();
                                  System.out.println("Invalid Content, Press one of the Given Numbers to perform a Operation");
                                  break;
                                  
                                  
                          }
                          System.out.println();
                          System.out.println();
                          System.out.println();
                          System.out.println("Thank You For Using Kunal Calculator, GOODBYE");
                          System.out.println();
                          System.out.println("Want to Use Again, then Wait 3 Seconds");
                          Thread.sleep(1800);
                          System.out.println();
                          System.out.println();
                          System.out.println();
                          
                          
                      }
                  }
              }
    

Make Sure To Build This in .jar Format and Save the File Name As "JavaCalculator.jar"

You can Use This As Much As You Want Coz This is In A Loop