CodeS-SourceS
Rechercher un code, un tuto, une réponse

Calculatrice scientifique

Soyez le premier à donner votre avis sur cette source.

Snippet vu 5 502 fois - Téléchargée 5 fois

Contenu du snippet

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 CalculatriceCsharp
{
public partial class Form1 : Form
{
public string no1, constfun;
public bool inputstatus;
public double memory;

public Form1()
{
InitializeComponent();
no1 = "";
textBox1.ReadOnly = true; //read only mode of textbox
textBox1.RightToLeft = RightToLeft.Yes;
radioButton1.Checked = true;
}
string operateur;
private void scientifiqueToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "1";
}

private void button13_Click(object sender, EventArgs e)
{
textBox1.Text += "2";
}

private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += "3";
}

private void button14_Click(object sender, EventArgs e)
{
textBox1.Text += "4";
}

private void button5_Click(object sender, EventArgs e)
{
textBox1.Text += "5";
}

private void button12_Click(object sender, EventArgs e)
{
textBox1.Text += "6";
}

private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += "7";
}

private void button21_Click(object sender, EventArgs e)
{
textBox1.Text += "8";
}

private void button17_Click(object sender, EventArgs e)
{
if (inputstatus == true)
{
textBox1.Text += "9";
}
else
{
textBox1.Text += "9";
inputstatus = true;
}
}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += "0";
}

private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += ",";
}

private void button4_Click(object sender, EventArgs e)
{
textBox1.Text += "+";
operateur = "+";
}

private void button8_Click(object sender, EventArgs e)
{
textBox1.Text += "-";
operateur = "-";
}

private void button11_Click(object sender, EventArgs e)
{
textBox1.Text += "*";
operateur = "*";
}

private void button16_Click(object sender, EventArgs e)
{
textBox1.Text += "/";
operateur = "/";
}
private void funcal()
{
switch (constfun)
{
case "+":
textBox1.Text = Convert.ToString(Convert.ToInt32(no1) + Convert.ToInt32(textBox1.Text)); //ading values of textbox

break;
case "-":
textBox1.Text = Convert.ToString(Convert.ToInt32(no1) - Convert.ToInt32(textBox1.Text));

break;
case "*":
textBox1.Text = Convert.ToString(Convert.ToInt32(no1) * Convert.ToInt32(textBox1.Text));
break;
case "/":
if (textBox1.Text == "0")
{
textBox1.Text = "infinity";
}
else
{
textBox1.Text = Convert.ToString(Convert.ToInt32(no1) / Convert.ToInt32(textBox1.Text));
}
break;
case "x^y":
textBox1.Text = Convert.ToString(System.Math.Pow(Convert.ToDouble(no1), Convert.ToDouble(textBox1.Text)));
break;
case "mod":
textBox1.Text = Convert.ToString(Convert.ToDouble(no1) % Convert.ToDouble(textBox1.Text));
break;
case "nPr": int varn, var2, var3; //variable declaration
varn = factorial(Convert.ToInt32(no1)); //calling factorial function
var2 = factorial(Convert.ToInt32(no1) - Convert.ToInt32(textBox1.Text));
textBox1.Text = Convert.ToString(varn / var2); //storing or showing result of factorial variables
break;
case "nCr":
varn = factorial(Convert.ToInt32(no1));
var2 = factorial(Convert.ToInt32(no1) - Convert.ToInt32(textBox1.Text));
var3 = factorial(Convert.ToInt32(textBox1.Text));
textBox1.Text = Convert.ToString(varn / (var3 * var2));
break;


}
}
//a user defined function to calculate factorial
private int factorial(int x)
{
int i = 1; //initialization values of i to 1
for (int s = 1; s <= x; s++)
{
i = i * s;
}
return i;
}



private void button6_Click(object sender, EventArgs e)
{
if(operateur == "+")
{
string[] chaine = textBox1.Text.Split('+');
textBox1.Text +=Environment.NewLine +"="+Environment.NewLine + (double.Parse(chaine[0]) + double.Parse(chaine[1])).ToString();
}
if (operateur == "-")
{
string[] chaine = textBox1.Text.Split('-');
textBox1.Text += Environment.NewLine + "=" + Environment.NewLine + (double.Parse(chaine[0]) - double.Parse(chaine[1])).ToString();
}
if (operateur == "*")
{
string[] chaine = textBox1.Text.Split('*');
textBox1.Text += Environment.NewLine + "=" + Environment.NewLine + (double.Parse(chaine[0]) * double.Parse(chaine[1])).ToString();
}
if (operateur == "/")
{
string[] chaine = textBox1.Text.Split('/');
if(double.Parse(chaine[1])!=0)
textBox1.Text += Environment.NewLine + "=" + Environment.NewLine + (double.Parse(chaine[0]) / double.Parse(chaine[1])).ToString();
}
funcal(); //calling of function
inputstatus = false;

}

private void button24_Click(object sender, EventArgs e)
{
textBox1.Enabled = true;
textBox1.Text = "0";
}

private void button19_Click(object sender, EventArgs e)
{
textBox1.Text = String.Empty;
inputstatus = true;
}

private void button44_Click(object sender, EventArgs e)
{
//if degree is selected
if(radioButton1.Checked==true)
{
textBox1.Text = Convert.ToString(System.Math.Sin((Convert.ToDouble(System.Math.PI)/180)*(Convert.ToDouble(textBox1.Text))));
inputstatus = false;
}
//if radian is selected
else if(radioButton2.Checked==true)
{
textBox1.Text = Convert.ToString(System.Math.Sin(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}


}

private void button54_Click(object sender, EventArgs e)
{
textBox1.Enabled = false;
textBox1.Text = "";
inputstatus = false;
}

private void button32_Click(object sender, EventArgs e)
{
int var1 = 1;
for (int i = 1; i <= Convert.ToInt16(textBox1.Text); i++)
{
var1 = var1 * i;
}
textBox1.Text = Convert.ToString(var1);
inputstatus = false;
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void button35_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox1.Text));
inputstatus = false;
}

private void button37_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox1.Text));
inputstatus = false;
}

private void button33_Click(object sender, EventArgs e)
{

}

private void button36_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "x^y";
}

private void button53_Click(object sender, EventArgs e)
{
textBox1.Text = "3.141592654";
}

private void button45_Click(object sender, EventArgs e)
{
//radian selected
if (radioButton2.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Cos(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
//degree selected
else
{
textBox1.Text = Convert.ToString(System.Math.Cos((Convert.ToDouble(System.Math.PI) / 180) * (Convert.ToDouble(textBox1.Text))));
inputstatus = false;
}
}

private void button42_Click(object sender, EventArgs e)
{
//radian selected
if (radioButton2.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Tan(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
//degree selected
else
{
textBox1.Text = Convert.ToString(System.Math.Tan((Convert.ToDouble(System.Math.PI) / 180) * (Convert.ToDouble(textBox1.Text))));
inputstatus = false;
}
}

private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(Convert.ToDouble(1.0 / Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}

private void button38_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(System.Math.Log10(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}

private void button43_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(System.Math.Log(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}

private void button18_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
int n = no1.Length;
textBox1.Text = (no1.Substring(0, n - 1)); //removing values one by one onclick of backspace button
}

private void button41_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "mod"; //explaned earlier to calculate mod in fncalc()
}

private void button23_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(-Convert.ToInt32(textBox1.Text));
inputstatus = false;
}

private void button22_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(System.Math.Sqrt(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}

private void button57_Click(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Asin(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
else
{
textBox1.Text = Convert.ToString(System.Math.Asin((Convert.ToDouble(System.Math.PI) / 180) * (Convert.ToDouble(textBox1.Text))));
inputstatus = false;
}
}

private void button56_Click(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Acos(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
else
{
textBox1.Text = Convert.ToString(System.Math.Acos((Convert.ToDouble(System.Math.PI) / 180) * (Convert.ToDouble(textBox1.Text))));
inputstatus = false;
}
}

private void button55_Click(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Atan(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
else
{
textBox1.Text = Convert.ToString(System.Math.Atan((Convert.ToDouble(System.Math.PI) / 180) * (Convert.ToDouble(textBox1.Text))));
inputstatus = false;
}
}

private void button58_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "nPr";
}

private void button50_Click(object sender, EventArgs e)
{
no1 = textBox1.Text;
textBox1.Text = "";
constfun = "nCr";
}

private void button27_Click(object sender, EventArgs e)
{
textBox1.Enabled = true;
textBox1.Text = "0";

}

private void button39_Click(object sender, EventArgs e)
{

}

private void button31_Click(object sender, EventArgs e)
{

}

private void button47_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Sinh((Convert.ToDouble(System.Math.PI) / 180) * Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
//if radian is selected
else if (radioButton2.Checked == true)
{
textBox1.Text = Convert.ToString(System.Math.Sinh(Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}
}

private void button46_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(System.Math.Cosh((Convert.ToDouble(System.Math.PI) / 180) * Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}

private void button40_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(System.Math.Tanh((Convert.ToDouble(System.Math.PI) / 180) * Convert.ToDouble(textBox1.Text)));
inputstatus = false;
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{

}

private void button29_Click(object sender, EventArgs e)
{

}

private void button20_Click(object sender, EventArgs e)
{
memory = 0;
textBox1.Text = null;
}
}
}

Compatibilité : 5.02

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.