Menghitung IPK dengan Array C# Posted by Unknown on January 14, 2015 Get link Facebook X Pinterest Email Other Apps Dengan keterangan program : - Input berupa : Kode Mata Kuliah, Nama Mata Kuliah, Besar SKS, dan Nilai Huruf. - Jumlah mata kuliah yang diinput tidak dibatasi, tergantung keinginan user. - Manfaatkan Array untuk menyimpan mata kuliah. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MODUL5_4 { class Program { static void Main(string[] args) { string pilihan; string[] kode = new string[0]; string[] nama = new string[0]; int[] sks = new int[0]; string[] huruf = new string[0]; float[] mutu = new float[0]; do { Array.Resize(ref kode, kode.Length + 1); Array.Resize(ref nama, nama.Length + 1); Array.Resize(ref sks, sks.Length + 1); Array.Resize(ref huruf, huruf.Length + 1); Array.Resize(ref mutu, mutu.Length + 1); Console.Write("Kode Mata Kuliah\t\t = "); kode[kode.GetUpperBound(0)] = Console.ReadLine(); Console.Write("Nama Mata Kuliah\t\t = "); nama[nama.GetUpperBound(0)] = Console.ReadLine(); Console.Write("Besar SKS\t\t\t = "); sks[sks.GetUpperBound(0)] = Convert.ToInt32(Console.ReadLine()); Console.Write("Nilai Huruf(A,B+,B,C+,C,D,E)\t = "); huruf[huruf.GetUpperBound(0)] = Console.ReadLine(); if (huruf[huruf.GetUpperBound(0)] == "A" || huruf[huruf.GetUpperBound(0)] == "a") { mutu[mutu.GetUpperBound(0)] = (float)sks[sks.GetUpperBound(0)] * 4f; } else if (huruf[huruf.GetUpperBound(0)] == "B+" || huruf[huruf.GetUpperBound(0)] == "b+") { mutu[mutu.GetUpperBound(0)] = (float)sks[sks.GetUpperBound(0)] * 3.5f; } else if (huruf[huruf.GetUpperBound(0)] == "B" || huruf[huruf.GetUpperBound(0)] == "b") { mutu[mutu.GetUpperBound(0)] = (float)sks[sks.GetUpperBound(0)] * 3f; } else if (huruf[huruf.GetUpperBound(0)] == "C+" || huruf[huruf.GetUpperBound(0)] == "c+") { mutu[mutu.GetUpperBound(0)] = (float)sks[sks.GetUpperBound(0)] * 2.5f; } else if (huruf[huruf.GetUpperBound(0)] == "C" || huruf[huruf.GetUpperBound(0)] == "c") { mutu[mutu.GetUpperBound(0)] = (float)sks[sks.GetUpperBound(0)] * 2f; } else if (huruf[huruf.GetUpperBound(0)] == "D" || huruf[huruf.GetUpperBound(0)] == "d") { mutu[mutu.GetUpperBound(0)] = (float)sks[sks.GetUpperBound(0)] * 1f; } else if (huruf[huruf.GetUpperBound(0)] == "E" || huruf[huruf.GetUpperBound(0)] == "e") { mutu[mutu.GetUpperBound(0)] = (float)sks[sks.GetUpperBound(0)] * 0f; } Console.Write("Mau input data lagi? (Y/T)\t = "); pilihan = Console.ReadLine(); Console.WriteLine(); } while (pilihan == "Y" || pilihan == "y"); Console.WriteLine("Kode MK\t Nama MK\t\t SKS\t NH\t Mutu"); Console.WriteLine("======================================================="); for (int i = 0; i < kode.Length; i++) { Console.WriteLine("{0,-10} {1,-21} {2,-7} {3,-8} {4,-10}", kode[i], nama[i], sks[i], huruf[i], mutu[i]); } Console.WriteLine("======================================================="); int tmp_sks = 0; float tmp_mutu = 0; for (int i = 0; i < sks.Length; i++) { tmp_sks += sks[i]; tmp_mutu += mutu[i]; } Console.WriteLine("IPK = {0}", (float)tmp_mutu / tmp_sks); Console.ReadKey(); } } } Comments
Comments
Post a Comment