Description
Description
• This is an individual assignment. Please do not collaborate
• If you think that this document does not clearly describe the assignment, ask questions before its too late.
This is a C Programming assignment. You will write a C program according to the following description.
• Your program catches user input, learns and tests a simple classifier. This assignment is about using control
statements, performing arithmetic operations and simple input/output.
Program Flow
• Read pre-defined number of points for class 1.
• Read pre-defined number of points for class 2.
• Find the average point for each class.
• Find the line connecting the two average points. • Find the midpoint of the connecting line.
• Find the perpendicular separating line which passes through the midpoint.
• Classify any given point and print its label until an unusual input is encountered.
Example
# commands
line 0 > 10.4 34.8 line 1 > 3.5 45.9
>.
>.
>.
line 10 > 22.2 12.6 line 11 > 62.1 11.0 >.
>.
>.
line 20 > 10.2 34.9
line 21 > class 1
average point
Figure 1: Visualization
comments User enters point coordinates for class 1
User enters point coordinates for class 2
User enters a test point Program prints its class
1
separating line
line 22 > 10.3 33.8 line 23 > class 1
>. >. >.
line x > q
Remarks
User enters a test point Program prints its class
User enters something not expected Program quits.
- There will be 20 training samples (10 for each class). But, don’t make this number hard-coded. Use a macro. Changing the macro should be enough for trying different number of samples. You can assume that the number of training samples for each class will be the same.
- There is no limit on the number of test points.
- Assume that non of the points will be on the separating line.
- Assume training phase will be error-free.
- Be careful with divide-by-zero situations. You can avoid them by perturbing the 0 results with very small
numbers.
- Do not print anything other than the expected output.
- Your program either prints class 1 or class 2. Each label should be on a new line. There shouldn’t be any
empty lines.
- You cannot use pointers and other things which are not covered in class.
- Using input/output redirection is advised. (Do not submit any of the files you used for testing).
Turn in:
- Source code of a complete C program. Name of the file should be in this format: <full_name>_<id>.c.
- Example: gokhan_kaya_000000.c. Please do not use any Turkish special characters.
- You don’t need to use an IDE for this assignment. Your code will be compiled and run in a command window.
- Your code will be compiled and tested on a Linux machine(Ubuntu). GCC will be used.
- Make sure you don’t get compile errors when you issue this command : gcc <full_name>_<id>.c.
- A script will be used in order to check the correctness of your results. So, be careful not to violate the expected
output format.
- Provide comments unless you are not interested in partial credit. (If I cannot easily understand your design,
you may loose points.)
- You may not get full credit if your implementation contradicts with the statements in this document.