Class dan Method pada OOP

destiya wulantari
0 view / 1596 show
3 years ago
Education

Tugas 3

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Destiya Wulantari { class Sistem { double num1, num2, num3; public void read() { Console.WriteLine("\n Inputkan dua bilangan:"); Console.Write("\n Bilangan pertama : "); num1 = double.Parse(Console.ReadLine()); Console.Write("\n Bilangan kedua : "); num2 = double.Parse(Console.ReadLine()); } public void read2() { Console.WriteLine("\n ini hanya percobaan:"); Console.Write("\n Masukan nilai : "); num3 = double.Parse(Console.ReadLine()); } public void add() { double sum = num1 + num2; Console.WriteLine("\n Hasil : ({0}) + ({1}) = {2}", num1, num2, sum); } public void subtract() { double diff = num1 - num2; Console.WriteLine("\n Hasil : ({0}) - ({1}) = {2}", num1, num2, diff); } public void multiply() { double prod = num1 * num2; Console.WriteLine("\n Hasil : ({0}) X ({1}) = {2}", num1, num2, prod); } public void divide() { double qt = num1 / num2; Console.WriteLine("\n Hasil : ({0}) / ({1}) = {2}", num1, num2, qt); } public void pangkat() { double pt = Math.Pow(num1,num2); Console.WriteLine("\n Hasil : ({0}) ^ ({1}) = {2}", num1, num2, pt); } public void modulus() { double mod = num1 % num2; Console.WriteLine("\n Hasil : ({0}) % ({1}) = {2}", num1, num2, mod); } public void sinus() { double sin = Math.Sin(num3); Console.WriteLine("\n Hasil sin dari bilangan ({0}) adalah = {1} ", num3, sin); } public void cosinus() { double sin = Math.Cos(num3); Console.WriteLine("\n Hasil cos dari bilangan ({0}) adalah = {1} ", num3, sin); } public void tangen() { double sin = Math.Tan(num3); Console.WriteLine("\n Hasil tan dari bilangan ({0}) adalah = {1} ", num3, sin); } } class Aritmatika { public static void Main() { Sistemna SC = new Sistemna(); int ch, i = 1; while (i == 1) { Console.Clear(); Console.WriteLine(" ^^^Calculator Sederhana^^^ "); Console.WriteLine("\n 1-----> Pertambahan |"); Console.WriteLine("\n 2-----> Pengurangan |"); Console.WriteLine("\n 3-----> Perkalian |"); Console.WriteLine("\n 4-----> Pembagian |"); Console.WriteLine("\n 5-----> Perpangkatan |"); Console.WriteLine("\n 6-----> Modulus |"); Console.WriteLine("\n 7-----> SIN |"); Console.WriteLine("\n 8-----> COS |"); Console.WriteLine("\n 9-----> TAN |"); Console.WriteLine("\n 10-----> Keluar |"); Console.WriteLine("\n ******************"); Console.Write("\n Pilih Operator: "); ch = int.Parse(Console.ReadLine()); switch (ch) { case 1: SC.read(); SC.add(); break; case 2: SC.read(); SC.subtract(); break; case 3: SC.read(); SC.multiply(); break; case 4: SC.read(); SC.divide(); break; case 5: SC.read(); SC.pangkat(); break; case 6: SC.read(); SC.modulus(); break; case 7: SC.read2(); SC.sinus(); break; case 8: SC.read2(); SC.cosinus(); break; case 9: SC.read2(); SC.tangen(); break; case 10: Environment.Exit(-1); break; default: Console.WriteLine(" Maaf, rupanya anda salah menginputkan."); break; } Console.Write("\n Ketik Ok untuk melanjutkan.. "); Console.ReadLine(); } Console.WriteLine("\n Maaf rupanya terjadi kesalahan dan tidak bisa diteruskan !"); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Destiya Wulantari { class Sistem { double num1, num2, num3; public void read() { Console.WriteLine("\n Inputkan dua bilangan:"); Console.Write("\n Bilangan pertama : "); num1 = double.Parse(Console.ReadLine()); Console.Write("\n Bilangan kedua : "); num2 = double.Parse(Console.ReadLine()); } public void read2() { Console.WriteLine("\n ini hanyalah percobaan:"); Console.Write("\n Masukan nilai : "); num3 = double.Parse(Console.ReadLine()); } public void add() { double sum = num1 + num2; Console.WriteLine("\n Hasil : ({0}) + ({1}) = {2}", num1, num2, sum); } public void subtract() { double diff = num1 - num2; Console.WriteLine("\n Hasil : ({0}) - ({1}) = {2}", num1, num2, diff); } public void multiply() { double prod = num1 * num2; Console.WriteLine("\n Hasil : ({0}) X ({1}) = {2}", num1, num2, prod); } public void divide() { double qt = num1 / num2; Console.WriteLine("\n Hasil : ({0}) / ({1}) = {2}", num1, num2, qt); } public void pangkat() { double pt = Math.Pow(num1,num2); Console.WriteLine("\n Hasil : ({0}) ^ ({1}) = {2}", num1, num2, pt); } public void modulus() { double mod = num1 % num2; Console.WriteLine("\n Hasil : ({0}) % ({1}) = {2}", num1, num2, mod); } public void sinus() { double sin = Math.Sin(num3); Console.WriteLine("\n Hasil sin dari bilangan ({0}) adalah = {1} ", num3, sin); } public void cosinus() { double sin = Math.Cos(num3); Console.WriteLine("\n Hasil cos dari bilangan ({0}) adalah = {1} ", num3, sin); } public void tangen() { double sin = Math.Tan(num3); Console.WriteLine("\n Hasil tan dari bilangan ({0}) adalah = {1} ", num3, sin); } } class Aritmatika { public static void Main() { Sistemna SC = new Sistemna(); int ch, i = 1; while (i == 1) { Console.Clear(); Console.WriteLine(" ***Kalkulator Sederhana*** "); Console.WriteLine("\n 1-----> Pertambahan |"); Console.WriteLine("\n 2-----> Pengurangan |"); Console.WriteLine("\n 3-----> Perkalian |"); Console.WriteLine("\n 4-----> Pembagian |"); Console.WriteLine("\n 5-----> Perpangkatan |"); Console.WriteLine("\n 6-----> Modulus |"); Console.WriteLine("\n 7-----> SIN |"); Console.WriteLine("\n 8-----> COS |"); Console.WriteLine("\n 9-----> TAN |"); Console.WriteLine("\n 10-----> Keluar |"); Console.WriteLine("\n *************************"); Console.Write("\n Pilih Operator: "); ch = int.Parse(Console.ReadLine()); switch (ch) { case 1: SC.read(); SC.add(); break; case 2: SC.read(); SC.subtract(); break; case 3: SC.read(); SC.multiply(); break; case 4: SC.read(); SC.divide(); break; case 5: SC.read(); SC.pangkat(); break; case 6: SC.read(); SC.modulus(); break; case 7: SC.read2(); SC.sinus(); break; case 8: SC.read2(); SC.cosinus(); break; case 9: SC.read2(); SC.tangen(); break; case 10: Environment.Exit(-1); break; default: Console.WriteLine(" Maaf !!! Anda salah menginputkan."); break; } Console.Write("\n Ketik ENTER untuk melanjutkan.. "); Console.ReadLine(); } Console.WriteLine("\n Maaf tidak bisa dilanjutkan.."); } } }

 

Share On :