ex-01
(高顯忠, sjgau4311@gmail.com, 2011-01-25 15:09)
1樓
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
// --------------------------------------------------------
struct Point {
int x;
int y;
} ;
enum Color {red=1, yellow, green, cyan, blue, pink, white };
struct Line {
struct Point p1;
struct Point p2;
double len;
int c1;
} ;
double sqr(int x)
{
return(x*x);
}// end of sqr()
// dist(line2[i]);
double dist(struct Line l2)
{
return(sqrt((sqr(l2.p1.x - l2.p2.x )) +
(sqr(l2.p1.y - l2.p2.y ))));
}// end of dist()
int main(int argc, char *argv[])
{
struct Line line2[10];
int c2;
int i;
srand(time(NULL));
for (i=0;i<10;i++) {
line2[i].p1.x= rand()%100;
line2[i].p1.y= rand()%100;
line2[i].p2.x= rand()%100;
line2[i].p2.y= rand()%100;
c2= rand()%7 + 1;
while ((c2==red) || (c2==blue)) {
c2= rand()%7 + 1;
}
line2[i].c1= c2;
line2[i].len= dist(line2[i]);
}
system("PAUSE");
return EXIT_SUCCESS;
}