Starting from:

$25

CSE102 - Programming Assignment 1 - Solved


. 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.

 

Figure 1: Visualization

Example

#                    commands                                         comments

line 0 > 10.4 34.8                                                                 User enters point coordinates for class 1

line 1 > 3.5 45.9

> . > . > .

line 10 > 22.2 12.6                                                              User enters point coordinates for class 2

line 11 > 62.1 11.0

> . > . > .

line 20 > 10.2 34.9                                                          User enters a test point

line 21 > class 1                                                               Program prints its class

line 22 > 10.3 33.8                                                          User enters a test point

line 23 > class 1                                                               Program prints its class

> . > . > .

line x > q                                                                          User enters something not expected

Program quits.

Remarks
•     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).


More products