InicioCiencia EducacionProyecto Calculadora c#
Buenos días compañeros de taringa, este es mi primer post y ya que quiero iniciar en el mundo de taringa me gustaría compartir con ustedes el siguiente proyecto que hice para la universidad.

Para empezar cuantos de ustedes no han estado buscando por toda la red como realizar una calculadora sencilla y funcional?
Pues hoy les he traído una calculadora un poco sencilla la cual podrán utilizar para mostrarles a su profesor, aprender a desarrollar una propia y por que no mejorarla.

Aquí una imagen del la calculadora desarrollada por mi.



Como podrán ver esta tiene las funciones básicas sin embargo vemos que tiene un pequeño menú arriba si desplegamos el menú ver nos mostrara estandar y cientifica



Es una calculadora algo básica pero bueno por falta de tiempo no pude terminarla como yo quería.

Y bueno lo que todos esperaban el famoso código de la calculadora. En la clase Form 1 está el código de lo que hace cada botón y cada función del programa. El Form 2 solo nos muestra algo así como un acerca de ps para darle mas estilo al proyecto ejejejejjejeje si quieren no lo pongan no va a pasar nada eso si primero deben quitar el llamado que hacel el Form 1 a el Form 2

CODIGO DE LA CALCULADORA:

FORM 1:

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 Calculadora_v2._0
{
public partial class Form1 : Form
{
private string acumulador = "";
private string operador = "";
private string acumulador1 = "";

public string getOperador()
{
return operador;
}
public void setOperador(string operador)
{
this.operador = operador;
}
public string getAcumulador()
{
return acumulador;
}
public void setAcumulador(string acumulador)
{
this.acumulador = acumulador;
}
public string getAcumulador1()
{
return acumulador1;
}
public void setAcumulador1(string acumulador1)
{
this.acumulador1 = acumulador1;
}

public Form1()
{
InitializeComponent();
button1.Click += Teclado_Numerico;
button2.Click += Teclado_Numerico;
button3.Click += Teclado_Numerico;
button4.Click += Teclado_Numerico;
button5.Click += Teclado_Numerico;
button6.Click += Teclado_Numerico;
button7.Click += Teclado_Numerico;
button8.Click += Teclado_Numerico;
button9.Click += Teclado_Numerico;
button10.Click += Teclado_Numerico;
button11.Click += Teclado_Numerico;
button20.Click += Teclado_Numerico;
button12.Click += Operaciones_Basicas;
button13.Click += Operaciones_Basicas;
button14.Click += Operaciones_Basicas;
button15.Click += Operaciones_Basicas;
button16.Click += Operaciones_Basicas;
button17.Click += Operaciones_Basicas;
button18.Click += Operaciones_Basicas;
button22.Click += Operaciones_Trigonometricas;
button23.Click += Operaciones_Trigonometricas;
button24.Click += Operaciones_Trigonometricas;
button25.Click += Operaciones_Trigonometricas;
button26.Click += Operaciones_Trigonometricas;
button27.Click += Operaciones_Trigonometricas;
button28.Click += Operaciones_Trigonometricas;
button29.Click += Operaciones_Trigonometricas;
button30.Click += Operaciones_Trigonometricas;
}


public void Teclado_Numerico(object sender, EventArgs e)
{
switch ((sender as Button).Name)
{
case "button1":
setAcumulador(getAcumulador() + "0";
textBox1.Text = getAcumulador();
break;
case "button2":
setAcumulador(getAcumulador() + "1";
textBox1.Text = getAcumulador();
break;
case "button3":
setAcumulador(getAcumulador() + "2";
textBox1.Text = getAcumulador();
break;
case "button4":
setAcumulador(getAcumulador() + "3";
textBox1.Text = getAcumulador();
break;
case "button5":
setAcumulador(getAcumulador() + "4";
textBox1.Text = getAcumulador();
break;
case "button6":
setAcumulador(getAcumulador() + "5";
textBox1.Text = getAcumulador();
break;
case "button7":
setAcumulador(getAcumulador() + "6";
textBox1.Text = getAcumulador();
break;
case "button8":
setAcumulador(getAcumulador() + "7";
textBox1.Text = getAcumulador();
break;
case "button9":
setAcumulador(getAcumulador() + "8";
textBox1.Text = getAcumulador();
break;
case "button10":
setAcumulador(getAcumulador() + "9";
textBox1.Text = getAcumulador();
break;
case "button11":
setAcumulador(getAcumulador() + ",";
textBox1.Text = getAcumulador();
break;
case "button20":
setAcumulador("-" + getAcumulador());
textBox1.Text = getAcumulador();
break;
default:
break;
}
}


public void Operaciones_Trigonometricas(object sender, EventArgs e) {
switch ((sender as Button).Name)
{
case "button22":
double valor = Convert.ToDouble(textBox1.Text);
double angulo = ((Math.PI) * (valor))/180;
double resultado = Math.Sin(angulo);
double nuevo = Math.Round(resultado, 12);
textBox1.Text = Convert.ToString(nuevo);
break;
case "button23":
double valor1 = Convert.ToDouble(textBox1.Text);
double angulo1 = ((Math.PI) * (valor1)) / 180;
double resultado1 = Math.Cos(angulo1);
double nuevo1 = Math.Round(resultado1, 12);
textBox1.Text = Convert.ToString(nuevo1);
break;
case "button24":
double valor2 = Convert.ToDouble(textBox1.Text);
double angulo2 = ((Math.PI) * (valor2)) / 180;
double resultado2 = Math.Tan(angulo2);
double nuevo2 = Math.Round(resultado2, 12);
textBox1.Text = Convert.ToString(nuevo2);
break;
case "button25":
double valor3 = Convert.ToDouble(textBox1.Text);
double resultado3 = Math.Pow(valor3,2);
double nuevo3 = Math.Round(resultado3, 12);
textBox1.Text = Convert.ToString(nuevo3);
break;
case "button26":
double valor4 = Convert.ToDouble(textBox1.Text);
double resultado4 = Math.Pow(valor4, 3);
double nuevo4 = Math.Round(resultado4, 12);
textBox1.Text = Convert.ToString(nuevo4);
break;
case "button27":
setAcumulador1(getAcumulador());
setAcumulador(null);
setOperador("^";
break;
case "button28":
double valor5 = Convert.ToDouble(textBox1.Text);
double angulo5 = ((Math.PI) * (valor5)) / 180;
double resultado5 = Math.Sinh(angulo5);
double nuevo5 = Math.Round(resultado5, 12);
textBox1.Text = Convert.ToString(nuevo5);
break;
case "button29":
double valor6 = Convert.ToDouble(textBox1.Text);
double angulo6 = ((Math.PI) * (valor6)) / 180;
double resultado6 = Math.Cosh(angulo6);
double nuevo6 = Math.Round(resultado6, 12);
textBox1.Text = Convert.ToString(nuevo6);
break;
case "button30":
double valor7 = Convert.ToDouble(textBox1.Text);
double angulo7 = ((Math.PI) * (valor7)) / 180;
double resultado7 = Math.Tanh(angulo7);
double nuevo7 = Math.Round(resultado7, 12);
textBox1.Text = Convert.ToString(nuevo7);
break;
}
}

public void Operaciones_Basicas(object sender, EventArgs e)
{
switch ((sender as Button).Name)
{
case "button12":
setAcumulador1(getAcumulador());
setAcumulador(null);
setOperador("+";
break;
case "button13":
setAcumulador1(getAcumulador());
setAcumulador(null);
setOperador("-";
break;
case "button15":
setAcumulador1(getAcumulador());
setAcumulador(null);
setOperador("*";
break;
case "button16":
setAcumulador1(getAcumulador());
setAcumulador(null);
setOperador("/";
break;
case "button17":
setAcumulador1(getAcumulador());
setAcumulador(null);
setOperador("raiz";
break;
case "button18":
setAcumulador1(getAcumulador());
setAcumulador(null);
setOperador("/2";
break;
default:
break;
}
}

private void acercaDeToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}

private void button14_Click(object sender, EventArgs e)
{
if(getOperador()=="+"
{
double primervalor = Convert.ToDouble(getAcumulador1());
double segundovalor = Convert.ToDouble(getAcumulador());
double suma = primervalor + segundovalor;
string resultado = Convert.ToString(suma);
setAcumulador(resultado);
textBox1.Text=resultado;
}else
{
if (getOperador() == "-"
{
double primervalor = Convert.ToDouble(getAcumulador1());
double segundovalor = Convert.ToDouble(getAcumulador());
double resta = primervalor - segundovalor;
string resultado = Convert.ToString(resta);
setAcumulador(resultado);
textBox1.Text = resultado;
}
else
{
if (getOperador() == "*"
{
double primervalor = Convert.ToDouble(getAcumulador1());
double segundovalor = Convert.ToDouble(getAcumulador());
double producto = primervalor * segundovalor;
string resultado = Convert.ToString(producto);
setAcumulador(resultado);
textBox1.Text = resultado;
}
else
{
if (getOperador() == "/"
{
double primervalor = Convert.ToDouble(getAcumulador1());
double segundovalor = Convert.ToDouble(getAcumulador());
if (segundovalor == 0.0)
{
textBox1.Text = "Math Error";
}
else
{
double cociente = primervalor / segundovalor;
string resultado = Convert.ToString(cociente);
setAcumulador(resultado);
textBox1.Text = resultado;
}
}
else
{
if (getOperador() == "/2"
{
double primervalor = Convert.ToDouble(getAcumulador1());
double cociente = 1 / primervalor;
string resultado = Convert.ToString(cociente);
setAcumulador(resultado);
textBox1.Text = resultado;
}
else
{
if (getOperador() == "raiz"
{
double primervalor = Convert.ToDouble(getAcumulador1());
double raiz = Math.Sqrt(primervalor);
string resultado = Convert.ToString(raiz);
setAcumulador(resultado);
textBox1.Text = resultado;
}
else
{
if (getOperador() == "^"
{
double primervalor = Convert.ToDouble(getAcumulador1());
double segundovalor = Convert.ToDouble(getAcumulador());
double potencia = Math.Pow(primervalor,segundovalor);
string resultado = Convert.ToString(potencia);
setAcumulador(resultado);
textBox1.Text = resultado;
}

}
}
}
}
}
}

}

private void button19_Click(object sender, EventArgs e)
{
setAcumulador(null);
setAcumulador1(null);
textBox1.Text = "0";
}

private void button21_Click(object sender, EventArgs e)
{
int ultimocaracter = textBox1.Text.Length - 1;
string linea = textBox1.Text.Substring(0, ultimocaracter);
string acum = linea;
textBox1.Text=null;
textBox1.Text = acum;
}

private void cientificaToolStripMenuItem_Click(object sender, EventArgs e)
{
ActiveForm.ClientSize = new Size(414, 285);
button1.Location = new Point(212, 242);
button2.Location = new Point(212, 205);
button3.Location = new Point(249, 205);
button4.Location = new Point(286, 205);
button5.Location = new Point(212, 168);
button6.Location = new Point(249, 168);
button7.Location = new Point(286, 168);
button8.Location = new Point(212, 131);
button9.Location = new Point(249, 131);
button10.Location = new Point(286, 131);
button11.Location = new Point(286, 242);
button12.Location = new Point(334, 242);
button13.Location = new Point(334, 205);
button14.Location = new Point(371, 205);
button15.Location = new Point(334, 168);
button16.Location = new Point(371, 168);
button17.Location = new Point(334, 131);
button18.Location = new Point(371, 131);
button19.Location = new Point(286, 94);
button20.Location = new Point(371, 94);
button21.Location = new Point(212, 94);
button22.Visible = true;
button23.Visible = true;
button24.Visible = true;
button25.Visible = true;
button26.Visible = true;
button27.Visible = true;
button28.Visible = true;
button29.Visible = true;
button30.Visible = true;
textBox1.Size = new Size(403, 41);
}

private void estandarToolStripMenuItem_Click(object sender, EventArgs e)
{
ActiveForm.ClientSize = new Size(214, 285);
button1.Location = new Point(12, 242);
button2.Location = new Point(12, 205);
button3.Location = new Point(49, 205);
button4.Location = new Point(86, 205);
button5.Location = new Point(12, 168);
button6.Location = new Point(49, 168);
button7.Location = new Point(86, 168);
button8.Location = new Point(12, 131);
button9.Location = new Point(49, 131);
button10.Location = new Point(86, 131);
button11.Location = new Point(86, 242);
button12.Location = new Point(134, 242);
button13.Location = new Point(134, 205);
button14.Location = new Point(171, 205);
button15.Location = new Point(134, 168);
button16.Location = new Point(171, 168);
button17.Location = new Point(134, 131);
button18.Location = new Point(171, 131);
button19.Location = new Point(86, 94);
button20.Location = new Point(171, 94);
button21.Location = new Point(12, 94);
button22.Visible = false;
button23.Visible = false;
button24.Visible = false;
button25.Visible = false;
button26.Visible = false;
button27.Visible = false;
button28.Visible = false;
button29.Visible = false;
button30.Visible = false;
textBox1.Size = new Size(203, 41);
}
}
}

FORM 2

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 Calculadora_v2._0
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
pictureBox1.Image = Image.FromFile("D:\Users\helpdesk\Pictures\Logo1.jpg";
}

private void button1_Click(object sender, EventArgs e)
{
new Form2();
this.Close();
}

}
}

jejejejejej bueno al parecer taringa me toma " ); " como si fueran un emoticon jajjajajaja pero en realidad solo tienen que cambiarlos por " ); "

Espero que lo disfruten y que le saquen provecho. Si quieren la explicación del código con gusto haré otro post para explicarlo.

Gracias por su atención.
Datos archivados del Taringa! original
10puntos
36visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
2visitas
0comentarios
Dar puntos:

Dejá tu comentario

0/2000

Autor del Post

c
Usuario
Puntos0
Posts1
Ver perfil →
PosteameloArchivo Histórico de Taringa! (2004-2017). Preservando la inteligencia colectiva de la internet hispanohablante.

CONTACTO

18 de Septiembre 455, Casilla 52

Chillán, Región de Ñuble, Chile

Solo correo postal

© 2026 Posteamelo.com. No afiliado con Taringa! ni sus sucesores.

Contenido preservado con fines históricos y culturales.