Share c++ source code for calculator

### Mã nguồn C ++ cho máy tính

**Giới thiệu**

Máy tính là một thiết bị thực hiện các tính toán toán học.Nó có thể được sử dụng để thực hiện các hoạt động số học cơ bản, chẳng hạn như cộng, trừ, nhân và chia, cũng như các hoạt động phức tạp hơn, chẳng hạn như các hàm lượng giác và logarit.Máy tính được sử dụng trong nhiều cài đặt khác nhau, bao gồm trường học, doanh nghiệp và nhà.

** Mã nguồn C ++ cho máy tính **

Sau đây là mã nguồn C ++ cho một máy tính đơn giản:

`` `C ++
#include <Istream>

sử dụng không gian tên STD;

int main () {
// Xác định các biến.
int num1, num2, toán tử;

// Nhận các số từ người dùng.
cout << "Nhập số đầu tiên:";
CIN >> NUM1;
cout << "Nhập số thứ hai:";
CIN >> NUM2;

// Nhận toán tử từ người dùng.
cout << "Nhập toán tử (+, -, *, /):";
CIN >> toán tử;

// Thực hiện tính toán.
chuyển đổi (toán tử) {
trường hợp '+':
cout << num1 + num2 << endl;
phá vỡ;
trường hợp '-':
cout << num1 - num2 << endl;
phá vỡ;
trường hợp '*':
cout << num1 * num2 << endl;
phá vỡ;
trường hợp '/':
cout << num1 / num2 << endl;
phá vỡ;
mặc định:
cout << "toán tử không hợp lệ."<< Endl;
}

trả lại 0;
}
`` `

** Đầu ra **

`` `
Nhập số đầu tiên: 10
Nhập số thứ hai: 20
Nhập toán tử ( +, -, *, /): +
30
`` `

**Phần kết luận**

Đây chỉ là một ví dụ đơn giản về một máy tính được viết bằng C ++.Có nhiều cách khác để viết một máy tính trong C ++ và bạn có thể tìm thấy nhiều ví dụ mã nguồn khác nhau trực tuyến.

### hashtags

* #C ++
* #máy tính
* #mã nguồn
* #Programming
* #tutorial
=======================================
### C++ Source Code for Calculator

**Introduction**

A calculator is a device that performs mathematical calculations. It can be used to perform basic arithmetic operations, such as addition, subtraction, multiplication, and division, as well as more complex operations, such as trigonometric functions and logarithms. Calculators are used in a variety of settings, including schools, businesses, and homes.

**C++ Source Code for a Calculator**

The following is the C++ source code for a simple calculator:

```c++
#include <iostream>

using namespace std;

int main() {
// Define the variables.
int num1, num2, operator;

// Get the numbers from the user.
cout << "Enter the first number: ";
cin >> num1;
cout << "Enter the second number: ";
cin >> num2;

// Get the operator from the user.
cout << "Enter the operator (+, -, *, /): ";
cin >> operator;

// Perform the calculation.
switch (operator) {
case '+':
cout << num1 + num2 << endl;
break;
case '-':
cout << num1 - num2 << endl;
break;
case '*':
cout << num1 * num2 << endl;
break;
case '/':
cout << num1 / num2 << endl;
break;
default:
cout << "Invalid operator." << endl;
}

return 0;
}
```

**Output**

```
Enter the first number: 10
Enter the second number: 20
Enter the operator (+, -, *, /): +
30
```

**Conclusion**

This is just a simple example of a calculator written in C++. There are many other ways to write a calculator in C++, and you can find many different source code examples online.

### Hashtags

* #C++
* #calculator
* #Source Code
* #Programming
* #tutorial
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top