Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 5. This lab covers 1. automated compilation process using make command 2. struct keyword in C with typedef specifier. 3. simple file 10 1.

image text in transcribed
image text in transcribed
image text in transcribed
Lab 5. This lab covers 1. automated compilation process using make command 2. struct keyword in C with typedef specifier. 3. simple file 10 1. Skeleton Preparation Create a text file (its filename has to be makefile") as below: CC - BCC # anything after the pond sign is a comment kmeans: kmean5.0 find-center.o find-label.o min-point.o max-point o scan-point. clean: $(RM) *.0 # be careful, the first character must be a tab cleanall: clean $(RM) label.exe be careful, the first character must be a tab and a header file (ece263L5.h) as below. Note that you are definitely not allowed to modify this header file. #ifndef ECE263LS_H / not to include the header file more than once */ #define ECE263L5 H #include typedef struct point_t { double x, y: } Point; double find_label(const Point *pos, int label, int n, const Point center, int k); double find_center(const Point "pos, const int *label, int n, Point center, int k); Point min_point(const Point "pos, int n); Point max_point(const Point "pos, int n); int scan_point(FILE *fp, Point "pos, int max_count); #endif 2. Implementation You will implement each function as a separate C file. The first two functions find label() and find_center() are very similar to xx() and yy() functions in the previous lab. The difference is to pass an array of Point structure as a pointer to the function instead of a 2D array. addition, it the argument label has sa NULL value, find center will consider al points are in a same label, so that it compute only one center point. min_point and max point() are to return the minimum x/y and the maximum x/y respectively. Be aware that they find the min (or max) x and y independently. The function scan point() is to read a data file into the array, whose maximum capacity is given as the third argument. The function returns the actual number of points read. If the file contains more than MAX points, the function stops reading after the MAX points. If the function does not stop after the MAX points, there would be a run-time error because the calling function has the memory space only up to the specified. To read it from standard input, you may use the function as Point position [MAX]; int num_points; num_points - scan_point(stdin, position, MAX); where stdin indicates a standard input. By default, the standard input is the keyboard, but you can change it by file redirection. In the function, you can use fscanf(fp, ...) instead of scanf(...). To know the end of file, refer the fscanf manual. You can compile the entire file using make command by typing $ make The command automatically find the dependency of source files specified in the makefile. If you update some source code, simply type make command at the prompt. You will make the main program kmean5.c to evaluate all functions and eventually print all data points with label. To delete all intermediate object files, you can type "make clean". 3. Execution and Results You will be given 3 data files (d211.d, d212.d. d213.d) with different numbers of data points. You will run the program for each data file and generate the resulting data with label and show what are lower and upper limits of the data points. For example, $ ./kmeans 0211.r If you want to print any intermediate result to the screen but not to the file, you can print them to the stderr using fprintf(stderr, ...) instead of printf(...). Use the gnuplot program to draw xy-graph with label for each data file. Did you find a good labeling? Try different center ata points to obtain a better labelling. Think about initial center points to obtain good labelling results. A good labelling is to form a group of clusterings. Use mingw32 Lab 5. This lab covers 1. automated compilation process using make command 2. struct keyword in C with typedef specifier. 3. simple file 10 1. Skeleton Preparation Create a text file (its filename has to be makefile") as below: CC - BCC # anything after the pond sign is a comment kmeans: kmean5.0 find-center.o find-label.o min-point.o max-point o scan-point. clean: $(RM) *.0 # be careful, the first character must be a tab cleanall: clean $(RM) label.exe be careful, the first character must be a tab and a header file (ece263L5.h) as below. Note that you are definitely not allowed to modify this header file. #ifndef ECE263LS_H / not to include the header file more than once */ #define ECE263L5 H #include typedef struct point_t { double x, y: } Point; double find_label(const Point *pos, int label, int n, const Point center, int k); double find_center(const Point "pos, const int *label, int n, Point center, int k); Point min_point(const Point "pos, int n); Point max_point(const Point "pos, int n); int scan_point(FILE *fp, Point "pos, int max_count); #endif 2. Implementation You will implement each function as a separate C file. The first two functions find label() and find_center() are very similar to xx() and yy() functions in the previous lab. The difference is to pass an array of Point structure as a pointer to the function instead of a 2D array. addition, it the argument label has sa NULL value, find center will consider al points are in a same label, so that it compute only one center point. min_point and max point() are to return the minimum x/y and the maximum x/y respectively. Be aware that they find the min (or max) x and y independently. The function scan point() is to read a data file into the array, whose maximum capacity is given as the third argument. The function returns the actual number of points read. If the file contains more than MAX points, the function stops reading after the MAX points. If the function does not stop after the MAX points, there would be a run-time error because the calling function has the memory space only up to the specified. To read it from standard input, you may use the function as Point position [MAX]; int num_points; num_points - scan_point(stdin, position, MAX); where stdin indicates a standard input. By default, the standard input is the keyboard, but you can change it by file redirection. In the function, you can use fscanf(fp, ...) instead of scanf(...). To know the end of file, refer the fscanf manual. You can compile the entire file using make command by typing $ make The command automatically find the dependency of source files specified in the makefile. If you update some source code, simply type make command at the prompt. You will make the main program kmean5.c to evaluate all functions and eventually print all data points with label. To delete all intermediate object files, you can type "make clean". 3. Execution and Results You will be given 3 data files (d211.d, d212.d. d213.d) with different numbers of data points. You will run the program for each data file and generate the resulting data with label and show what are lower and upper limits of the data points. For example, $ ./kmeans 0211.r If you want to print any intermediate result to the screen but not to the file, you can print them to the stderr using fprintf(stderr, ...) instead of printf(...). Use the gnuplot program to draw xy-graph with label for each data file. Did you find a good labeling? Try different center ata points to obtain a better labelling. Think about initial center points to obtain good labelling results. A good labelling is to form a group of clusterings. Use mingw32

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions