Bài tập hướng dẫn thực hành: Lab Objective

Sử dụng cú pháp của ngôn ngữ C# Task 01. Conversion Thực hiện chương trình có nội dung code sau và cho biết kết quả của chương trình. Nhận xét dòng 13 có vấn đề gì xảy ra không? Tại sao. Thay đổi nội dung chương trình như sau:

doc13 trang | Chia sẻ: tlsuongmuoi | Lượt xem: 2142 | Lượt tải: 0download
Bạn đang xem nội dung tài liệu Bài tập hướng dẫn thực hành: Lab Objective, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Bài tập hướng dẫn thực hành: Lab Objective Sử dụng cú pháp của ngôn ngữ C# Task 01. Conversion Thực hiện chương trình có nội dung code sau và cho biết kết quả của chương trình. Nhận xét dòng 13 có vấn đề gì xảy ra không? Tại sao. Thay đổi nội dung chương trình như sau: Cho biết lý do xảy ra lỗi. Giải thích và sửa chữa chương trình lại để chương trình không bị lỗi. Task 02. Variables and Parameters Thực hiện chương trình có nội dung như sau: Cho biết tại sao chương trình bị lỗi? Và sửa lỗi cho chương trình. Thực hiện chương trình có nội dung như sau: Cho biết kết quả được hiển thị trên màn hình. Thực hiện Debug chạy từng dòng lệnh để nhận xét. Task 03. A Reference Parameters Viết chương trình để hoán vị giá trị của 2 số x và y. Nhận xét kết quả của chương trình sau: Thay đổi chương trình để thực hiện đúng yêu cầu đề bài. Bài tập thực hành tự làm: Sinh viên tự thực hành sau đó gửi kết quả qua email cho giáo viên. Lưu ý: Sinh viên nộp gửi mail trong top 5 sinh viên đầu được cộng +1 điểm. Sinh viên đến hết thời gian thực hành vẫn chưa hoàn thành xong -1 điểm. Mỗi sinh viên liệt kê kết quả ra một file word. Source của bài tập đóng gói tất cả thành 1 file nén. Gửi qua Email: phuochai2012@gmail.com Tiêu đề email: MSSV.BT01. Câu 01: Câu 02: Câu 03: Câu 04: Câu 05: Câu 07: Câu 08: Câu 09: Câu 10: Câu 11: Câu 13: Câu 14: Câu 15: Câu 16: Phần 2: Exercise 1 using System; class Class1 { static void Main() { const int y = 1,z = 2; const string x = "Hello"; string X = "World"; Console.WriteLine(y + z); Console.WriteLine(x + " " + X); Console.ReadLine(); } } 2.1 What is written by this program? 2.2 List all variables in this program. Exercise 2 using System; class Class1 { static void Main() { const int b=a+1; //1 const int d=c+3; //2 const int c=b+2; //3 const int a=1; //4 Console.WriteLine(a + b + c + d); Console.ReadLine(); } } 3.1 From this program, when compiled, there are some errors. Why? 3.2 This program can be corrected by rearrangement of lines (1) to (4). Rewrite CONSTANT DECLARATION PART of this program to correct it. ________________________ ________________________ ________________________ ________________________ Exercise 3 static void Main() { string s = "abc"; //1 int n = 0; //2 double x = 0.0; //3 s = n; //4 n = 1.0; //5 n = x; //6 x = 999; //7 x += n; //8 s = "abc" + 1; //9 s -= 1; //10 n = 1 + 1.5; //11 } In which line of this program (4-11) did errors occur? Line The problem is … PART II: Operators and Priorities Precedence Order Operator 1 () 2 ++(x),--(x),+(x),-(x) 3 *,/,% 4 +,- 5 =,+=,-=,*=,/=,%= 6 (x)++,(x)-- Exercise 4 class Test { static void Main() { double x = 3.0, y = 2.0; int a = 10, b = 2; (1) Console.ReadLine(); } } Insert the line numbered (1) using instructions from the following table. Fill the column output. (1) Output Console.WriteLine(x+a); Console.WriteLine(a/b); Console.WriteLine(y/x); Console.WriteLine(y%x); Console.WriteLine(++y%x-1); Console.WriteLine(y--%x+1); Console.WriteLine(a+b%b); Console.WriteLine(x/y*b); Console.WriteLine((a+b)/b%a); Console.WriteLine(9.0/5.0*(a-x)); Console.WriteLine(x+y-x*y%x); Console.WriteLine(57%50/25); PART III: Control Flow Exercise 5 class IfElseStruct { static void Main() { int x = 15; int y=20 ; if(x>y)Console.WriteLine(x); else Console.WriteLine(y) ; Console.ReadLine(); } } What is written from this program? Exercise 6 class ForStruct { static void Main() { for(int i=1 ;i<10 ;i++){ Console.WriteLine(i*i); } Console.ReadLine(); } } What is written from this program? Exercise 7 using System; { class WhileStruct { static void Main() { int n=10; while(true){ if(n>0){ Console.WriteLine(n); n--; } else break; } Console.ReadLine(); } } } What is written from this program? Exercise 8 using System; { class Foreach { static void Main() { int[] A={10,9,8,7,6,5,4,3,2,1}; foreach(var x in A){ Console.WriteLine(x); } Console.ReadLine(); } } } What is written from this program?

Các file đính kèm theo tài liệu này:

  • docBài tập hướng dẫn thực hành- Lab Objective.doc