【代码】
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define maxSize 255
#define PI 3.1415926
typedef struct
{
double x1, y1;
}Point;
typedef union
{
Point p;
double r;
}share;
typedef struct LNode
{
char name[maxSize];
double x0, y0;
share data;
struct LNode* next;
}LNode;
void draw_line(double x1, double y1, double x2, double y2)
{
}
void draw_rect(double x1, double y1, double w, double h)
{
}
void draw_circle(double x, double y, double r)
{
Point p;//p为圆弧上的一点
double a;//a为p到圆心o的连线与x轴的夹角
for (a = 0; a <= 2 * PI; a += 0.01)
{
//计算p的坐标
p.x1 = x + r * cos(a);
p.y1 = y + r * sin(a);
draw_line(x, y, p.x1, p.y1);
}
}
LNode* ReadData()
{
FILE* fp;
if ((fp = fopen("201410data.txt", "r")) == NULL)
exit(0);
LNode* L;
LNode* r, *s;
char str[maxSize];
fscanf(fp, "%s", str);
L = (LNode*)malloc(sizeof(LNode));
L->next = NULL;
r = L;
while (!feof(fp) && strcmp(str, "END") != 0)
{
s = (LNode*)malloc(sizeof(LNode));
strcpy(s->name, str);
if (strcmp(str, "LINE") == 0 || strcmp(str, "RECT") == 0)
fscanf(fp,"%d %d %d %d", &s->x0, &s->y0, &s->data.p.x1, &s->data.p.y1);
else
fscanf(fp, "%d %d %d", &s->x0, &s->y0, &s->data.r);
r->next = s;
r = s;
fscanf(fp, "%s", str);
}
r->next = NULL;
fclose(fp);
return L;
}
//查找输出图形
void FindPolygon(LNode* L)
{
char s[maxSize] = "RECT" ;
//scanf("%s",s);
LNode* p;
p = L->next;
while (p != NULL)
{
if (strcmp(p->name, s) == 0)
{
if (strcmp(p->name, "RECT") == 0)
draw_rect(p->x0, p->y0, p->data.p.x1, p->data.p.y1);
else if (strcmp(p->name, "LINE") == 0)
draw_line(p->x0, p->y0, p->data.p.x1, p->data.p.y1);
else
draw_circle(p->x0, p->y0, p->data.r);
}
p = p->next;
}
}
void Delete_All(LNode*L)
{
LNode*p, *q;
p = L->next;
L->next = NULL;
while (p != NULL)
{
q = p->next;
free(p);
p = q;
}
free(L);
}
int main()
{
return 0;
}