Pages

Kamis, 21 Maret 2013

Tugas OOPS



Exercise 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Geometrical_Shapes
{
    double No_of_coordinates;
    double 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 classy
{
    static void Main(string[] args)
    {
    Geometrical_Shapes Small_rectangle= new Geometrical_Shapes();
    Small_rectangle.Create();
    Small_rectangle.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("\nThe details entered are as follows:");
               Console.Write("First name: ");
            Console.WriteLine(Fname);
               Console.Write("Last name: ");
            Console.WriteLine(Lname);
               Console.Write("Number of players:");
            Console.WriteLine(NoOfPlayers);
               Console.Write("Level:");
            Console.WriteLine(Level);
        }
}
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);
}
}

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 nymber of wheels in 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.WriteLine("\n");
        Console.WriteLine(Car.Number_of_tyres);
        Console.WriteLine(" :is the number of wheels in a Car\n");
        Console.WriteLine(Motorcycle.Number_of_tyres);
        Console.WriteLine(" :is the number of wheels in a Motorcycle \n");
    }
}

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;
        New_score=Top_score;
        Top_score=New_score;
    }
    void Display()
    {
        Console.WriteLine("The new value of top score is:");
        Console.WriteLine(Top_score);
        Console.WriteLine("The old value of top score was:");
        Console.WriteLine(New_score);
    }
    static void Main()
    {
        Interchange I1=new Interchange ();
        I1.Swap();
        I1.Display();
    }
}

EXERCISE 6
using System;
class Library
{
    int ISBNNumber;
    string BookCategory;
    string Author;
    int NumberOfCopyAvailable;
    public void Borrowing_Book_Details()
    {
        Console.WriteLine("The 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 of 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 Olga
{
    public static void Main(string[] args)
    {
        Library L1 = new Library();
        L1.Get_Author_Details();
        L1.Borrowing_Book_Details();
        Console.ReadLine();
    }
}




Kamis, 14 Maret 2013

Introduction to the Object-Oriented Approach

Classes in C# 

Contoh code class:
public class Hello
        public static void Main(string[] args)
       {
       System.Console.WriteLine(“Hello, World! \n”); 
       } 
Public class Hello merupakan identitas dari sebuah class.
Public static void Main (string[]args) merupakan fungsi untuk menggambarkan sebuah objek.
System.Console.WriteLine ("Hello,World! \n"); merupakan code Console class dari System namespace yang menampilkan ("Hello, World! \n");.
Dalam class method Main{} akan menampilkan message “Hello, World!” pada layar

The Main() Function 

Function main() dibutuhkan agar program C dapat dieksekusi.Tanpa function main, program C dapat dicompile tapi tidak dapat dieksekusi (harus dengan flag parameter -c, jika di UNIX) . Pada saat program C dijalankan, maka compiler C pertama kali akan mencari function main() dan melaksanakan instruksi-instruksi yang ada di sana.

The class Keyword

The class keyword digunakan untuk mendeklarasikan class.Class keyword juga mendefinisikan class Hello.Class keyword juga terdiri dari class keyword C#,C# adalah bahasa pemrograman yang menggunakan jumlah kata-kata yang tidak terlalu banyak. C# hanya berisi kata-kata yang biasa disebut dengan keywords. Keywords ini digunakan untuk menjelaskan berbagai macam informasi.

The Class Name 

Class keyword membutuhkan class name agar bisa mengetahui classes nya. Aplikasi C# mempunyai beberapa fungsi yang diletakkan pada sebuah Class.Nama suatu fungsi pada C# harus diawali dengan huruf, atau garis bawah “_” yang kemudian bisa diikuti oleh huruf, angka atau garis bawah.Pada bagian akhir nama fungsi digunakan tanda kurung buka dan kurung tutup “()”.Penamaan fungsi tidak boleh mengandung spasi. Awal dan akhir suatu fungsi di mulai dengan tanda “{“ dan diakhiri dengan tanda “}”.Penulisan komentar ( tulisan yang tidak di eksekusi) dapat dibuat sebagai berikut. Komentar satu baris dengan menggunakan tanda “//” .Komenter yang lebih dari satu baris dengan di awali tanda “/*” dan diakhiri oleh “*/”.

System.Console.WriteLine()  

Console adalah class yang termasuk systen namespace.System namespace pada metode WriteLine() yang menampilkan teks di layar tertutup. Karakter (.) digunakan sebagai akses function WriteLine.

The Escape Characters

Escape Sequences adalah karakter-karakter khusus yang tidak akan itampilkan.Contohnya, ada karakter yang digunakan sebagai tanda akhir dari suatu baris yang memerintahkan program untuk melanjutkan ke baris berikutnya. Cara penulisannya diawali dengan tanda \ diikuti dengan karakter khusus (dalam contoh ini adalah “n”) sehingga penulisannya menjadi \n. Contoh new line escape sequence:
    Console.WriteLine ("Hello \n World");

 

PRACTICE QUESTIONS

 1. Which of the following is not a class? A Ford Ikon car with the registration number XXXX
 2. Which method displays the message “Hello People” on the screen? Console.WriteLine(“Hello People”); 
3. Console is a Class 
4. In a C# program, which is the first function to be executed? Main 
5. Which of the following is used to denote a newline character? \n
 

(c)2009 OOPS C#. Based in Wordpress by wpthemesfree Created by Templates for Blogger