0% found this document useful (0 votes)
16 views19 pages

Project Khushhal

The document presents a project on creating a simple interest calculator in C++ as part of the Bachelor of Computer Applications program at Galgotias University. It includes an introduction to basic arithmetic operations, the methodology for implementing the calculator, and discusses results and future enhancements such as a graphical user interface and additional functionalities. The project emphasizes fundamental programming concepts and aims to improve user experience and error handling.

Uploaded by

askrahulsingh350
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views19 pages

Project Khushhal

The document presents a project on creating a simple interest calculator in C++ as part of the Bachelor of Computer Applications program at Galgotias University. It includes an introduction to basic arithmetic operations, the methodology for implementing the calculator, and discusses results and future enhancements such as a graphical user interface and additional functionalities. The project emphasizes fundamental programming concepts and aims to improve user experience and error handling.

Uploaded by

askrahulsingh350
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Project

on

Creating a simple Interest calculator


in C++

Submitted in partial fulfillment of the requirement


for the award of the degree of

BACHELORS OF COMPUTER APPLICATIONS

Session 2023-24
Under The Supervision of

Dr. Lalit Kumar

Submitted By

Anas Khan(23SCSE1040379)
Khushhal Kumar(23SCSE1040363)
Granth Shandilya(23SCSE1040357)
Ashish Kashyap(23SCSE1040344)

SCHOOL OF COMPUTER APPLICATIONS AND TECHNOLOGY,


GALGOTIAS UNIVERSITY, GREATER NOIDA, INDIA
JUNE-2024
CANDIDATE’S DECLARATION
We hereby certify that the work which is being presented in the project, entitled “Creating a simple

Interest Calculator in C++ ” in partial fulfillment of the requirements for the award of the BCA

submitted in the School of Computing Science and Engineering of Galgotias University, Greater Noida, is an

original work carried out during the period of March, 2024 to June and 2024, under the supervision of Dr.

Lalit Kumar, School of Computer Applications and Technology, Galgotias University,Greater Noida

The matter presented in the thesis/project/dissertation has not been submitted by us for the award of any

other degree of this or any other places.

Anas Khan (23SCSE1040379)


Khushhal Kumar(23SCSE1040363)
Granth Shandilya(23SCSE1040357)
Ashish Kashyap(23SCSE1040344)

This is to certify that the above statement made by the candidates is correct to the best of my knowledge.

Dr.Lalit Kumar
(Associate Professor)
CERTIFICATE

The Final Project Viva-Voce examination of ANAS KHAN(23SCSE1040379),

KHUSHHAL KUMAR (23SCSE1040363), GRANTH SHANDILYA

(23SCSE1040357), ASHISH KAHSYAP (23SCSE1040344) “CREATING

SIMPLE INTEREST CALCULATOR IN C++” has been held on

And his/her work is recommended for the award of Bachelor of Computer Applications.

Signature of Examiner(s) Signature of Supervisor(s)

Signature of Program Chair Signature of Dean

Date:

Place:Greater Noida
ABSTRACT

A simple calculator is a device used to perform basic arithmetic operations such as


addition, subtraction, multiplication, and division. It makes arithmetic calculations easier
and faster. In this article, we will learn how to code a simple calculator using C++.

Algorithm to Make a Simple Calculator

Initialize two float variables num1 and num2 to take two operands as input.
Initialize a char variable op to take the operator as input.
Start the switch statement with op as the expression of the switch statement.
Now, create cases for different arithmetic operations.

o ‘+’ for addition


o ‘-‘ for subtraction
o ‘*’ for multiplication
o ‘/’ for division
• Default case for the case when the entered operator is not one of the above
operators.
o The operation will be performed based on the operator entered as the input.

CONTENT

CHAPTER TITLE PAGE


NO NO.
ABSTRACT

LIST OF FIGURES

LIST OF TABLES

LIST OF ABBREVIATIONS
1 INTRODUCTION

1.1

1.2

2 LITERATURE REVIEW

2.1

2.2

3 EXISTING METHODOLOGY

3.1

3.2

4 PROPOSED METHODOLOGY

4.1

4.2

5 RESULTS

5.1

5.1.1

6 RESULTS AND DISCUSSION

7 CONCLUSION AND FUTURE WORK


LIST OF FIGURES

FIGUR FIGURE NAME PAGE


ENO. NO.
1.1

4.1
4.2.4.

LIST OF TABLES

TABLE NO. TABLE NAME PAGE NO.

5.1
5.2

LIST OF ABBREVATIONS
CHAPTER- 1

INTRODUCTION

A simple calculator is a device used to perform basic arithmetic operations such as


addition, subtraction, multiplication, and division. It makes arithmetic calculations easier
and faster. In this article, we will learn how to code a simple calculator using C++.

Algorithm to Make a Simple Calculator

Initialize two float variables num1 and num2 to take two operands as input.
Initialize a char variable op to take the operator as input.
Start the switch statement with op as the expression of the switch statement.
Now, create cases for different arithmetic operations.

o ‘+’ for addition


o ‘-‘ for subtraction
o ‘*’ for multiplication
o ‘/’ for division
• Default case for the case when the entered operator is not one of the above
operators.
o The operation will be performed based on the operator entered as the input.

CHAPTER-2
LITERATURE REVIEW

**Literature Review:**

A simple calculator program in C++ can be used to perform basic arithmetic operations such
as addition, subtraction, multiplication, and division. It can take input from the user, perform
the requested operation, and then display the result. This type of program is often used as a
learning exercise for beginners to understand concepts like variables, user input, conditional
statements, and basic arithmetic operations in programming. Additionally, it can serve as a
handy tool for quick calculations when needed.

*Simple calculator Implementations:*


Sure, here's a step-by-step breakdown of how you can implement a simple calculator in
C++:

### Step 1: Include Necessary Libraries


```cpp
#include <iostream>
```
This line includes the Input/Output stream library, which allows you to use functions like
`cout` and `cin` for input and output operations.

### Step 2: Declare Variables


```cpp
using namespace std;
```
This line allows you to use names from the standard C++ library without prefixing them
with `std::`.

```cpp
int main() {
char op;
float num1, num2, result;
```
Declare variables to store the operator (`op`), two numbers (`num1` and `num2`), and the
result of the calculation (`result`).

### Step 3: Get Operator and Numbers from User


```cpp
cout << "Enter operator (+, -, *, /): ";
cin >> op;

cout << "Enter two numbers: ";


cin >> num1 >> num2;
```
Prompt the user to enter an operator and two numbers. Use `cin` to read the values
entered by the user into the variables `op`, `num1`, and `num2`.

### Step 4: Perform Calculation Based on Operator


```cpp
switch(op) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if(num2 != 0)
result = num1 / num2;
else {
cout << "Error! Division by zero is not allowed.";
return -1;
}
break;
default:
cout << "Error! Invalid operator.";
return -1;
}
```
Use a `switch` statement to perform the appropriate arithmetic operation based on the
operator entered by the user. Handle division by zero as an error case.

### Step 5: Display the Result


```cpp
cout << "Result: " << result << endl;

return 0;
}
```
Output the result of the calculation using `cout`.

### Putting it All Together


When you put all the steps together, you get the complete simple calculator program in
C++.

```cpp
#include <iostream>

using namespace std;

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

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


cin >> op;

cout << "Enter two numbers: ";


cin >> num1 >> num2;

switch(op) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if(num2 != 0)
result = num1 / num2;
else {
cout << "Error! Division by zero is not allowed.";
return -1;
}
break;
default:
cout << "Error! Invalid operator.";
return -1;
}

cout << "Result: " << result << endl;

return 0;
}
```
This program will perform basic arithmetic operations based on the user's input and
display the result.*Object-Oriented Design Patterns:*

CHAPTER-3

EXISTING METHODOLOGY

The existing methodology for a simple calculator typically involves the following steps:

1. User Interface: Provide a user interface where users can input numbers and select operations.

2. Input Handling: Capture user input for numbers and the desired operation.

3. Operation Execution: Based on the selected operation, perform the corresponding arithmetic
calculation.

4. Output Display: Display the result of the calculation to the user.

Here's a more detailed explanation of each step:

1. User Interface
The user interface should be intuitive and allow users to:

• Input numbers (operands)


• Select the operation they want to perform (addition, subtraction, multiplication, division)
• See the result of the calculation

This can be implemented using text-based interfaces (command-line interface) or graphical user
interfaces (using libraries like Qt, GTK, or Windows Forms).

2. Input Handling
Capture user input for:

• Two numbers (operands)


• The operation to perform

Ensure input validation to handle cases where users enter invalid characters or divide by zero.

3. Operation Execution
Perform the arithmetic operation selected by the user:

• Addition: Add the two numbers together.


• Subtraction: Subtract the second number from the first.
• Multiplication: Multiply the two numbers.
• Division: Divide the first number by the second (ensure handling for division by zero).
4. Output Display
Display the result of the calculation to the user:

• Print the result to the console or display it in the graphical user interface.

*pseudocode

Display "Welcome to Simple Calculator"


Prompt "Enter first number: "
Read num1
Prompt "Enter second number: "
Read num2
Prompt "Select operation (+, -, *, /): "
Read operation

Switch operation:
Case '+':
result = num1 + num2
Case '-':
result = num1 - num2
Case '*':
result = num1 * num2
Case '/':
if num2 != 0:
result = num1 / num2
else:
Display "Error: Division by zero"
Terminate program
Default:
Display "Error: Invalid operation"
Terminate program

Display "Result: ", result

CHAPTER-4

PROPOSED METHODOLOGY

1. Define the Operations: Decide which operations your calculator will support. Typically, it
includes addition, subtraction, multiplication, and division.

2. Design the User Interface: Determine how users will interact with your calculator. You might use
the console for input and output in a simple implementation.

3. Error Handling: Handle cases where the user enters invalid input (e.g., non-numeric input).

4. Testing: Test your calculator with various inputs to ensure it produces correct results and handles
errors gracefully.
CHAPTER 5: RESULT

#include <iostream>

// Function to add two numbers


double add(double a, double b) {
return a + b;
}

// Function to subtract two numbers


double subtract(double a, double b) {
return a - b;
}

// Function to multiply two numbers


double multiply(double a, double b) {
return a * b;
}

// Function to divide two numbers


double divide(double a, double b) {
if (b == 0) {
std::cout << "Error: Division by zero\n";
return 0; // or handle differently, e.g., return infinity
}
return a / b;
}

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

// Prompt user for input


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

// Prompt user for numbers


std::cout << "Enter two numbers: ";
std::cin >> num1 >> num2;
// Perform operation based on operator
switch(op) {
case '+':
std::cout << "Result: " << add(num1, num2) << std::endl;
break;
case '-':
std::cout << "Result: " << subtract(num1, num2) << std::endl;
break;
case '*':
std::cout << "Result: " << multiply(num1, num2) << std::endl;
break;
case '/':
std::cout << "Result: " << divide(num1, num2) << std::endl;
break;
default:
std::cout << "Invalid operator\n";
}

return 0;
}

OUTPUT :
CHAPTER 6:RESULTS AND DISCUSSION

Result: The implemented calculator allows users to perform basic arithmetic operations such as
addition, subtraction, multiplication, and division. It takes two numbers and an operator as input from
the user, performs the operation, and displays the result. The program also handles division by zero
error gracefully by providing an error message.

Discussion:

1. Functionality: The calculator performs basic arithmetic operations accurately. Users can easily
input numbers and select the desired operation.

2. User Experience: The user experience is straightforward as the program prompts the user for
input and displays the result. However, the console interface might not be the most user-friendly
for some users. Consider implementing a graphical user interface (GUI) for better usability.

3. Error Handling: The program handles division by zero error by displaying an error message.
However, it terminates after displaying the error message. You might want to allow users to
continue using the calculator after encountering an error.
CHAPTER 7

CONCLUSION AND FUTURE WORK

Conclusion:

The simple calculator implemented in C++ provides a basic yet functional tool for performing arithmetic
operations. It successfully allows users to input two numbers and select an operation to perform,
displaying the result accurately. The calculator demonstrates fundamental programming concepts such
as functions, user input handling, error checking, and basic arithmetic operations.

Future Work:

1. Graphical User Interface (GUI): Enhance the user experience by implementing a GUI using
libraries like Qt or GTK. A GUI would provide a more intuitive and user-friendly interface
compared to the console.

2. Input Validation: Improve robustness by implementing input validation to ensure that users
enter valid numeric input and a valid operator. This prevents unexpected behavior and enhances
error handling.

3. Additional Operations: Extend the calculator to support more operations such as


exponentiation, square root, modulus, and trigonometric functions. This would increase its utility
and versatility.

4. Scientific Calculator Features: Implement advanced mathematical functions commonly found in


scientific calculators, such as logarithms, factorial, and inverse trigonometric functions.

5. Memory Functions: Add memory functions like memory recall and memory clear to allow users
to store and retrieve values for further calculations.

6. Internationalization: Support multiple languages by adding localization features to the


calculator, enabling users to interact with the application in their preferred language.

7. Optimization: Optimize the code for efficiency and performance, especially for large
calculations. This may involve using more efficient algorithms or data structures.
8. Error Handling Improvement: Enhance error handling to provide more informative error
messages and allow users to recover from errors gracefully without terminating the program.

By implementing these enhancements and addressing areas for improvement, the simple calculator can
evolve into a more versatile, user-friendly, and feature-rich tool for performing mathematical
calculations in C++.

RFERENCES

1. C++ Programming Books:

• "C++ Primer" by Stanley B. Lippman, Josée Lajoie, and Barbara E. Moo.


• "Programming: Principles and Practice Using C++" by Bjarne Stroustrup.
• "Accelerated C++: Practical Programming by Example" by Andrew Koenig and Barbara E. Moo.
2. Online Tutorials and Websites:

• Websites like GeeksforGeeks (www.geeksforgeeks.org) and Tutorialspoint


(www.tutorialspoint.com) provide tutorials and examples on C++ programming, including simple
calculator implementations.
• YouTube channels such as The Cherno (https://www.youtube.com/user/TheChernoProject) and
ProgrammingKnowledge (https://www.youtube.com/user/ProgrammingKnowledge) offer video
tutorials on C++ programming for beginners.

3. C++ Programming Forums:

• Platforms like Stack Overflow (www.stackoverflow.com) have a wealth of information on C++


programming. You can find discussions, code snippets, and solutions to common programming
problems, including simple calculator implementations.

4. GitHub Repositories:

• Explore GitHub repositories that contain simple calculator implementations in C++. Searching for
keywords like "simple calculator C++" on GitHub can lead you to various open-source projects and
code examples.

5. Educational Websites:

• Websites like Codecademy (www.codecademy.com) and freeCodeCamp (www.freecodecamp.org)


offer interactive programming courses that cover C++ basics. They often include exercises and
projects, which may include creating a simple calculator.

6. Programming Communities and Forums:

• Participate in programming communities and forums like Reddit's r/learnprogramming subreddit or


the C++ section of forums like CodeProject (www.codeproject.com) and CodeGuru
(www.codeguru.com). You can ask questions, seek advice, and find resources related to C++
programming projects.

When using online resources, ensure to check the credibility and relevance of the information provided.
Additionally, referring to official C++ documentation (www.cppreference.com) can help you understand language
features and standard library functions used in your calculator implementation.

You might also like