Kamis, 21 Maret 2013

Exercise 1

using System;
class Geometrical_Shape
{
    double No_of_coordinates, Area;
    string Color;
    public void create()
    {
        Console.WriteLine(" Enter Number of Coordinates:  ");
        No_of_coordinates = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine(" Enter the Area     :");
        Area = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine(" Enter the Color    :");
        Color = (Console.ReadLine());
    }
    public void display()
    {
        Console.WriteLine("THIS IS WHAT YOU ENTERED: \n");
        Console.Write("Number OF Coordinates :");
        Console.WriteLine(No_of_coordinates);
        Console.Write("Area:");
        Console.WriteLine(Area);
        Console.Write("Color :");
        Console.WriteLine(Color);

    }
    class Program
    {
        static void Main(string[] args)
        {
            Geometrical_Shape geo = new Geometrical_Shape();
            geo.create();
            geo.display();
            Console.ReadLine();
        }

    }
}


exercise 2

using System;
class GameDetails
    {
        string Fname;
        string Lname;
        int NoofPlayers;
        int Level;

        public void Accept_game_details()
        {
            Console.WriteLine("Enter your first name:");
            Fname = Console.ReadLine();
            Console.WriteLine("Enter your Last name:");
            Lname = Console.ReadLine();
            Console.WriteLine("Enter number of players:");
            NoofPlayers= Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter complexity level number:");
            Level= Convert.ToInt32(Console.ReadLine());
        }
        public void Display_game_details()
        {
            Console.WriteLine("\n the details entered are as follows:");
            Console.Write("First name:");
            Console.WriteLine(Fname);
            Console.WriteLine("Last name");
            Console.WriteLine(Fname);
            Console.Write("Number of Players");
            Console.WriteLine(NoofPlayers);
            Console.Write("Level:");
            Console.WriteLine(Level);
            Console.ReadLine();
        }
    }
    class My
    {
        static void Main(string[] args)
        {
            GameDetails Bingo = new GameDetails();
            Bingo.Accept_game_details();
            Bingo.Display_game_details();
        }
    }
}


Exercise 3

using System;
class Myclass
{
       static void Main()
       {
              string Answer="Y";
              string Response_code="66";
              int Counter=60;
              Console.WriteLine(Answer);
              Console.WriteLine(Response_code);
              Console.WriteLine(Counter);
              Console.ReadLine();
       }
}


Exercise 4

using System;
class Vehicle
{
       public int Number_of_tyres;
}

class MyVehicle
{
       static void Main(string[] args)
       {
       Vehicle Motorcycle= new Vehicle();
       Vehicle Car = new Vehicle();
       Console.WriteLine("Enter the Number of Wheels on a car:");
       Car.Number_of_tyres=Convert.ToInt32(Console.ReadLine());
       Console.WriteLine("Enter The Number of Wheels in a MotorCycle:");
       Motorcycle.Number_of_tyres=Convert.ToInt32(Console.ReadLine());
       Console.Write("\nThe number of wheels in a car is ");
       Console.WriteLine(Car.Number_of_tyres);
       Console.Write("The Number of Wheels of a Motorcycle is ");
       Console.WriteLine(Motorcycle.Number_of_tyres);
       Console.ReadLine();
       }
}


Exercise 5

using System;
class Interchange
{
    int Top_score;
    int New_score;
    int Temp;
    void Swap()
    {
        Top_score=5;
        New_score=10;
        Temp=Top_score;
        Top_score = New_score;
        New_score = Temp;
    }

      
    void Display()
    {
        Console.WriteLine("The new value of top score is:{0}",New_score);
        Console.WriteLine("The old value of top score was:" + Top_score);
        Console.ReadLine();
    }
    static void Main()
    {
        Interchange I1=new Interchange();
        I1.Swap();
        I1.Display();
        Console.ReadLine();
    }
}


Exercise 6

using System;
class Library
{
    int ISBNNumber;
    string BookCategory;
    string Author;
    int NumberOfCopyAvailable;
    public void Borrowing_Book_Details()
    {
        Console.WriteLine("\nThe Details of the Author Book:");
        Console.WriteLine("ISBN Number:");
        Console.WriteLine(ISBNNumber);
        Console.WriteLine("Book Category:");
        Console.WriteLine(BookCategory);
        Console.WriteLine("Author Name:");
        Console.WriteLine(Author);
        Console.WriteLine("Number of copies available:");
        Console.WriteLine(NumberOfCopyAvailable);
    }
    public void Get_Author_Details()
    {
        Console.WriteLine("Please, Enter the details of the Author");
        Console.WriteLine("\n Enter ISBN Number:");
        ISBNNumber = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Category of Books to be borrow (Fiction or Nonfiction):");
        BookCategory = Console.ReadLine();
        Console.WriteLine("Enter Author Book Name:");
        Author = Console.ReadLine();
        Console.WriteLine("Number Of Copy Available:");
        NumberOfCopyAvailable = Convert.ToInt32(Console.ReadLine());
    }
}
class OKi
{
    public static void Main(string[] args)
    {
        Library L1 = new Library();
        L1.Get_Author_Details();
        L1.Borrowing_Book_Details();
        Console.ReadLine();
    }
}











tugas coding OOPS

Posted by Unknown
Kamis, 14 Maret 2013
Object Oriented Programming Using C# adalah bahasa pemrograman baru yang diciptakan Microsoft yang digunakan oleh banyak developer .NET untuk mengembangkan applikas dengan platform .NET. Kelebihan dalam penggunaan bahasa pemrogaman C#.net antara lain :

1.    Object Oriented Language 

C# memenuhi syarat-syarat sebagai sebuah bahasa pemrograman yang bersifat Object Oriented, yaitu encapsulation, inheritance dan polymorphism.

2.    Powerfull dan Fleksibel 

C# bisa digunakan untuk membuat berbagai macam aplikasi, seperti aplikasi pengolah kata, grapik, spreadsheets, atau bahkan membuat kompiler untuk sebuah bahasa permrograman.

3.     Efisien 

C# tidak memiliki terlalu banyak keyword, sehingga dapat mengurangi kerumitan.

4.     Modular 

Kode C# ditulis dengan pembagian masing Class-Class (classes) yang terdiri dari beberapa routines yang disebut sebagai member methods. Class-Class dan metode-metode ini dapat digunakan kembali oleh program atau aplikasi lain. Hanya dengan memberikan informasi yang dibutuhkan oleh Class dan metode yang dimaksud, maka kita akan dapat membuat suata kode yang dapat digunakan oleh satu atau beberapa aplikasi dan program (reusable code)

Contoh codding dalam bahasa pemrograman C#

   
Public class Program
    {
        Public static void Main(string[] args)
        {
            System.Console.WriteLine("Hello, World ! \n");
            System.Console.ReadKey();
        }
    }

Nantinya setelah program tersebut dicompile, akan keluar output “Hello, World ! .


Penjelasan Dari Program diatas adalah sebagai berikut.


Public Class Program

{
.
.
}

Potongan Code diatas merupakan sebuah keyword untuk mendeklarasikan Sebuah class. Class pengelompokkan tertentu terhadap sebuah benda berdasarkan kesamaan, contoh, Mobil itu ada banyak mereknya, bisa saya tuliskan seperti ini, MOBIL terdiri dari beberapa merek yaitu TOYOTA, HONDA, SUZUKI, BMW, dll. Nah, kata-kata “MOBIL”, itu lah classnya, sedangkan merknya, yaitu TOYOTA, HONDA, SUZUKI, BMW itu merupakan objek.


    Jadi keyword class mendefinisikan class Program, kurung kurawa atau { dan } merupakan limiter atau bisa dikatakan untuk mengindikasikan start dan end-nya statement class.


Public static void Main(string[] args)

   
Selanjutnya, Fungsi Main() adalah code pertama yg dijalankan oleh compiler C#, fungsi main() inilah yg digunakan untuk membuat object dan meminta fungsi member ( input ).

System.Console.WriteLine("Hello, World ! \n");


Console is a class that belongs to the system namespace. A namespace i a collection classes. The system namespace contains th method WriteLine(), which diplays the enclosed text on the screen. The preceding line can also be written a Console.Writeln() if the statement using System is included a the first line of code.


The escape character


Berikut dalah code untuk menampilkan special character seperti, baris baru ( newline ), backspace character. List escape character yg digunakan di C#.

\’    Single Quotation Mark
\>>    Double Quotation Mark
\\    backlash
\0    Null
\a     Alert
\b     Backspace
\f    Form Feed
\n    New Line
\r    Carriage return
\t    Horizontal Tab
\v    vertical Tab

Practice Question


1.    Which of the following i not a classes ?

 Answer A : A ford Ikon car with the registration number XXXX

2.    Which method diplays the message “Hello People” on the sceen ?

Answer A : Console.WriteLine (“Hello People”);

3.    Console is a...

Answer B : Class

4.    In a C# program, which is the first function to be executed ?

Answer A : Main()

5.    Which of the following is used to denote a newline character ?

Answer B : \n

OOPS Chapter 1 Tugas

Posted by Unknown

Blogger templates

Blogroll

Labels

Diberdayakan oleh Blogger.

Pengikut

Labels

Labels

Blogger templates

Copyright © Kie Blog'ke Si Sigid -Black Rock Shooter- Powered by Blogger - Designed by Johanes Djogan