Friday, October 11, 2013

PEMROGRAMAN BERORIENTASI OBJEK_ C#



//Program menghitung hambatan
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 MenghitungHambatan
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            float r1 = Convert.ToSingle(txtR1.Text);
            float r2 = Convert.ToSingle(txtR2.Text);
            float r3 = Convert.ToSingle(txtR3.Text);
            float r4 = Convert.ToSingle(txtR4.Text);

            if (optSeri.Checked) {
            txtHasil.Text= Convert.ToString(seri(r1,r2,r3,r4));
            }
            if (optParalel.Checked) {
                txtHasil.Text = Convert.ToString(paralel(r1,r2,r3,r4));
            }
        }
        //bebas membuat fungsi
        float seri(float r1, float r2, float r3, float r4) {
            return r1 + r2 + r3 + r4;
        }
        float paralel(float r1, float r2, float r3, float r4) {
            return (1 / r1) + (1 / r2) + (1 / r3) + (1 / r4);
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}


No comments:

Post a Comment