0% found this document useful (0 votes)
1 views4 pages

Objective

The document outlines the creation of a simple calculator program in C++ that performs basic arithmetic operations such as addition, subtraction, multiplication, and division. It includes the necessary tools, theory, procedure, source code, and sample output, demonstrating the program's functionality and error handling for division by zero. The conclusion confirms the successful development and testing of the calculator, along with potential viva questions for further discussion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Objective

The document outlines the creation of a simple calculator program in C++ that performs basic arithmetic operations such as addition, subtraction, multiplication, and division. It includes the necessary tools, theory, procedure, source code, and sample output, demonstrating the program's functionality and error handling for division by zero. The conclusion confirms the successful development and testing of the calculator, along with potential viva questions for further discussion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

🧪 Lab Report: Calculator in C++

🔹 Title

Creating a Simple Calculator Using C++

🔹 Objective

To develop a basic calculator program using C++ that performs arithmetic


operations such as addition, subtraction, multiplication, and division.

---

🔹 Tools & Software

Programming Language: C++

Compiler: g++, Turbo C++, or any C++ IDE (Code::Blocks, Dev C++, etc.)

Operating System: Windows / Linux

---

🔹 Theory

A calculator program performs mathematical operations based on user input.


In C++, we use conditional or switch statements to decide which operation
to perform, based on the operator (+, -, *, /) entered by the user.

---

🔹 Procedure

1. Start the C++ IDE or compiler.

2. Create a new .cpp file.


3. Write the C++ code for the calculator.

4. Compile and run the program.

5. Test it with different inputs.

---

🔹 Source Code

#include <iostream>

using namespace std;

int main() {

char op;

float num1, num2;

cout << "Enter operator (+, -, *, /): ";

cin >> op;

cout << "Enter two numbers: ";

cin >> num1 >> num2;

switch(op) {

case '+':

cout << "Result: " << num1 + num2 << endl;

break;

case '-':

cout << "Result: " << num1 - num2 << endl;


break;

case '*':

cout << "Result: " << num1 * num2 << endl;

break;

case '/':

if(num2 != 0)

cout << "Result: " << num1 / num2 << endl;

else

cout << "Error: Division by zero!" << endl;

break;

default:

cout << "Invalid operator!" << endl;

return 0;

---

🔹 Sample Output

Enter operator (+, -, *, /): +

Enter two numbers: 5 3

Result: 8

---

🔹 Conclusion
The C++ calculator program was successfully developed and tested. It can
perform basic arithmetic operations and handles division-by-zero errors.

---

🔹 Viva Questions

1. What is the use of switch statement in C++?

2. How does the program handle invalid input?

3. What happens when you divide a number by zero?

4. How can we improve this calculator?

You might also like