একটি সিম্পল ক্যালকুলেটর মৌলিক অপারেশনগুলো করে: '+' (যোগ), '-' (বিয়োগ), '*' (গুণ), '/' (ভাগ)। ক্যালকুলেটর এই অপারেশনগুলো দ্রুত করে। এখানে সুইচ স্টেটমেন্ট ব্যবহার করে ক্যালকুলেটর বানানো হয়েছে।
নমুনা
Operator - '+' => 34 + 324 = 358 Operator - '-' => 3874 - 324 = 3550 Operator - '*' => 76 * 24 = 1824 Operator - '/' => 645 / 5 = 129
উদাহরণ কোড
#include <iostream>
using namespace std;
int main() {
char op = '+';
float a = 63, b = 7;
// cout << "Enter operator either + or - or * or /: ";
// cin >> op;
cout << "The operator is " << op << endl;
// cout << "Enter two operands: ";
// cin >> a >> b;
cout << "a = " << a << " b = " << b << endl;
switch(op) {
case '+':
cout << "Sum of " << a << " and " << b << " is " << a+b;
break;
case '-':
cout << "Difference of " << a << " and " << b << " is " << a-b;
break;
case '*':
cout << "Product of " << a << " and " << b << " is " << a*b;
break;
case '/':
cout << "Division of " << a << " and " << b << " is " << a/b;
break;
default:
cout << "Error! operator is not correct";
break;
}
return 0;
}
আউটপুট
The operator is + a = 63 b = 7 Sum of 63 and 7 is 70