0% found this document useful (0 votes)
14 views

Final Pps Project

This is a C project of simple calculator which I and my teammates have created using basic C concepts like switch case and functions.

Uploaded by

satyamujjain2508
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Final Pps Project

This is a C project of simple calculator which I and my teammates have created using basic C concepts like switch case and functions.

Uploaded by

satyamujjain2508
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

PROJECT REPORT (CSN101)

A report submitted in partial fulfilment of the requirement for the course

PROGRAMMING FOR PROBLEM SOLVING


Part of the degree of

BACHELOR OF COMPUTER SCIENCE AND ENGINEERING

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)

Mussoorie Diversion Road, Dehradun, Uttarakhand - 248009, India.


November, 2024
CANDIDATES DECLARATION

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.

Date : 11/11/2024 Signature of the Candidate :


TABLE OF CONTENT
CHAPTER PAGE No.

Introduction iv

Project Description v

Methods and vi - x vi

Implementation Results and xvii

Analysis Conclusion xviii

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.

Hardware and software requirements:


Hardware Requirements:
Asus vivobook Laptop with 6GB RAM and 512GB
SSD. Software Requirements:
Operating System: Windows 11
Compiler: Online C compiler- Programiz.
Methods and Implementation

Modules and Functions:

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:

#include <stdio.h> // Required for input and output functions

// Function prototypes for calculator operations


float add(float num1, float num2);
float subtract(float num1, float num2);
float multiply(float num1, float num2);
float divide(float num1, float num2);
float percentage(float num1, float num2);
float square(float num1);

// Main function
int main() {
// Declare variables to store user input and choice
float num1, num2;
int choice;

// Print the program title


printf("=====================================\n");
printf(" SIMPLE CALCULATOR\n");
printf("=====================================\n");

// Display the menu options to the user


printf("Select an operation to perform:\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("5. Percentage\n");
printf("6. Square\n");
printf("-------------------------------------\n");

// Prompt the user to enter their choice


printf("Enter your choice (1, 2, 3, 4, 5 or 6): ");
scanf("%d", &choice);

// Check if the input is within the valid range


if (choice < 1 || choice > 6) {
// Invalid choice handling
printf("Invalid input! Please restart the program and choose a valid option.\n");
return 1; // Exit the program with an error code
}

// Prompt the user to enter the first number


printf("Enter the first number: ");
scanf("%f", &num1);

// For some operations, we need a second number


if (choice != 6) {
// Prompt the user to enter the second number
printf("Enter the second number: ");
scanf("%f", &num2);
}

// Perform the selected operation based on user's choice


switch (choice) {
case 1: // Addition
printf("-------------------------------------\n");
printf("Result: %.2f + %.2f = %.2f\n", num1, num2, add(num1, num2));
printf("-------------------------------------\n");
break;

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;

default: // Redundant default case for safety


printf("Unexpected error occurred.\n");
break;
}

// End of program message


printf("Thank you for using the Simple Calculator!\n");
printf("=====================================\n");

return 0; // Exit the program successfully


}

// Function to perform addition


float add(float num1, float num2) {
// Return the sum of num1 and num2
return num1 + num2;
}

// Function to perform subtraction


float subtract(float num1, float num2) {
// Return the difference of num1 and num2
return num1 - num2;
}

// Function to perform multiplication


float multiply(float num1, float num2) {
// Return the product of num1 and num2
return num1 * num2;
}

// Function to perform division


float divide(float num1, float num2) {
// Return the quotient of num1 and num2
return num1 / num2;
}

// Function to calculate the percentage of num1 based on num2


float percentage(float num1, float num2) {
// Return the percentage (num1 % of num2)
return (num1 * num2) / 100;
}

// Function to calculate the square of num1


float square(float num1) {
// Return the square of num1
return num1 * num1;
}
Screen shots of outputs:
Result analysis
A result analysis for a simple calculator involves evaluating how well the calculator performs
its intended tasks. This includes understanding the accuracy, speed, and user experience of the
tool. Here’s a breakdown:
1. Accuracy of Calculations
 Expected Outcome: The calculator should accurately perform basic arithmetic operations
(addition, subtraction, multiplication, division) and handle edge cases (e.g., dividing by
zero, large numbers).
 Analysis: If the calculator produces correct results for simple calculations, such as:
o 2+2=4
o 5 * 6 = 30
o 9÷3=3
 Conclusion: The calculator is functioning correctly if all operations return the
expected results.
2. Handling of Special Cases
 Expected Outcome: The calculator should correctly handle edge cases like division
by zero, negative numbers, and decimal values.
 Analysis:
o Division by zero: Should display an error or "undefined" message.
o Negative numbers: Should accept inputs such as -5 + 3 and return correct results.
o Decimals: Should support operations like 5.5 + 4.2.
 Conclusion: If these cases are handled properly, the calculator is robust and user-friendly.
3. Speed of Calculation
 Expected Outcome: The calculator should provide results instantly or with minimal delay.
 Analysis: If the calculator performs operations quickly (e.g., within a second), it
indicates that the program is optimized.
 Conclusion: Speed is crucial for user satisfaction, especially for frequent and rapid use.
A slow calculator may frustrate users.
Conclusion

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

1. Programiz Online Compiler


- Used for compiling and testing C code online. Accessible
at: [https://www.programiz.com/c-programming/online-
compiler]

2. ChatGPT Assistance
- Consulted for guidance on code structuring, error handling, and best practices in C
programming.

3. Class Notes and Lectures by Mr. Arjun Rai Dutta Sir


- Provided foundational understanding of procedural programming, control structures, and
debugging techniques in C.

You might also like