Make-up Class Method Students are advised to utilize the website NTU COOL for class compensation. Please note, the required login credentials are those associated with your individual training class account.
Recording Classroom Lectures Policy Recording of classroom lectures is prohibited unless advance written permission is obtained from the class instructor and any guest presenter(s).
Date | Summary |
---|---|
2025.4.15 |
|
2025.4.18 |
|
2025.4.22 | |
2025.4.25 |
|
2025.4.29 |
|
2025.5.2 (video) |
|
2025.5.6 |
|
2025.5.9 |
|
2025.5.13 |
|
2025.5.16 |
|
Promotion |
Late Homework Policy All programming labs should be submitted before the last date of class in order to deliver your final grades to the office so that the certificates can be issued soon. (See a recent complaint letter here.)
Homework Submission Send the source code (the file with .cs extension) to my email shown in the beginning of this page. Remember to indicate this class number, your full Chinese name, and homework number in your email title. For example, [CSharp 438] Homework 1 盧政良. Do not attach any class file because any executable file will be ruled out by Gmail. Demonstrate your solutions on GitHub. Please create a new Github account if you do not have one. Then create a new repository (in short, repo) for this course, nameed like CSharp_nnn. You may include a README file with a short description for this repo, especially stating your full Chinese name. You should upload only your source codes with .cs extension and leave the rest of project files on your own computer. Please ensure the repo is accessible to the instructor. Send me with the repo hyperlink and I will review your solutions directly on GitHub. No late-submission policy.
Write a program for number-guessing game (you may refer to Guess the Number if you have never played this game). The program first generates a secret number ranging between 0 and 99, inclusive. Then the program asks the player to guess a number. If the input number is equal to the secret number, then the player wins. If not, then update the range depending on the input accordingly. (For example, assume that the secret number is 42. If the player types 50 for the first time, then the program shows (0, 49) on the screen.) When there is only one integer left, the player loses the game. Also, make sure that the player types a number in the feasible range; otherwise, ask the player to redo the input.
Add some strategies (AI?) to play this game and calculate each winning rate by using these strategies for 1e5 times. For example, the naive strategy is to guess a number in random, and its result is around 66%. Surprisingly, the winning rate for binary search is about 63%, not as expected to beat the naive one. Why?
Find the optimal strategy to beat the former two. The result is shown below. As you could see, the winning rate of my optimal strategy reaches 99%!
Modify the game loop which allows the player to guess at most 7 times (why?). Also report their performance like below:
The performance of binary search remains ~63% while the other two degrade severely!
The virus, COVID-19 (aka Wuhan coronavirus), is primarily spread from close contact with infected people. You task is to design an algorithm to identify the chain of virus transmission from one person to the next. For simplicity, let N be the number of citizens, each denoted by an integer ID from 0 to N − 1. Each citizen is asked to keep a record of the ID of the person they comes in contact with. It is assumed that no two citizens keep the same ID of the citizen in close contact. To avoid typing numbers by hand, I suggust using the shuffling algorithm to generate a random sequence of 0, 1, 2, ..., N − 1 for testing. For example, consider N = 16 and assume that the citizen with ID 0 is initially infected. Your program is to identify and list all IDs along this infection chain. A possible output is shown below.
Let M be a 2D matrix whose number of ``rows'' and ``cols'' are integers specified by user input from the keyboard. Write a program for the following tasks: (1) generate integers from 0 to rows * cols − 1 and fill up a 2D array (more explicitly, created by calling new int[rows, cols]) with these integers in a random order (you could use the shuffle algorithm here), (2) sort M by performing row exchanges based on the numbers of the first columns in ascending order, and (3) output the resulting matrix. Note that you need to encapsulate some code snippets into functions / methods as needed.
Redo Lab 3 but using List<List<int>>
instead of native arrays for M.
Rewrite your program of Lab 1 in OOP style. First analyze the functionalities of Lab 1 and then define at least two classes for each functionality. For instance, you could create two objects: one object to manage the game procedure, the other for the player who generates an integer within feasible range during the game. To achieve this, you will need to define a protocol, similar to the relationship between the Console.WriteLine method and the ToString method of any C# object. Hence the game will have minimal dependency on the player (the game won't need to know which kind of player during the game procudure). A possible class design in UML is shown below.
Use WPF to implement a simple calculator illustrated in the figure below.