VP Calculator

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Code Implementation

Button 0-9

1. private void button1_Click(object sender, EventArgs e) {


2. if (textBox.Text == "0" || isoptr) {
3. textBox.Clear();
4. }
5. isoptr = false;
6. Button button = (Button) sender;
7. if (textBox.Text == ".") {
8. if (!textBox.Text.Contains(".")) {
9. textBox.Text += button.Text;
10. }
11. } else textBox.Text += button.Text;
12. //textBox.Text = button.Text;
13. }

Buttons Operators

1. private void button39_Click(object sender, EventArgs e) {


2. switch (abbb) {
3. case "+"
4. textBox.Text = (firstdigit + double.Parse(textBox.Text)).T
oString();
5. break;
6. case "-"
7. textBox.Text = (firstdigit - double.Parse(textBox.Text)).T
oString();
8. break;
9. case "*"
10. textBox.Text = (firstdigit * double.Parse(textBox.Text)).
ToString();
11. break;
12. case "/"
13. textBox.Text = (firstdigit / double.Parse(textBox.Text)).
ToString();
14. break;
15. }
16. }

Backspace button

1. private void button22_Click(object sender, EventArgs e) {


2. int index = textBox.Text.Length;
3. index--;
4. textBox.Text = textBox.Text.Remove(index);
5. if (textBox.Text == "") {
6. textBox.Text = "0";
7. }
8. }

Clear button

1. private void button21_Click(object sender, EventArgs e)


2. {
3. textBox.Text = "0";
4. }

± button

1. private void button23_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = result * -1;
5. textBox.Text = result.ToString();
6. }

Square root button

1. private void button11_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Sqrt(result);
5.
6. textBox.Text = result.ToString();
7. }

% button

1. private void button18_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = result / 100;
5. textBox.Text = result.ToString();
6. }

Ceil Button

1. private void button19_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Ceiling(result);
5. textBox.Text = result.ToString();
6. }

Floor Button

1. private void button20_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Floor(result);
5. textBox.Text = result.ToString();
6. }

Square Button

1. private void button12_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Pow(result,2);
5. textBox.Text = result.ToString();
6. }

Cube Button

1. private void button14_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Pow(result,3);
5. textBox.Text = result.ToString();
6. }

1/x Button

1. private void button14_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = 1/result;
5. textBox.Text = result.ToString();
6. }

MOD Button

1. private void button15_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = (firstdigit % double.Parse(textBox.Text));
5. textBox.Text = result.ToString();
6. }

Log Button

1. private void button6_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Log10(result);
5. textBox.Text = result.ToString();
6. }

Sin Button

1. private void button7_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Sin(result);
5. textBox.Text = result.ToString();
6. }

Cos Button

1. private void button8_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Cos(result);
5. textBox.Text = result.ToString();
6. }

Tan Button

1. private void button9_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Tan(result);
5. textBox.Text = result.ToString();
6. }

Pi Button

1. private void button10_Click(object sender, EventArgs e)


2. {
3.
4. result = Math.PI;
5. textBox.Text = result.ToString();
6. }

Exponential Button

1. private void button5_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Exp(result);
5. textBox.Text = result.ToString();
6. }

TanH Button

1. private void button4_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Tanh(result);
5. textBox.Text = result.ToString();
6. }

CosH Button

1. private void button3_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Cosh(result);
5. textBox.Text = result.ToString();
6. }

SinH Button

1. private void button2_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Sinh(result);
5. textBox.Text = result.ToString();
6. }

OFF Button

1. private void button1_Click_1(object sender, EventArgs e)


2. {
3. Application.Exit();
4. }
Natural Log x button

1. private void button17_Click(object sender, EventArgs e)


2. {
3. result = double.Parse(textBox.Text);
4. result = Math.Log(result);
5. textBox.Text = result.ToString();}

Output

Here is the output in which I have performed basic multiplication and used the square
root method.

Multiplication

Input
5*5
Expected output:
25

Square Root

Input
25
Expected Output
5
using System;

using System.Windows.Forms;

public partial class ScientificCalculatorForm : Form


{

private bool isOperatorClicked = false;

public ScientificCalculatorForm()

InitializeComponent();

private void DigitButton_Click(object sender, EventArgs e)

Button button = (Button)sender;

if (isOperatorClicked)

textBox.Text = button.Text;

isOperatorClicked = false;

else

textBox.Text += button.Text;

private void OperatorButton_Click(object sender, EventArgs e)

Button button = (Button)sender;

// Handle basic operators here (e.g., +, -, *, /)


isOperatorClicked = true;

private void EqualButton_Click(object sender, EventArgs e)

// Implement the code to evaluate the expression and display the result.

// You may use DataTable.Compute or other methods for evaluating expressions.

private void SquareRootButton_Click(object sender, EventArgs e)

// Implement square root function

double number = double.Parse(textBox.Text);

textBox.Text = Math.Sqrt(number).ToString();

isOperatorClicked = true;

private void SinButton_Click(object sender, EventArgs e)

// Implement sine function

double angle = double.Parse(textBox.Text);

textBox.Text = Math.Sin(angle).ToString();

isOperatorClicked = true;

private void ExpButton_Click(object sender, EventArgs e)

// Implement exponential function

double number = double.Parse(textBox.Text);


textBox.Text = Math.Exp(number).ToString();

isOperatorClicked = true;

private void PowerButton_Click(object sender, EventArgs e)

// Implement power function

double baseNumber = double.Parse(textBox.Text);

double exponent = 2; // You can modify this based on user input or use another control for entering
the exponent.

textBox.Text = Math.Pow(baseNumber, exponent).ToString();

isOperatorClicked = true;

private void BackspaceButton_Click(object sender, EventArgs e)

if (textBox.Text.Length > 0)

textBox.Text = textBox.Text.Substring(0, textBox.Text.Length - 1);

private void ClearButton_Click(object sender, EventArgs e)

textBox.Clear();

isOperatorClicked = false;

private void OffButton_Click(object sender, EventArgs e)


{

Application.Exit();

private void PiButton_Click(object sender, EventArgs e)

textBox.Text += Math.PI.ToString();

You might also like