Instructor: DR YUAN Cheng Jiun (CJ)
Email: cjyuan@cse.cuhk.edu.hk
Office:: SHB 129
Tutor: Chan Kam Tong (Thomas)
Email: ktchan@cse.cuhk.edu.hk
Office:: SHB 114A
Other Materials:
Login to WebCT to access other course materials
|
Tutorial Notes
|
Submission Guideline (Read this before starting your assignment):
|
-
Your source code file must be named "main.c".
(In case the assignment requires multiple files, the one containing the main function must be named "main.c")
-
Compress your completed source code file(s) into a zip file named "main.zip".
(Do not include any folders inside your zip file.)
-
Send an email to csc1110@cse.cuhk.edu.hk
with title "CSC1110 Assignment X Y" (without quotes).
X is the assignment number.
Y is your student ID (Enter all 8 digits).
For example, your student ID is 08123456 and you want to submit your assignment 1, then the title will be:
CSC1110 Assignment 1 08123456
Attach the "main.zip" from the previous step to the email.
Use your CUHK email account to submit the assignments. Other email accounts are not accepted.
-
Wait for an email reply. The reply should state whether your program has passed our tests.
You will get the score for the assignment only if your program passes our tests.
If no reply is received after a reasonable period of time. Try to submit again or contact the TA directly.
|
Assignments:
|
Assignments 1
Specification:
| Objective: | To write your first C program (The "HelloWorld" program). |
| Input: | Nothing |
| Output: | HelloWorld! |
| Deadline: | 24-Jan 23:59 |
Sample Output:
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
Assignments 2
Specification:
| Objective: |
To write a temperature unit conversion program.
- Prompt the user for input ("Enter a temperature in degree celsius: ")
- Convert the temperature
- Output the result to the screen (i.e., printf)
|
| Input: | A temperature value in Celsius (Integer) |
| Output: | The temperature value converted to Fahrenheit (Integer) |
| Help / Note: |
-
Celsius to Fahrenheit Conversion Function:
[F] = [C] x 9 / 5 + 32
We require only integer answers. No manual rounding is needed.
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 24-Jan 23:59 |
Sample Output 1:
Enter a temperature in degree celsius: 32
89
|
Sample Output 2:
Enter a temperature in degree celsius: -10
14
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
|
==================================
|
Assignments 3
Specification:
| Objective: |
Fair division of cake?
- Ask the user for the number of cakes (n) and people (m) available
- A cake can only be cut evenly into 3 pieces. (Not 2 pieces, 4 pieces, etc.)
- Tell whether the cakes can be equally distributed to everyone (i.e., every person gets the same amount of cakes)
- If so, output also the amount of cakes each person will get
- Output "Not enough cakes!" if there are not enough cake for everybody.
|
| Input: | n and m. Both are positive integers > 0. |
| Output: |
- Whether the cake can be equally distributed to everyone. ("Yes" / "No" / "Not enough cakes!")
- The amount of cakes each person will get. (if the answer is Yes) [No need to simplify the factional part.]
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 20-Feb 23:59 |
Sample Output 1:
Enter the number of cakes: 24
Enter the number of people: 12
Yes. The amount of cakes each person receives is 2.
|
Sample Output 2:
Enter the number of cakes: 8
Enter the number of people: 6
Yes. The amount of cakes each person receives is 1 and 2/6.
|
Sample Output 3:
Enter the number of cakes: 2
Enter the number of people: 6
Yes. The amount of cakes each person receives is 2/6.
|
Sample Output 4:
Enter the number of cakes: 2
Enter the number of people: 5
No.
|
Sample Output 5:
Enter the number of cakes: 1
Enter the number of people: 5
Not enough cakes!
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
Assignments 4
Specification:
| Objective: |
Odd or Even?
- Read a sequence of integers from the user
- Count the number of odd numbers in the sequence
- Print the sum of all even numbers in the sequence
|
| Input: | A sequence of positive integers > 0. The numbers are separated by a whitespace. The sequence ends with the number 0. |
| Output: |
- The number of odd numbers and the sum of all even numbers in the sequence, separated by a whitespace.
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 20-Feb 23:59 |
Sample Output 1:
1 2 3 4 5 6 7 8 9 10 0
5 30
|
Sample Output 2:
Sample Output 3:
Sample Output 4:
Sample Output 5:
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
Assignments 5
Specification:
| Objective: |
Sum it up!
- Ask the user for the number of integers to sum up (n)
- Read n integers from the user. You can assume that all the numbers inputed by the user are distinct (i.e., No repetitions).
- Print the sum of the n integers excluding the largest and the smallest number.
|
| Input: | n and a set of n distinct integers. n ≥ 0. |
| Output: |
- the sum of the n integers excluding the largest and the smallest number.
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 20-Feb 23:59 |
Sample Output 1:
Enter the number of integer to add: 5
Enter an integer: 3
Enter an integer: 7
Enter an integer: 4
Enter an integer: 1
Enter an integer: 8
The answer is 14.
|
Sample Output 2:
Enter the number of integer to add: 1
Enter an integer: 5
The answer is 0.
|
Sample Output 3:
Enter the number of integer to add: 0
The answer is 0.
|
Sample Output 4:
Enter the number of integer to add: 10
Enter an integer: 10
Enter an integer: 53
Enter an integer: 8
Enter an integer: 0
Enter an integer: -1
Enter an integer: 20
Enter an integer: -15
Enter an integer: 6
Enter an integer: 2
Enter an integer: 31
The answer is 76.
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
|
==================================
|
Assignments 6
Specification:
| Objective: |
Dice Game
- Implement a dice game as described in the specification.
- Please use the template for you to start your assignment.
- Please download the sample program for reference.
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample program. Including the spaces and cases.
|
| Update: |
The definition of "Two of a kind" is now updated to
"Two of the three dices show the same value."
to align with the sample program.
You can ignore this update if you have passed the online test.
|
| Deadline: | 6-Mar 23:59 |
Sample Output 1 (Please check against the sample program):
Please enter a seed number: 5000
1. Test Functions
2. Play Game
Please enter your choice (1-2): 2
=====================================================
Your current balance is: 1000
1. Small [1:2]
2. Big [1:2]
3. Straight [1:9]
4. Two of a kind [4:9]
5. Three of a kind [1:36]
6. Quit
Please enter your choice (1-6): 1
Please enter your bet (1-1000): -100
Bet amount is out of range. Please try again.
Please enter your bet (1-1000): 10000
Bet amount is out of range. Please try again.
Please enter your bet (1-1000): 100
The three dices show: 5 2 4 (Sorry, you lose!)
=====================================================
Your current balance is: 900
1. Small [1:2]
2. Big [1:2]
3. Straight [1:9]
4. Two of a kind [4:9]
5. Three of a kind [1:36]
6. Quit
Please enter your choice (1-6): 2
Please enter your bet (1-900): 100
The three dices show: 6 6 3 (Congratulation! You win!)
=====================================================
Your current balance is: 1000
1. Small [1:2]
2. Big [1:2]
3. Straight [1:9]
4. Two of a kind [4:9]
5. Three of a kind [1:36]
6. Quit
Please enter your choice (1-6): 7
Invalid option, please try again.
=====================================================
Your current balance is: 1000
1. Small [1:2]
2. Big [1:2]
3. Straight [1:9]
4. Two of a kind [4:9]
5. Three of a kind [1:36]
6. Quit
Please enter your choice (1-6): 6
Your remaining balance is: 1000
Thank you for playing this game.
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
|
==================================
|
Assignments 7
Specification:
| Objective: |
Remove Duplicated Elements
- Get a list of integers from the user and store it into an array
- Remove the duplicated integers from the array
- Print resulting array
|
| Input: | A list of n positive integers > 0 and ≤ 100. Where n ≤ 1000. The list of integer ends with 0. |
| Output: |
- A list of number with duplicated elements removed. The order of this list should remain the same.
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 13-Mar 23:59 (Note that the deadline is different from Assignment 8 and 9. |
Sample Output 1:
Sample Output 2:
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 0
1 2 3 4 5 6 7 8 9
|
Sample Output 3:
1 6 5 40 6 1 40 3 0
1 6 5 40 3
|
Sample Output 4:
10 56 94 13 0
10 56 94 13
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
Assignments 8
Specification:
| Objective: |
Reversing Array
- Get a list of integers from the user and store it into an array
- Get instructions from user and perform the corresponding operation
- Each instruction contains two numbers, you are to reverse the portion of the array indicated by these 2 numbers.
- Print "Index out of bound" if an instruction contains an invalid index
- Print resulting array
|
| Input: |
- A list of n positive integers > 0. Where n ≤ 1000. The list of integer ends with 0.
-
A set of instruction. Each instruction consists of 2 integers indicating the sub-array to be reversed.
The first integer is the starting index of the sub-array and the second integer is the ending index of the sub-array.
- The first element in the original list of integers has the index 0.
- The last instruction is "-1 -1". In this case, your program does not need to output "Index out of bound".
|
| Output: |
- The resulting list of numbers after performing the reverse operations as specified by the input instructions.
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 20-Mar 23:59 (Note that the deadline is different from Assignment 7.) |
Sample Output 1:
1 2 3 4 5 6 7 8 9 0
0 4
-1 -1
5 4 3 2 1 6 7 8 9
|
Sample Output 2:
1 2 3 4 5 6 7 8 9 0
0 1
0 4
7 8
-1 -1
5 4 3 1 2 6 7 9 8
|
Sample Output 3:
1 2 3 4 5 6 7 8 9 0
3 3
-1 -1
1 2 3 4 5 6 7 8 9
|
Sample Output 4:
8 4 2 6 9 0
0 4
-1 2
Index out of bound
2 5
Index out of bound
3 2
Index out of bound
0 4
-1 -1
8 4 2 6 9
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
Assignments 9
Specification:
| Objective: |
Data Statistics
- Get a list of integers from the user and store it into an array
- Compute some statistics of the input numbers (e.g., mean, median, etc.)
|
| Input: | A list of n positive integers > 0 and ≤ 50. Where n ≤ 1000. The list of integer ends with 0. |
| Output: |
- The following statistics
- Number of integers in each number range (i.e., 1-10, 11-20, 21-30, 31-40, 41-50)
- Mean (truncate to integer), Mode and Median of the input numbers
- Tie-breaking rules
- Mode: Choose the smallest number among all numbers with the same frequency
- Median: Choose the smaller value
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 20-Mar 23:59 (Note that the deadline is different from Assignment 7.) |
Sample Output 1:
5 15 25 35 45 0
1-10: 1
11-20: 1
21-30: 1
31-40: 1
41-50: 1
Mean: 25
Mode: 5
Median: 25
|
Sample Output 2:
1 1 2 2 2 3 4 4 4 4 0
1-10: 10
11-20: 0
21-30: 0
31-40: 0
41-50: 0
Mean: 2
Mode: 4
Median: 2
|
Sample Output 3:
9 7 5 3 1 8 6 4 2 0
1-10: 9
11-20: 0
21-30: 0
31-40: 0
41-50: 0
Mean: 5
Mode: 1
Median: 5
|
Sample Output 4:
0
1-10: 0
11-20: 0
21-30: 0
31-40: 0
41-50: 0
Mean: 0
Mode: 0
Median: 0
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
|
==================================
|
Assignments 10
Specification:
| Objective: |
String Processing Exercise
- Read one line from the user each time and store the string into a character array
- Remove duplicated spaces in the string
-
Change long weekday names in the string to short form
- Monday -> MON
- Tuesday -> TUE
- Wednesday -> WED
- Thursday -> THU
- Friday -> FRI
- Saturday -> SAT
- Sunday -> SUN
- Add 1 to all integers inside the string (i.e. "ABC 1999 xyz" -> "ABC 2000 xyz"
No need to handle cases like: "ABC1999xyz", "ABC1999 xyz", "ABC 1999xyz", "19xyz99"). No negative values will appear in the input.
- Print the resulting string
|
| Input: |
Several lines of string.
- The last line contains the character "." only.
- Each line contains at most 100 characters (excluding the ending "\0" or "\n") and has no leading or trailing spaces.
|
| Output: |
- The resulting string after performing the operations specified in the objective.
|
| Help / Note: |
-
C libraries used:
- stdio.h
- stdlib.h
- string.h
- ctype.h
Other libraries are not allowed.
-
Note the sample output. Your program's outputs should be exactly the same as our sample output. Including the spaces and cases.
|
| Deadline: | 3-Apr 23:59 Extended to 6-Apr 23:59 |
Sample Output 1:
Monday, Monday ,Monday
Monday, MON ,Monday
Monday MONDAY mONDAY MoNdAy mOnDaY
MON MON MON MON MON
This line contains a lot of SPACE.
This line contains a lot of SPACE.
CSC1110 is great!
CSC1110 is great!
In Chinese, Monday literally means " week 0 ", Tuesday means " week 1 ", etc.
In Chinese, MON literally means " week 1 ", TUE means " week 2 ", etc.
0 x 0 = 0 ?
1 x 1 = 1 ?
.
.
|
*
Blue text: Outputs produced by your program.
Red text: Inputs by user.
|
|
==================================
|
Assignments 11
Specification:
| Objective: |
Simple Drawing Program
- Simulate a simple drawing program as described in the specification.
- Please download the sample program for reference.
|
| Input / Output: |
All input and outputs are done via File I/O. Please refer to the specification for details.
|
| Program Execution: |
Run your program should be run under command prompt using the following statement:
main.exe input.txt output.txt
Assuming that:
- main.exe - Program Executable Name
- input.txt - Input file name
- output.txt - Output file name
|
| Scoring: |
Your score for the assignment is proportional to the number of test cases your program can pass in the online submission system. Here are the test case descriptions:
| Test Case | Description |
| 1.txt | General Test Cases. Combination of input statements. |
| 2.txt | Simple rectangle creation and listing. |
| 3.txt | Simple mouse click Test. |
| 4.txt | Complicated mouse click test with TO-BACK and TO-FRONT statements. |
| 5.txt | Complicated mouse click test with TO-BACK and TO-FRONT statements. |
| 6.txt | Move, resize, change color statements. |
|
| Help / Note: |
-
Note the sample output. Your program's outputs should be exactly the same as our sample program. Including the spaces and cases.
|
| Deadline: | 17-Apr 23:59 Extended to 21-Apr 23:59 |
Sample Test Cases:
Please derive your own test cases to locate other possible errors in your program.
|