Need help with my C programming lab. The text and header files are included. The
ID: 3850211 • Letter: N
Question
Need help with my C programming lab. The text and header files are included. The exact instructions are the pictures below. Please use comments to explain key parts.
Header File:
#ifndef FIG_H
#define FIG_H
#include <stdio.h>
#define MAXLEN 16
#define OC_COLOR 0
#define OC_ELLIPSE 1
#define OC_POLYLINE 2
#define OC_SPLINE 3
#define OC_TEXT 4
#define OC_ARC 5
#define OC_COMPOUND 6
// ARC SUB-TYPE
#define ST_OPEN_ENDED 1
#define ST_PIE_WEDGE 2
// ELLIPSE SUB-TYPE
#define ST_ELLIPSE_BY_RADII 1
#define ST_ELLIPSE_BY_DIAMETERS 2
#define ST_CIRCLE_BY_RADIUS 3
#define ST_CIRCLE_BY_DIAMETER 4
// POLYLINE SUB-TYPE
#define ST_POLYLINE 1
#define ST_BOX 2
#define ST_POLYGON 3
#define ST_ARC_BOX 4
#define ST_PIC_BOUNDING_BOX 5
// SPLINE SUB-TYPE
#define ST_OPEN_APPROX_SPLINE 0
#define ST_CLOSED_APPROX_SPLINE 1
#define ST_OPEN_INTERPOLATED_SPLINE 2
#define ST_CLOSED_INTERPOLATED_SPLINE 3
#define ST_OPEN_X_SPLINE 4
#define ST_CLOSED_X_SPLINE 5
// TEXT SUB-TYPE
#define ST_LEFT_JUSTIFIED 0
#define ST_CENTER_JUSTIFIED 1
#define ST_RIGHT_JUSTIFIED 2
enum ArrowType {STICK_TYPE, CLOSED_TRIANGLE, CLOSED_INDENTED, CLOSED_POINTED};
enum ArrowStyle {HOLLOW, FILLED};
typedef struct arrow_t {
int active;
enum ArrowType type;
enum ArrowStyle style;
float thickness, width, height;
} Arrow;
typedef struct attribute_t {
int line_style;
int thickness;
int pen_color;
int fill_color;
int depth;
int pen_style;
int area_fill;
float style_val;
int join_style;
int cap_style;
int radius;
int direction;
/* for text only */
int font;
double font_size;
double angle;
int font_flags;
int justification;
Arrow farrow, barrow;
} Attribute;
struct fig_config_t {
char orientation[MAXLEN];
char justification[MAXLEN];
char units[MAXLEN];
char papersize[MAXLEN];
float magnification;
char multiple_page[MAXLEN];
int transparent_color;
int resolution;
int coord_system;
int tracing;
};
int fig_open(FILE *fp);
int fig_convert(double x);
int fig_userinfo(FILE *fp, int grid, char *title, char *author, char *date);
int fig_polyline(FILE *fp, int *x, int *y, int n, char *astring);
int fig_box(FILE *fp, int *x, int *y, char *astring);
int fig_polygon(FILE *fp, int *x, int *y, int n, char *astring);
int fig_arc_box(FILE *fp, int *x, int *y, char *astring);
int fig_spline(FILE *fp, int *x, int *y, int n, char *astring);
int fig_circle(FILE *fp, int cx, int cy, int radius, char *astring);
int fig_arc(FILE *fp, double cx, double cy, int *x, int *y, char *astring);
int fig_text(FILE *fp, int x, int y, char *string, char *astring);
#endif
Text file of circle dimentions:
5.65 1.92 0.74 2.49 3.19 1.22
4.13 4.11 1.32 7.39 6.52 0.56
1.41 6.62 1.29 1.26 7.20 0.66
1.69 6.50 0.84 5.44 0.84 0.80
5.53 2.86 1.09 3.59 2.89 1.49
8.31 4.62 0.62 2.26 5.57 1.11
8.24 5.08 1.13 5.69 1.20 0.72
1.60 6.02 0.71 8.00 5.56 0.99
8.30 1.60 1.12 6.67 4.70 0.62
1.52 3.08 1.45 7.12 1.53 1.50
3.30 3.69 1.30 4.51 3.42 1.28
6.81 1.53 1.19 8.87 7.46 0.58
7.66 4.44 1.24 5.98 6.66 1.40
1.99 3.42 0.98 2.17 1.56 0.96
7.10 1.34 0.56 7.94 1.91 1.19
1.98 5.34 1.21 4.42 7.51 0.53
8.09 3.53 0.54 9.84 4.03 0.76
5.81 2.97 1.40 5.77 2.36 1.32
5.23 5.73 0.67 5.19 3.90 0.63
1.52 4.85 1.43 3.55 3.85 1.30
Explanation / Answer
Here you are finding shortest distance between diagrams. In this program you have defined constants for (x,y) coordinates, radius etc. After that you are converting dimension from INCHES to figure defined dimensions using fig_convert function. Then after that you have some functions such as fig_circe, fig_arc etc. which takes coordinates of two figures and process to print result.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.