Final Pps Project
Final Pps Project
Submitted to
Mr. Arjun Rai Dutta
Assistant Professor
Submitted by: Group
Piyush Gaurav- (1000025085)
Satyam Ujjain- (1000025565)
Ayush Gupta- (1000025271)
Naman Kaushik- (1000024341)
SECTION -
SCHOOL OF COMPUTING
DIT UNIVERSITY,
DEHRADUN
(State Private University through State Legislature Act No. 10 of 2013 of Uttarakhand and approved by
UGC)
I hereby certify that the work, which is being presented in the Report, entitled “project title”,
in partial fulfilment of the requirement as part of the course Programming for Problem
Solving of the Degree of Bachelor of Computer Science and Engineering and submitted to
the DIT University is an authentic record of my work carried out during the period 12/10/2024
to 07/11/2024 under the guidance of Dr. Prabhjot Kaur.
Introduction iv
Project Description v
Methods and vi - x vi
Bibliography xix
Introduction
This Simple Calculator project was developed as a hands-on application of foundational C programming
concepts. The Simple calculator is the four-function calculator, which can perform basic arithmetic such as
addition, subtraction, multiplication and division. Four-function calculators usually have a +, -, x and / sign
to denote the operations and can produce decimal numbers. Some also have a %, ^ button, which is used to
calculate percentages and squares respectively.
The project was coded and tested using the Programiz online C compiler, ensuring that it runs efficiently on
minimal resources. Additionally, guidance from class lectures and notes provided by Mr. Arjun Rai Dutta
Sir,
, alongside minor assistance from ChatGPT, contributed to understanding and implementing robust error
handling and control structures. This project not only showcases C programming techniques but also
reinforces concepts essential to building interactive applications, setting a solid foundation for further
programming challenges and games.
Project Description
Purpose:
To perform basic arithmetic such as addition, subtraction, multiplication, division, percentage and
square.
Problem statement:
The goal is to design and implement a simple calculator that can perform basic arithmetic
operations such as addition, subtraction, multiplication, division, percentage and square.
The calculator should accept numerical inputs from the user and return the correct results
for these operations. The problem involves creating an interface that allows users to input
numbers and operators, and then displays the output of the calculation.
1. Input Handling:
o Get two numbers from the user.
o Ask for the operator (+, -, *, /, % or ^).
2. Perform Calculation:
o Use a switch-case or if-else to perform the required arithmetic operation
based on the input operator.
3. Error Handling:
o Check for division by zero.
o Handle invalid operators.
4. Output the Result:
o Display the result of the operation.
Algorithm :
Algorithm for a simple calculator that handles basic operations like addition, subtraction,
multiplication, and division:
1. Start
2. Declare the variables
(Num1 and Num2 as float
Choice as int)
3. Input the choice
(+, -, *, /, %, ^)
4. Input the first number.
5. Input the second number.
(Check if operation needs second no. or not)
6. Call the function on the basis of given input
(Between 1 to 6)
7. Perform the function
a. Addition (num1+num2)
b. Subtraction (num1-num2)
c. Multiplication (num1*num2)
d. Division (num1/num2)
e. Percentage (num1*num2/100)
f. Square (num1*num1)
8. Print the result.
9. Stop
Data Structure:
For a simple calculator, the data structure mainly involves storing the two numbers (operands)
and the operator.
C Code:
The full C code for the Simple calculator:
// Main function
int main() {
// Declare variables to store user input and choice
float num1, num2;
int choice;
case 2: // Subtraction
printf("-------------------------------------\n");
printf("Result: %.2f - %.2f = %.2f\n", num1, num2, subtract(num1, num2));
printf("-------------------------------------\n");
break;
case 3: // Multiplication
printf("-------------------------------------\n");
printf("Result: %.2f * %.2f = %.2f\n", num1, num2, multiply(num1, num2));
printf("-------------------------------------\n");
break;
case 4: // Division
// Check for division by zero
if (num2 == 0) {
printf("-------------------------------------\n");
printf("Error! Division by zero is not allowed.\n");
printf("-------------------------------------\n");
} else {
printf("-------------------------------------\n");
printf("Result: %.2f / %.2f = %.2f\n", num1, num2, divide(num1, num2));
printf("-------------------------------------\n");
}
break;
case 5: // Percentage
printf("-------------------------------------\n");
printf("Result: %.2f %% of %.2f = %.2f\n", num1, num2, percentage(num1, num2));
printf("-------------------------------------\n");
break;
case 6: // Square
printf("-------------------------------------\n");
printf("Result: %.2f squared = %.2f\n", num1, square(num1));
printf("-------------------------------------\n");
break;
A simple calculator is an essential and practical tool that performs basic arithmetic operations such
as addition, subtraction, multiplication, division, percentage and square making it invaluable for
everyday calculations. While its functionality is straightforward, the accuracy and efficiency of the
calculator are critical in ensuring that users can quickly and reliably obtain the results they need. A
well-designed simple calculator should also be able to handle edge cases, such as division by zero
or operations involve ing negative numbers, without crashing or giving incorrect results.
Additionally, the user experience plays a significant role in the success of a simple calculator. It
should feature an intuitive and easy- to-navigate interface with clear input options and fast response
times, allowing users to perform calculations seamlessly. Whether on a physical device or as part of
a software application, a good calculator minimizes the potential for errors and maximizes
convenience. Overall, a simple calculator, when designed with attention to accuracy, speed, and
usability, proves to be an indispensable tool that can save time and effort in everyday tasks, from
balancing a budget to solving quick math problems. A simple calculator serves as an essential tool
for performing basic arithmetic operations like addition, subtraction, multiplication, and division.
Its primary purpose is to provide accurate and efficient calculations, ensuring users can quickly
obtain results for everyday math tasks. For optimal performance, the calculator should handle
special cases, such as division by zero or negative numbers, without errors. Additionally, a user-
friendly interface is key, offering clear input options and quick feedback. When designed
effectively, a simple calculator is not only reliable and fast but also easy to use, making it an
indispensable tool for both casual and professional use.
In summary, The calculator can be implemented using simple conditional structures (like if or
switch) and basic input/output functions. It ensures that operations are performed correctly, handles
errors gracefully, and provides clear feedback to the user.
Overall, the simple calculator is a useful, easy-to-implement tool for basic mathematical operations,
making it an ideal starting project for learning programming concepts like functions, conditionals,
and user input handling.
Bibliography
2. ChatGPT Assistance
- Consulted for guidance on code structuring, error handling, and best practices in C
programming.