SUBDIRECCIÓN ACADÉMICA
DEPARTAMENTO DE SISTEMAS Y COMPUTACIÓN
SEMESTRE AGOSTO-DICIEMBRE 2013
ING. EN SISTEMAS COMPUTACIONALES
FUNDAMENTOS DE PROGRAMACION 2SC1
Otros 1
UNIDAD 3
ALVAREZ LAPIZCO MIGUEL ANGEL
13211477
RODRIGUEZ MORENO MARCO ANTONIO
Indice
Introducción ... 1
Practica 1: Hola mundo! ... 2
Practica 2: Suma (2 + 3) ... 3
Practica 3: Suma de dos numeros ... 4
4. Nombre y edad ... 5
5. Area del circulo ... 6
6. Formula general ... 7
“” ... 8
7. Operaciones basicas ... 9
“” ... 10
8. Areas ... 11
“” ... 12
“” ... 13
9. Promedio de 6 calificaciones ... 14
10. Promedio (random) ... 15
11. Bebida (If) ... 16
12. Promedio (If) ... 17
“” ... 18
13. Numero mayor (If) ... 19
14. Numero menor (If) ... 20
15. Edad menor (If) ... 21
16. Edad (100 años) ... 22
17. MenuStrip ... 23
“ ... 24
“” ... 25
“” ... 26
“” ... 27
Conclusión ... 28
1
Introducción
En este proyecto comenzamos a aprender más detalladamente los
elementos que son base del C#, más adelante en este caso vemos lo que
es el “If” y comenzamos a aplicarla en práctica.
Vemos las prácticas cada vez más complejas conforme a lo que vamos
aprendiendo, estamos viendo la teoría y el uso práctico del “If” así como el
“MenusStrip” y otros elementos más simples como las variables usando Int,
Double, etc.
2
Practica 1: Hola mundo!
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button2_Click(object sender, EventArgs e) {
MessageBox.Show("Hola mundo!"); }
private void button1_Click(object sender, EventArgs e) {
button4.Visible = false; }
private void button3_Click(object sender, EventArgs e) {
Close(); }
} }
3
Practica 2: Suma (2 + 3)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication2 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button2_Click(object sender, EventArgs e) {
int suma; suma = 2 + 3;
MessageBox.Show("Tu resultado es: " + suma); }
private void button1_Click(object sender, EventArgs e) {
}
private void button3_Click(object sender, EventArgs e) {
Close(); }
} }
4
Practica 3: Suma de dos números.
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button3_Click(object sender, EventArgs e) {
double a, b, res;
a = Convert.ToDouble(textBox1.Text); b = Convert.ToDouble(textBox2.Text); res = a + b;
MessageBox.Show("Tu resultado es : " + res); }
private void button4_Click(object sender, EventArgs e) {
Close(); }
private void button2_Click(object sender, EventArgs e) { button1.Visible = false; label4.Visible = false; textBox1.Clear(); textBox2.Clear(); } } }
5
Practica 4: Nombre y edad.
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button2_Click(object sender, EventArgs e) {
string nombre;
nombre = textBox1.Text; int edad;
edad = Convert.ToInt16(textBox2.Text);
MessageBox.Show("Tu nombre es " + nombre + " y tienes " + edad + " años."); }
private void button4_Click(object sender, EventArgs e) {
Close(); }
private void button3_Click(object sender, EventArgs e) { textBox2.Clear(); textBox1.Clear(); } } }
6
Practica 5: Area de un circulo
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button3_Click(object sender, EventArgs e) {
Close(); }
private void button2_Click(object sender, EventArgs e) {
double r, res;
r = Convert.ToDouble(textBox1.Text); res = (r * r) * 3.1416;
MessageBox.Show("Tu resultado es : " + res); }
private void button1_Click(object sender, EventArgs e) {
textBox1.Clear(); }
} }
7
Practica 6: Formula General.
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) {
}
private void button3_Click(object sender, EventArgs e) {
Close(); }
private void cal_Click(object sender, EventArgs e) {
Double a, b, c, res1, res2;
a = Convert.ToDouble(textBox1.Text); b = Convert.ToDouble(textBox2.Text); c = Convert.ToDouble(textBox3.Text);
res1 = (-b + (Math.Sqrt(Math.Pow(b, 2)) - (4 * a * c) ) / (2*a)); res2 = (-b - (Math.Sqrt(Math.Pow(b, 2)) - (4 * a * c) ) / (2*a));
8
MessageBox.Show("Tus resultados son : " + res1 + " y " + res2); }
private void lim_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); } } }
9
Practica 7: Operaciones basicas.
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void label2_Click(object sender, EventArgs e) {
}
private void Form1_Load(object sender, EventArgs e) {
}
private void cmddiv_Click(object sender, EventArgs e) {
int div, a, b;
a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); div = a / b;
MessageBox.Show("Tu resultado es : " + div); }
private void cmdcal_Click(object sender, EventArgs e) {
10
textBox2.Clear(); label4.Text = " ";
}
private void cmdsalir_Click(object sender, EventArgs e) {
Close(); }
private void cmdsumar_Click(object sender, EventArgs e) {
int suma, a, b;
a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); suma = a + b;
MessageBox.Show("Tu resultado es : " + suma); }
private void cmdrestar_Click(object sender, EventArgs e) {
int res, a, b;
a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); res = a - b;
MessageBox.Show("Tu resultado es : " + res); }
private void cmdmulti_Click(object sender, EventArgs e) {
int multi, a, b;
a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); multi = a * b;
MessageBox.Show("Tu resultado es : " + multi); }
private void textBox1_TextChanged(object sender, EventArgs e) {
}
private void pictureBox1_Click(object sender, EventArgs e) {
} } }
11
Practica 8: Areas.
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
12
}
private void button1_Click(object sender, EventArgs e) { label2.Visible = false; button2.Visible = false; button3.Visible = false; button4.Visible = false; label2.Visible = false; labelradio.Visible = true; txtradio.Visible = true; calcular.Visible = true; resultadocir.Visible = true; }
private void calcular_Click(object sender, EventArgs e) {
double r, res;
r = Convert.ToDouble(txtradio.Text); res = r * r * 3.1416;
MessageBox.Show("Tu resultado es : " + res); }
private void salir_Click(object sender, EventArgs e) {
Close(); }
private void button2_Click(object sender, EventArgs e) { label2.Visible = false; button1.Visible = false; button3.Visible = false; button4.Visible = false; txtalturatri.Visible = true; txtbasetri.Visible = true; basetri.Visible = true; alturatri.Visible = true; calculartri.Visible = true; resultadotri.Visible = true; }
private void calculartri_Click(object sender, EventArgs e) {
double a, b, res;
a = Convert.ToDouble(txtalturatri.Text); b = Convert.ToDouble(txtbasetri.Text); res = (a * b) / 2;
MessageBox.Show("Tu resultado es : " + res); }
private void regresar_Click(object sender, EventArgs e) {
13
private void Form1_Load(object sender, EventArgs e) {
} } }
14
Practica 9: Promedio de 6 calificaciones.
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programacion
* Matricula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { double a, b, c, d, Z, f, res; a = Convert.ToDouble(textBox1.Text); b = Convert.ToDouble(textBox2.Text); c = Convert.ToDouble(textBox3.Text); d = Convert.ToDouble(textBox4.Text); Z = Convert.ToDouble(textBox5.Text); f = Convert.ToDouble(textBox6.Text); res = (a + b + c + d + Z + f) / 6;
MessageBox.Show("Tu promedio es: " + res); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); textBox6.Clear(); }
private void button2_Click(object sender, EventArgs e) {
Close(); }
} }
15
Practica 10: Promedio de calificaciones (random).
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
int c1, c2, c3, c4, c5, c6, prom; Random cal = new Random();
c1 = cal.Next(0, 100); c2 = cal.Next(0, 100); c3 = cal.Next(0, 100); c4 = cal.Next(0, 100); c5 = cal.Next(0, 100); c6 = cal.Next(0, 100); prom = (c1 + c2 + c3 + c4 + c5 + c6) / 6; textBox1.Text = c1.ToString(); textBox2.Text = c2.ToString(); textBox3.Text = c3.ToString(); textBox4.Text = c4.ToString(); textBox5.Text = c5.ToString(); textBox6.Text = c6.ToString();
MessageBox.Show("Tu promedio es : " + prom); }
private void button2_Click(object sender, EventArgs e) {
Close(); }
16
Practica 11: Bebida (if)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void textBox1_TextChanged(object sender, EventArgs e) {
}
private void button1_Click(object sender, EventArgs e) {
if (textBox1.Text == "Coca-Cola") {
MessageBox.Show("Eres tripiante"); }
}
private void button2_Click(object sender, EventArgs e) {
Close(); }
} }
17
Practica 12: Promedio (If)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button2_Click(object sender, EventArgs e) { int c1, c2, c3, c4, c5, c6, prom; c1 = Convert.ToInt16(textBox1.Text); c2 = Convert.ToInt16(textBox2.Text); c3 = Convert.ToInt16(textBox3.Text); c4 = Convert.ToInt16(textBox4.Text); c5 = Convert.ToInt16(textBox5.Text); c6 = Convert.ToInt16(textBox6.Text); prom = (c1 + c2 + c3 + c4 + c5 + c6) / 6; if (prom >= 70)
MessageBox.Show("Tu calificación es APROVATORIA con un promedio de : " + prom);
}
private void button3_Click(object sender, EventArgs e) {
Close(); }
18
private void button1_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); textBox6.Clear(); } } }
19
Practica 13: Numero mayor (If)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { double a, b; a = Convert.ToDouble(textBox1.Text); b = Convert.ToDouble(textBox2.Text); if (a >= b) {
MessageBox.Show(a + " es mayor que" + " " + b); }
textBox1.Clear(); textBox2.Clear(); }
private void button2_Click(object sender, EventArgs e) {
}
private void button3_Click(object sender, EventArgs e) {
Close(); }
} }
20
Practica 14: Numero menor
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { { double a, b; a = Convert.ToDouble(textBox1.Text); b = Convert.ToDouble(textBox2.Text); if (a <= b) {
MessageBox.Show(a + " es menor que" + " " + b); }
textBox1.Clear(); textBox2.Clear(); }
}
private void button3_Click(object sender, EventArgs e) {
Close(); }
} }
21
Practica 15: Edad es menor (If)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button3_Click(object sender, EventArgs e) {
Close(); }
private void button2_Click(object sender, EventArgs e) {
textBox1.Clear(); }
private void button1_Click(object sender, EventArgs e) {
int a;
a = Convert.ToInt16(textBox1.Text); if (a <= 18)
MessageBox.Show("Eres menor de edad por " + (18 - a)+ " años"); }
} }
22
Practica 16: Edad (100 años)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
int a;
a = Convert.ToInt16(textBox1.Text); if (a >= 100)
MessageBox.Show("Ya estas viejo compa"); }
private void button2_Click(object sender, EventArgs e) {
Close(); }
} }
23
24
Forma 1 (código)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form1 : Form
{
25
{
InitializeComponent(); }
private void mensajeToolStripMenuItem_Click(object sender, EventArgs e) {
}
private void salirToolStripMenuItem_Click(object sender, EventArgs e) {
Close(); }
private void mensajeToolStripMenuItem1_Click(object sender, EventArgs e) {
Form mensaje = new Form3(); mensaje.Show();
}
private void sumaToolStripMenuItem1_Click(object sender, EventArgs e) {
Form op = new Form2(); op.Show();
this.Hide(); }
private void restaToolStripMenuItem_Click(object sender, EventArgs e) { label1.Visible = true; label2.Visible = true; button1.Visible = true; button2.Visible = true; button3.Visible = true; button4.Visible = true; textBox1.Visible = true; textBox2.Visible = true; }
private void button1_Click(object sender, EventArgs e) {
double a, b, res;
a = Convert.ToDouble(textBox1.Text); b = Convert.ToDouble(textBox2.Text); res = a - b;
MessageBox.Show("Tu resultado es : " + res); }
private void button2_Click(object sender, EventArgs e) {
textBox1.Clear(); textBox2.Clear(); }
private void button4_Click(object sender, EventArgs e) {
26
label1.Visible = false; label2.Visible = false; button1.Visible = false; button2.Visible = false; button3.Visible = false; button4.Visible = false; textBox1.Visible = false; textBox2.Visible = false; }private void button3_Click(object sender, EventArgs e) { Close(); } } }
Forma 2 (código)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form2 : Form
{
public Form2() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
double a, b, res;
a = Convert.ToDouble(textBox1.Text); b = Convert.ToDouble(textBox2.Text); res = a + b;
MessageBox.Show("Tu resultado es : " + res); }
private void button5_Click(object sender, EventArgs e) {
}
private void button3_Click(object sender, EventArgs e) {
textBox1.Clear(); textBox2.Clear(); }
27
{
Form menu = new Form1(); menu.Show();
this.Hide(); }
private void button4_Click(object sender, EventArgs e) { Close(); } } }
Forma 3 (código)
/* Alvarez Lapizco Miguel Angel
* Ingenieria en Sistemas Computacionales * Fundamentos de Programación
* Matrícula 13211477 * */
namespace WindowsFormsApplication1 {
public partial class Form3 : Form
{
public Form3() {
InitializeComponent(); }
private void button2_Click(object sender, EventArgs e) {
this.Hide(); }
private void button1_Click(object sender, EventArgs e) {
MessageBox.Show("Hola salón 502!"); }
private void button3_Click(object sender, EventArgs e) {
Close(); }
} }