Sabtu, 05 Maret 2011

TUGAS PEMROGRAMAN C#

TUGAS 8
1.HELLO WORLD_0320100027
using System;

namespace Hello_World_0320100027
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                Console.WriteLine("Hellooooo!!!!");
                                                Console.ReadLine();
                                }
                }
}





2.VARIABEL ,KONSTANTA,TIPE DATA_0320100027
using System;

namespace Variabel_0320100027
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                int a;
                                                a=90;
                                                Console.Write("Hasilnya adalah {0}",a);
                                                Console.ReadLine();
                                }
                }
}




3. OPERASI ARITMATIKA_0320100027
using System;

namespace Soal_No_3
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                             int pilih,a,b,c;
                                             Console.WriteLine("      #  Operasi Aritmatika  #");
                                             Console.WriteLine("\n\nPilihan :\n 1. + \n 2. - \n 3. * \n 4. / \n");
                                             Console.Write("Masukkan Pilihan Nomor : ");
                                             pilih=Convert.ToInt32(Console.ReadLine());
                                             switch(pilih)
                                             {
                                                          case 1 : Console.Write("Masukkan Angka Pertama : ");
                                                                        a=Convert.ToInt32(Console.ReadLine());
                                                                        Console.Write("Masukkan Angka Kedua   : ");
                                                                        b=Convert.ToInt32(Console.ReadLine());
                                                                        c = a+b;
                                                                        Console.WriteLine("Hasilnya adalah          : {0}",c);
                                                                        break;
                                                         case 2 : Console.Write("Masukkan Angka Pertama : ");
                                                                       a=Convert.ToInt32(Console.ReadLine());
                                                                       Console.Write("Masukkan Angka Kedua : ");
                                                                       b=Convert.ToInt32(Console.ReadLine());
                                                                       c = a-b;
                                                                       Console.WriteLine("Hasilnya adalah : {0}",c);
                                                                       break;
                                                         case 3 : Console.Write("Masukkan Angka Pertama : ");
                                                                       a=Convert.ToInt32(Console.ReadLine());
                                                                       Console.Write("Masukkan Angka Kedua : ");
                                                                       b=Convert.ToInt32(Console.ReadLine());
                                                                       c=a*b;
                                                                       Console.WriteLine("Hasilnya adalah : {0}",c);
                                                                        break;
                                                         case 4 : Console.Write("Masukkan Angka Pertama : ");
                                                                       a=Convert.ToInt32(Console.ReadLine());
                                                                       Console.Write("Masukkan Angka Kedua : ");
                                                                       b=Convert.ToInt32(Console.ReadLine());
                                                                       c = a/b;
                                                                       Console.WriteLine("Hasilnya adalah : {0}",c);
                                                                       break;
                                                }                                             
                                                Console.ReadLine();
                                }
                }
}


4.IF_0320100027
using System;

namespace Soal_4__IF_
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                int a;
                                                Console.WriteLine("     #  Penentuan Grade Nilai  #");
                                                Console.WriteLine("\n\nMasukkan Nilai Anda : ");
                                                a=Convert.ToInt32(Console.ReadLine());
                               
                                                if(a<=100 && a>=85)
                                                {
                                                                Console.WriteLine("Grade anda A");
                                                }
                                                if(a<=84 && a>=70)
                                                {
                                                                Console.WriteLine("Grade anda B");
                                                }
                                                if(a<=69 && a>=50)
                                                {
                                                                Console.WriteLine("Grade anda C");
                                                }
                                                if(a<=49 && a>=25)
                                                {
                                                                Console.WriteLine("Grade anda D");
                                                }
                                                if(a<=24 && a>=0)
                                                {
                                                                Console.WriteLine("Grade anda E");
                                                }
                                                Console.ReadLine();
                                }
                }
}

5. LOOP
using System;

namespace Tugas_5_LOOP_
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                int a,b,c;
                                                string jawab;
                                                do
                                                {
                                                       Console.WriteLine("# Penghitungan pangkat #");
                                                       Console.Write("\n\nMasukkan Angka : ");
                                                       a=Convert.ToInt32(Console.ReadLine());
                                                       b=a*a;
                                                       Console.WriteLine("\nHasil dari pangkatnya adalah {0} ",b);
                                                       Console.Write("\nApakah anda ingin menghitung lagi ? (Y/T)");
                                                        jawab=Convert.ToString(Console.ReadLine());
                                                }
                                                while(jawab=="Y");
                                                {
                                                        Console.WriteLine("Keluar");
                                                 }
                                   }

                     
               }
                                               
}



6. ARRAY_0320100027

using System;

namespace Aray_0320100027
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                int a,b,c;
                                                int[] nilai = new int[8];
                                               
                                                Console.Write("Masukkan Bilangan :");
                                                a=Convert.ToInt32(Console.ReadLine());
                                                for(b=1;b<=a;b++)
                                                {
                                                                Console.Write("Bilangan ke_ {0} : ",b);
                                                                nilai[b]=Convert.ToInt32(Console.ReadLine());
                                                }
                                                Console.WriteLine("\nJadi Hasilny adalah :/n");
                                                for(b=1;b<=a;b++)
                                                {
                                                               
                                                                Console.WriteLine("Bilangan ke_ {0} : {1} ",b,nilai[b]);
                                                               
                                                }Console.ReadLine();
                                               

                                }
                }
}
7. MEMBACA DAN MENULIS KE LAYAR_0320100027

using System;

namespace Soal_7_Membaca_dan_Menulis_Ke_layar_
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                string tulis;
                                                Console.WriteLine("Membaca dan Menulis");
                                                Console.Write("Masukkan Nama : ");
                                                tulis=Convert.ToString(Console.ReadLine());
                                                Console.Write("Nama Prodi : ");
                                                string prodi=Convert.ToString(Console.ReadLine());
                                                Console.Write("NIM      : ");
                                                string nim=Convert.ToString(Console.ReadLine());
                                                Console.WriteLine("\nNAMA        : {0}",tulis);
                                                Console.WriteLine("\nPRODI      : {0}",prodi);
                                                Console.WriteLine("\nNIM        : {0}",nim);
                                                Console.ReadLine();
                                }
                }
}

8. EXCEPTION HANDLING_0320100027

using System;

namespace Exception_Handling
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                int a,nilai,c;
                                                string nama;
                                                try
                                                {
                                                                Console.WriteLine("Program Nilai");
                                                                Console.Write("Nama                   : ");
                                                                nama=Convert.ToString(Console.ReadLine());
                                                                Console.Write("Prodi                     : ");
                                                                string prodi=Convert.ToString(Console.ReadLine());
                                                                Console.Write("Nilai                       : ");
                                                                nilai=Convert.ToInt32(Console.ReadLine());
                                                }
                                                catch
                                                {
                                                    Console.WriteLine("Maaf data yang anda masukkan salah !!Tolong isikan data yang sesuai !");
                                                }
                                                Console.ReadLine();
                                }
                }
}

TUGAS BAGIAN 1 &11

BAG I

1.SELISIH WAKTU_0320100027

using System;


namespace selisih_waktu_0320100027
{
                class Class1
                {

                                public struct w
                                {
                                                public int hh;
                                                public int mm;
                                                public int ss;
                                }
               
                                static void Main(string[] args)
                                {
                                                w hh1;
                                                w hh2;
                                                w hh3;
                                                Console.Write("Jam awal percakapan : ");
                                                hh1.hh = Convert.ToInt32(Console.ReadLine());
                                                hh1.mm = Convert.ToInt32(Console.ReadLine());
                                                hh1.ss = Convert.ToInt32(Console.ReadLine());
                                                Console.Write("Jam selesai percakapan : ");
                                                hh2.hh = Convert.ToInt32(Console.ReadLine());
                                                hh2.mm = Convert.ToInt32(Console.ReadLine());
                                                hh2.ss = Convert.ToInt32(Console.ReadLine());
                                                hh3.hh = Convert.ToInt32(Console.ReadLine());
                                                hh3.mm = 0;
                                                hh3.ss = 0;
                                                if(hh2.ss >= hh1.ss)
                                                {
                                                                hh3.ss=hh2.ss-hh1.ss;
                                                }
                                                if(hh2.ss<=hh1.ss)
                                                {
                                                                hh3.ss=(hh2.ss+60)-hh1.ss;
                                                                hh2.mm=hh2.mm-1;
                                                }
                                                if(hh2.mm>=hh1.mm)
                                                {
                                                                hh3.mm=hh2.mm-hh1.mm;
                                                }
                                                if(hh2.mm<=hh1.mm)
                                                {
                                                                hh3.mm=(hh2.mm+60)-hh1.mm;
                                                                hh2.hh=hh2.hh-1;
                                                }
                                                hh3.hh=hh2.hh-hh1.hh;
                                                Console.WriteLine("\nSelisih waktu ={0}:{1}:{2}",hh3.hh,hh3.mm,hh3.ss);
                                                Console.ReadLine();
                                }
                }
}

2.FAKTORIAL_0320100027
using System;

namespace Faktorial_0320100027
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                int fak,n,k;
                                                Console.Write("Masukkan Bilangan : ");
                                                n=Convert.ToInt32(Console.ReadLine());
                                                fak=1;
                                                                                for(k=1;k<=n;k++)
                                                                                {
                                                                                                fak=fak*k;
                                                                                }
                               
                                                Console.WriteLine("Hasilnya :{0}",fak);
                                                Console.ReadLine();
                                }
                }
}    
  

BAG II       

3. PERBANDINGAN ANGKA_0320100027

using System;

namespace Perbandingan_Angka_0320100027
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                int a,b,c;
                                                Console.Write("A = ? ");
                                                a=Convert.ToInt32(Console.ReadLine());
                                                Console.Write("B = ? ");
                                                b=Convert.ToInt32(Console.ReadLine());
                                                Console.Write("C = ? ");
                                                c=Convert.ToInt32(Console.ReadLine());
                                               

                                                if (a<b)
                                                {
                                                                if(b<c)
                                                                {
                                                                    Console.WriteLine("Bilangan Terbesar adalah {0}",c);
                                                                }
                                                                else
                                                                {
                                                                                if(c>a)
                                                                                {
                                                                                     Console.WriteLine("Bilangan Terbesar adalah {0}",b);
                                                                                }
                                                                                else
                                                                                {
                                                                                     Console.WriteLine("Bilangan Terbesar adalah {0}",b);
                                                                                }
                                                                }
                                                }
                                                else
                                                {
                                                                if(b>c)
                                                                {
                                                                    Console.WriteLine("Bilangan Terbesar adalah {0}",a);
                                                                }
                                                                else
                                                                {
                                                                                if(c>a)
                                                                                {
                                                                                    Console.WriteLine("Bilangan Terbesar adalah {0}",c);
                                                                                }
                                                                                else
                                                                                {
                                                                                     Console.WriteLine("Bilangan Terbesar adalah {0}",a);
                                                                                }
                                                                }
                                                }
                                                Console.ReadLine();
                                }
                }
}

4.KALKULATOR_0320100027

using System;

namespace Soal_No_3
{
                /// <summary>
                /// Summary description for Class1.
                /// </summary>
                class Class1
                {
                                /// <summary>
                                /// The main entry point for the application.
                                /// </summary>
                                [STAThread]
                                static void Main(string[] args)
                                {
                                                decimal a,b,c;
                                                string pilih;
                                                Console.Write("A=? ");
                                                a=Convert.ToInt32(Console.ReadLine());
                                                Console.Write("B=? ");
                                                b=Convert.ToInt32(Console.ReadLine());
                                                Console.Write("Masukkan Pilihan(+, -, *, /) : ");
                                                pilih=Convert.ToString(Console.ReadLine());
                                                switch(pilih)
                                                {
                                                       case "+" :c = a+b;
                                                                       Console.WriteLine("Hasilnya adalah          : {0}",c);
                                                                       break;
                                                       case "-" : c = a-b;
                                                                        Console.WriteLine("Hasilnya adalah : {0}",c);
                                                                        break;
                                                       case "*" : c=a*b;
                                                                        Console.WriteLine("Hasilnya adalah : {0}",c);
                                                                        break;
                                                       case "/" : c = a/b;
                                                                        Console.WriteLine("Hasilnya adalah : {0}",c);
                                                                        break;
                                                }
                                               
                                                Console.ReadLine();


                                }
                }
}



0 komentar:

Posting Komentar