calculator c++

#include <iostream>
#include <string>
#include <unistd.h>

using namespace std;

class Calculator
{
private:
    char i_numOperator;
    float i_a = 00.0f, i_b = 00.0f;
public:
    Calculator(char numOperator, float a, float b)
    {
        i_numOperator = numOperator;
        i_a = a;
        i_b = b;
    }

    float the_calculator()
    {
        switch (i_numOperator)
        {
        case '+':
            return (i_a + i_b);
            break;
        case '-':
            return (i_a - i_b);
            break;
        case '*':
            return (i_a * i_b);
            break;
        case '/':
            return (i_a / i_b);
            break;
        
        default:
            cout << "invalid operator please try again\n";
            break;
        }
    }
};

int main() {
    char again = 'y';
    while(again == 'y' || again == 'Y')
    {
        int a = 00.0f, b = 00.0f;
        char op;

        cout << "first num\n";
        cin >> a;
        cout << "operator\n";
        cin >> op;
        cout << "second num\n";
        cin >> b;

        Calculator calt(op, a, b);

        cout << "result : " << calt.the_calculator() << endl;

        cout << "do you want to use it again?(Y/N)\n";
        cin >> again;
        system("clear");   
    }
    system("clear");
    cout << "ok.. bye!\n";
    sleep(2);
    system("clear");

    return 0;
}

how to make calculaor in c++

# include <iostream>
using namespace std;

int main() {
    char op;
    float num1, num2;

    cout << "Enter operator: +, -, *, /: ";
    cin >> op;

    cout << "Enter two operands: ";
    cin >> num1 >> num2;

    switch(op) {
        case '+':
            cout << num1 << " + " << num2 << " = " << num1 + num2;
            break;

        case '-':
            cout << num1 << " - " << num2 << " = " << num1 - num2;
            break;

        case '*':
            cout << num1 << " * " << num2 << " = " << num1 * num2;
            break;

        case '/':
            cout << num1 << " / " << num2 << " = " << num1 / num2;
            break;

        default:
            // If the operator is other than +, -, * or /, error message is shown
            cout << "Error! operator is not correct";
            break;
    }

    return 0;
}

calculator in cpp

#include <iostream>
using namespace std;
// Hi I'm Jillani Soft Tech. I'm a Developer.
main()
{
	while(true)
	{
		
		
		int sum,mul,sub,div;	// variable decalration
		int num1,num2;
		int choice;
		
		cout<<"\n\n\t\t\t----------Main Menu-----------"<<endl;
		
		cout<<"Press 1 for Sum "<<endl;
		cout<<"Press 2 for Sub "<<endl;
		cout<<"Press 3 for Mul "<<endl;
		cout<<"Press 4 for Div "<<endl;
		
		cout<<"\nEnter Your Choice ? "<<endl;	
		cin>>choice;
		
		
		cout<<"Enter frist number : "<<endl;
		cin>>num1;
		cout<<"Enter Second number : "<<endl;
		cin>>num2;
		
		
		
		if(choice==1)
		{
			sum=num1+num2;
			cout<<"There sum is this : "<<sum<<endl;
		}
		else if(choice==2)
		{
			sub=num1-num2;
			cout<<"There sub is this : "<<sub<<endl;
		}
		else if(choice==3)
		{
			mul=num1*num2;
			cout<<"There mul is this : "<<mul<<endl;
		}
		else if(choice==4)
		{
			div=num1/num2;
			cout<<"There div is this : "<<div<<endl;
		}
		else
		{
			
			cout<<"\n\n\t\t\tInvalid Selection Try Again.... "<<endl;
		}
		
	}
}

c++ calculator

1 #include<stdio.h>
 2 
 3 int main(){
 4 
 5     char operator;
 6     double first, second;
 7 
 8     printf("Enter the Operator ( +, -, *, / ) : ");
 9     scanf("%c",&operator);
10 
11     printf("Enter the two Numbers one by one : ");
12     scanf("%lf %lf",&first,&second);
13 
14     switch (operator)
15     {
16 
17     case '+':
18         printf("%.2lf + %.2lf = %.2lf",first,second,(first+second));
19         break;
20         
21     case '-':
22         printf("%.2lf - %.2lf = %.2lf",first,second,(first-second));
23         break;
24 
25     case '*':
26         printf("%.2lf * %.2lf = %.2lf",first,second,(first*second));
27         break;
28 
29     case '/':
30         if( second != 0.0 )
31             printf("%.2lf / %.2lf = %.2lf",first,second,(first/second));
32         else 
33             printf("Divide by Zero situation");
34         break;
35     
36     default:
37         printf("%c is an invalid Operator",operator);
38         
39     }
40 
41     return 0;
42 }

C++相关代码片段

how to kill

hello world cpp

cpp hello world

when kotlin

how to write hello world c++

fenwick tree

main function

python loop

is palindrom

subsequence

insertion sort

react cookie

data structure

Stack Modified

increment integer

496. Next Greater Element I.cpp

c++ freecodecamp course 10 hours youtube

simple interest rate

deliberation meaning

fingerprint

c++ system() from variable

operator using

unambiguous

Stream Overloading

quick_sort

hash table

graph colouring

the question for me

fname from FString

how togreper

is plaindrome

logisch oder

robot framework for loop example

spyder enviroment

pallindrome string

ue4 c++ string from fvector

interactive problem

two sum solution

interpolation search

Required Length

new expression

Targon lol

xor linked list

stack implementation

typescript

loop through array

loop array

how to point to next array using pointer c++

file exist

floating point exception

array di struct

castin in C++

varint index

how to make a instagram report bot python

windows servis from console app

add integers

listas enlazadas/ linked lists

niet werkend

bubble sort

triangle angle sum

divisor summation

rotateArray

destiny child

Populating Next Right Pointers in Each Node

cosnt cast

bucket sort

double plus overload

Z-function

binary search

permutation

linked list

Implicit conversion casting

square root

public method

tower of hanoi

selection sort

dangling pointer

hello world programming

statements

volumeof a sphere