Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 45 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
45
Dung lượng
1,51 MB
Nội dung
02/21/14
Bài 1:
LÀM QUEN VỚI NGÔN
NGỮ LẬPTRÌNH C#
02/21/14
Nội Dung Trình Bày
Nội dung và yêu cầu môn học
Tài liệu tham khảo
Giới thiệu NNLT C#
Cài đặt C#
Một số ví dụ đơn giản
Viết 1 số bài tập đơn giản
02/21/14
Nội Dung Chính
Làm quen với Ngôn Ngữ C#
Cài đặt C#
Các thành phần của C#
Cấu trúc chọn lựa
Cấu trúc lặp
Mảng – Dãy
(Trong quá trình tìm hiểu và làm bài
tập phát triển tư duy lập trình)
02/21/14
Lưu Ý
Kỹ năng lậptrình không thể có nếu
không làm bài tập thường xuyên
Các buổi học có sự kế thừa nhau,
do vậy nếu không xem và làm bài
tập tốt khó khăn cho các buổi
học còn lại
02/21/14
Các bước tổng quát
Tiếp cận bài toán-vấn đề
Thiết kế giải thuật và cấu trúc dữ
liệu
Viết chương trình (dựa trên 1 NNLT)
Nhập chương trình (với text editor)
Biên dịch/thông dịch, thi hành,gỡ
rối (với chương trình biên dịch,
debug,…)
Sửa chữa, hoàn chỉnh
02/21/14
Ưu điểm của C#
Các ưu điểm này đứng trên quan điểm 1
người sử dụng NNLT như 1 công cụ thể
hiện giải thuật
-Gần gủi với các NNLT thông dụng
(Pascal,C/C++,Java)
-“3 in 1 “ : C++ / C# và Java
-Cải tiến các khuyết điểm của C/C++ :con trỏ,
các hiệu ứng phụ,…
-“Copy” các ưu điểm từ các ngôn ngữ lậptrình
khác : dọn rác, fall-through, kiểu dữ liệu
string-bool,….
- Và 1 số ưu điểm khác
02/21/14
Một số ví
dụ làm
quen với
C#
02/21/14
Cấu trúc 1 chương trình C# đơn giản
using <tên “gói thư viện” >;
class <tên lớp>
{
public static void Main ( )
{
<các khai báo hằng, biến>;
<các lệnh> ;
}
}
02/21/14
Ví dụ 1:
using System;
/*
Ghi chú :
Chương trình in ra dòng chữ Hello,my friends
*/
class Vidu1_1
{
static public void Main()
{
Console.WriteLine("Hello,my friends");
} // chấm dứt khai báo hàm
} // chấm dứt khai báo lớp
02/21/14
Sử dụng Studio .NET
[...]... Vidu1_3 { static public void Main() { Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("What is your name "); String name=Console.ReadLine(); Console.ForegroundColor=ConsoleColor.Green; Console.WriteLine("Hello, "+name); return; }} 02/ 21/ 14 02/ 21/ 14 02/ 21/ 14 02/ 21/ 14 02/ 21/ 14 02/ 21/ 14 02/ 21/ 14 02/ 21/ 14 Ví dụ 4 : Di chuyển cursor using System; class Vidu1_4 { static public void Main() { Console.Clear();... hinh Console.ForegroundColor=ConsoleColor.Green; Console.SetCursorPosition (10 ,2); Console.Write("What is your name "); String name=Console.ReadLine(); Console.SetCursorPosition (10 ,4); Console.WriteLine("Hello ,"+name); return; }} 02/ 21/ 14 Ví dụ 5:kiểu int, chuyển chuỗi sang số using System; class Vidu1_5 { static public void Main() { Console.Clear(); Console.ForegroundColor=ConsoleColor.Green; Console.SetCursorPosition (10 ,2);... String name =""; Console.Clear(); Console.ForegroundColor=ConsoleColor.Green; Console.SetCursorPosition (10 ,2); Console.Write("What is your name "); 02/ 21/ 14 name=Console.ReadLine(); Console.SetCursorPosition (10 ,4); Console.Write("When were you born , "+name + " : "); String sborn=Console.ReadLine(); born =Int32.Parse(sborn); age = thisyear - born ; Console.SetCursorPosition (10 ,5); Console.WriteLine(name... born ; Console.SetCursorPosition (10 ,5); Console.WriteLine(name +" , you're " + age + " years old"); return 0; } } 02/ 21/ 14 danhsachthamso 02/ 21/ 14 0 1 3. 51 17.56 Ví dụ 8: Tham số dòng lệnh using System; class Vidu1_7 { static public void Main(String[] args) { int count = args.Length; if (count !=2 ) return; float num1 = Single.Parse(args[0]); float num2 = Single.Parse(args [1] ); Console.WriteLine(num1 +... Console.WriteLine(num1 + (num1+num2) ); Console.WriteLine(num1 + Console.WriteLine(num1 + (num1*num2) ); Console.WriteLine(num1 + } } 02/ 21/ 14 " + " + num2 + " = " + " - " + num2 + " = " + (num1-num2) ); " x " + num2 + " = " + " / " + num2 + " = " + (num1/num2) ); Ví dụ 9: Phát âm thanh using System; public class Vidu1_9 { public static void Main() { int time=500, f=500; for (int i=0;i . name=Console.ReadLine();
Console.ForegroundColor=ConsoleColor.Green;
Console.WriteLine("Hello, "+name);
return;
} }
02/ 21/ 14
02/ 21/ 14
02/ 21/ 14
02/ 21/ 14
02/ 21/ 14
. Main()
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write("What is your name ");
String name=Console.ReadLine();
Console.ForegroundColor=ConsoleColor.Green;
Console.WriteLine("Hello,