Professional Documents
Culture Documents
Calculator
Calculator
CALCULATOR APPLICATION
Submitted by
Geeth S MY.SC.I5MCA21046
Under the guidance of
Nividita S
Assistant Professor
Department of Computer Science,
School of Computing,
Amrita Vishwa Vidyapeetham,
Mysuru, Karnataka, India
2023 - 2024
Acknowledgement
It is a great pleasure for us to acknowledge the assistance and support of many
individuals who have been responsible for the successful completion of this project
work.
First, we take this opportunity to express our sincere gratitude to School of
Computing, Am- rita Vishwa Vidyapeetham, Mysuru for providing us with a great
opportunity to pursue our Bachelor’s degree in this institution.
It is a matter of immense pleasure to express our sincere thanks to Dr. Adwitiya
Mukhopad- hyay, Professor & Chairperson, Department of Computer Science, School
of Computing, Amrita Vishwa Vidyapeetham, Mysuru Campus, for providing right
academic guidance that made our task possible.
We would like to thank our guide Prof. Nividita S, Assistant Professor, Dept. of
Computer Science for sparing her valuable time to extend help in every step of our
project work, which paved the way for smooth progress and fruitful culmination of
the project.
We are also grateful to our family and friends who provided us with every requirement
throughout the course.
We would like to thank one and all who directly or indirectly helped us in the Project
work.
Geeth S – MY.SC.I5MCA21046
CALCULATOR APPLICATION
Geeth S
Abstract
This project aims to develop a simple calculator application in C# programming language.
The calculator will provide basic arithmetic operations such as addition, subtraction,
multiplication, and division. It will feature a user-friendly interface allowing users to input
numbers and select operations through buttons or keyboard input. The application will
perform calculations accurately and display results in real-time. This project serves as a
fundamental exercise for beginners to practice C# programming concepts and GUI
development while creating a useful utility for performing basic mathematical operations.
1. Program
1.1 Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Calculator_In_a_cSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Text = "Calculator";
lblAppTitle.Text = "Calculator".ToUpper();
}
int maxSize = 0;
double total1 = 0;
double total2 = 0;
bool equalBtnClicked = false;
bool periodBtnClicked = false;
bool addBtnClicked = false;
bool subtractBtnClicked = false;
bool multiplyBtnClicked = false;
bool divideBtnClicked = false;
private void ConfirmExit()
{
if (MessageBox.Show("Do you want to exit the application?",
"Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
DialogResult.Yes)
{
Application.Exit();
}
}
private void Minimize()
{
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.WindowState = FormWindowState.Minimized;
}
}
private void PrintNumber(Button btnName)
{
if (maxSize < 19)
{
if (lblCompute.Text == "0" || equalBtnClicked == true)
{
lblCompute.Text = btnName.Text;
}
else if (lblCompute.Text == "0.")
{
lblCompute.Text += btnName.Text;
}
else
{
lblCompute.Text += btnName.Text;
}
equalBtnClicked = false;
++maxSize;
}
}
private void ClearScreen()
{
lblCompute.Text = "0";
maxSize = 0;
ResetButtons();
}
private void ResetButtons()
{
equalBtnClicked = false;
periodBtnClicked = false;
addBtnClicked = false;
subtractBtnClicked = false;
multiplyBtnClicked = false;
divideBtnClicked = false;
}
private void Operator()
{
total1 += double.Parse(lblCompute.Text);
ClearScreen();
ResetButtons();
}
private void Period()
{
if (maxSize < 19)
{
if (lblCompute.Text == "0" || equalBtnClicked == true)
{
lblCompute.Text = "0.";
equalBtnClicked = false;
}
else
{
if (periodBtnClicked == false)
{
lblCompute.Text += ".";
}
periodBtnClicked = true; ++maxSize;
}
}
}
private void Zero()
{
if (lblCompute.Text == "0" || equalBtnClicked == true)
{
lblCompute.Text = btnZero.Text;
maxSize = 0;
}
else
{
lblCompute.Text = lblCompute.Text + btnZero.Text;
++maxSize;
}
}
private void Add()
{
Operator();
addBtnClicked = true;
}
PrintNumber(btnOne);
PrintNumber(btnNine);
Minimize();
}
}
1.2 Form1.cs(Design)
2. Result
3. Conclusion
In conclusion, the development of this simple calculator in C# has been a valuable
exercise in applying fundamental programming concepts. Through this project, we
have successfully created a functional calculator application capable of performing
basic arithmetic operations. By incorporating user-friendly interfaces and real-time
result displays, we have enhanced the usability and accessibility of the calculator for
users of varying technical backgrounds. This project not only serves as a practical
tool for performing day-to-day calculations but also as a learning opportunity for
individuals seeking to improve their C# programming skills. Moving forward, there is
potential for further enhancements such as additional functionalities, improved user
interfaces, and optimization for performance. Overall, the creation of this simple
calculator in C# has been a rewarding journey, demonstrating the power and
versatility of the C# programming language in software development.