예제 #1
0
파일: mpoint.c 프로젝트: rivasyafri/ADT
void MasukProgram() {
	int a;
	float b,c;
	int d,e;
	scanf("%d",&a);
	switch (a) {
	case 1 : { 
				BacaPOINT(&P1);
				break;
			}
	case 2 : {
				BacaPOINT(&P2);
				break;
			}
	case 3 : {
				TulisPOINT(P1);
				break;
			}
	case 4 : {
				TulisPOINT(P2);
				break;
			}
	case 5 : { 
				TulisPOINT(plus(P1,P2));
				break; 
		}
	case 6 : { 
				TulisPOINT(minus(P1,P2));
				break; 
			}
	case 7 : { 
				printf("%.2f\n",dot(P1,P2));
				break; 
			}
	case 8 : {
				printf("%.2f\n",cross(P1,P2));
				break;
			}
	case 9 : {
				if (IsOrigin(P1)) {
					printf("Ya\n");
				} else {
					printf("Tidak\n");
				}
				break;
			}
	case 10 : {
				if (IsOnSbX(P1)) {
					printf("Ya\n");
				} else {
					printf("Tidak\n");
				}
				break;
			}
	case 11 : {
				if (IsOnSbY(P1)) {
					printf("Ya\n");
				} else {
					printf("Tidak\n");
				}
				break;
			}
	case 12 : {
				if (EQ(P1,P2)) {
					printf("Ya\n");
				} else {
					printf("Tidak\n");
				}
				break;
			}
	case 13 : {
				if (NEQ(P1,P2)) {
					printf("Ya\n");
				} else {
					printf("Tidak\n");
				}
				break;
			}
	case 14 : {
				if (lebihkecil(P1,P2)) {
					printf("Ya\n");
				} else {
					printf("Tidak\n");
				}
				break;
			}
	case 15 : {
				if (lebihbesar(P1,P2)) {
					printf("Ya\n");
				} else {
					printf("Tidak\n");
				}
				break;
			}
	case 16 : {
				printf("Titik berada di kuadran %d\n",Kuadran(P1));
				break;
			}
	case 17 : {
				TulisPOINT(NextX(P1));
				break;
			}
	case 18 : {
				TulisPOINT(NextY(P1));
				break;
			}
	case 19 : {
				scanf("%f %f",&b,&c);
				TulisPOINT(PlusDelta(P1,b,c));
				break;
			}
	case 20 : {
				scanf("%d %d",&d,&e);
				TulisPOINT(MirrorOf(P1,d,e));
				break;
			}
	case 21 : {
				printf("Jarak dari (0,0) adalah %.2f\n",Jarak0(P1));
				break;
			}
	case 22 : {
				printf("Panjang P1 ke P2 adalah %.2f\n",Panjang(P1,P2));
				break;
			}
	case 23 : {
				scanf("%f %f",&b,&c);
				Geser(&P1,b,c);
				break;
			}
	case 24 : {
				GeserKeSbX(&P1);
				break;
			}
	case 25 : {
				GeserKeSbY(&P1);
				break;
			}
	case 26 : {
				scanf("%d %d",&d,&e);
				Mirror(&P1,d,e);
				break;
			}
	case 27 : {
				scanf("%f",&b);
				Putar(&P1,b);
				break;
			}
	case 28 : {
				scanf("%d",&b);
				SetAbsis(P1,b);
				break;
			}
	case 29 : {
				scanf("%d",&b);
				SetOrdinat(P1,b);
				break;
			}
	case 30 : {
				keluar = true;
				break;
			}
	}
}
int main(){
	int i,h,DX,DY;
	float sudut;
	POINT ptest,p1,p2;
	srand(time(NULL));
	ptest=MakePOINT(rand(),rand());
	TulisPOINT(ptest);
	SetAbsis(&ptest,rand());
	TulisPOINT(ptest);
	SetOrdinat(&ptest,rand());
	TulisPOINT(ptest);
	BacaPOINT(&ptest);
	TulisPOINT(ptest);

//cek operator relasional
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		p2=MakePOINT(rand(),rand());
		TulisPOINT(p1);
		printf("==");
		TulisPOINT(p2);
		printf("=");
		h=EQ(p1,p2);
		printf("%x\n",h);
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		p2=p1;
		TulisPOINT(p1);
		printf("==");
		TulisPOINT(p2);
		printf("=");
		h=EQ(p1,p2);
		printf("%x\n",h);
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		p2=MakePOINT(rand(),rand());
		TulisPOINT(p1);
		printf("!=");
		TulisPOINT(p2);
		printf("=");
		h=NEQ(p1,p2);
		printf("%x\n",h);
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		p2=p1;
		TulisPOINT(p1);
		printf("!=");
		TulisPOINT(p2);
		printf("=");
		h=NEQ(p1,p2);
		printf("%x\n",h);
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		TulisPOINT(p1);
		printf("is Origin");
		printf("=");
		h=IsOrigin(p1);
		printf("%x\n",h);
	}
	p1=MakePOINT(0,0);
	TulisPOINT(p1);
	printf("is Origin");
	printf("=");
	h=IsOrigin(p1);
	printf("%x\n",h);
	printf("\n\ncek\n");
	p1=MakePOINT(0,rand());
	TulisPOINT(p1);
	printf("is Origin");
	printf("=");
	h=IsOrigin(p1);
	printf("%x\n",h);
	printf("\n\ncek\n");
	p1=MakePOINT(rand(),0);
	TulisPOINT(p1);
	printf("is Origin");
	printf("=");
	h=IsOrigin(p1);
	printf("%x\n",h);
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		TulisPOINT(p1);
		printf("is On SbX");
		printf("=");
		h=IsOnSbX(p1);
		printf("%x\n",h);
	}
	p1=MakePOINT(0,0);
	TulisPOINT(p1);
	printf("is SbX");
	printf("=");
	h=IsOnSbX(p1);
	printf("%x\n",h);
	p1=MakePOINT(0,rand());
	TulisPOINT(p1);
	printf("is SbX");
	printf("=");
	h=IsOnSbX(p1);
	printf("%x\n",h);
	p1=MakePOINT(rand(),0);
	TulisPOINT(p1);
	printf("is SbX");
	printf("=");
	h=IsOnSbX(p1);
	printf("%x\n",h);
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		TulisPOINT(p1);
		printf("is On SbY");
		printf("=");
		h=IsOnSbY(p1);
		printf("%x\n",h);
	}
	p1=MakePOINT(0,0);
	TulisPOINT(p1);
	printf("is SbY");
	printf("=");
	h=IsOnSbY(p1);
	printf("%x\n",h);
	p1=MakePOINT(0,rand());
	TulisPOINT(p1);
	printf("is SbY");
	printf("=");
	h=IsOnSbY(p1);
	printf("%x\n",h);
	p1=MakePOINT(rand(),0);
	TulisPOINT(p1);
	printf("is SbY");
	printf("=");
	h=IsOnSbY(p1);
	printf("%x\n",h);
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand()-rand(),rand()-rand());
		printf("kuadran ");
		TulisPOINT(p1);
		printf("=");
		h=Kuadran(p1);
		printf("%d\n",h);
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		printf("NextX ");
		TulisPOINT(p1);
		printf("=");
		TulisPOINT(NextX(p1));
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand(),rand());
		printf("NextY ");
		TulisPOINT(p1);
		printf("=");
		TulisPOINT(NextY(p1));
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand()-rand(),rand()-rand());
		TulisPOINT(p1);
		DX=rand()%10;
		DY=rand()%10;
		printf(" + (%d,%d) =",DX,DY);
		TulisPOINT(PlusDelta(p1,DX,DY));
		printf("\n");
		TulisPOINT(p1);
		printf(" + (%d,%d)g =",DX,DY);
		Geser(&p1,DX,DY);
		TulisPOINT(p1);
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT(rand()-rand(),rand()-rand());
		printf("MirrorOf(");
		TulisPOINT(p1);
		printf(",1,0) =");
		TulisPOINT(MirrorOf(p1,1,0));
		printf("\n");
	}
	for (i=0;i<14;i++){
		p1=MakePOINT(rand()-rand(),rand()-rand());
		printf("MirrorOf(");
		TulisPOINT(p1);
		printf(",0,1) =");
		TulisPOINT(MirrorOf(p1,0,1));
		printf("\n");
	}
	for (i=0;i<14;i++){
		p1=MakePOINT(rand()-rand(),rand()-rand());
		printf("MirrorOf(");
		TulisPOINT(p1);
		printf(",1,1) =");
		TulisPOINT(MirrorOf(p1,1,1));
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		printf("Jarak0(");
		TulisPOINT(p1);
		printf(") = %f",Jarak0(p1));
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		p2=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		printf("Panjang(");
		TulisPOINT(p1);
		printf(",");
		TulisPOINT(p2);
		printf(") = %f",Panjang(p1,p2));
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		TulisPOINT(p1);
		printf("digeser ke Sb-X menjadi ");
		GeserKeSbX(&p1);
		TulisPOINT(p1);
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		TulisPOINT(p1);
		printf("digeser ke Sb-Y menjadi ");
		GeserKeSbY(&p1);
		TulisPOINT(p1);
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		TulisPOINT(p1);
		printf("dicerminkan dengan Sb-X menjadi ");
		Mirror(&p1,1,0);
		TulisPOINT(p1);
		printf("\n");
	}
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		TulisPOINT(p1);
		printf("dicerminkan dengan Sb-Y menjadi ");
		Mirror(&p1,0,1);
		TulisPOINT(p1);
		printf("\n");
	}
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		TulisPOINT(p1);
		printf("dicerminkan dengan (0,0) menjadi ");
		Mirror(&p1,1,1);
		TulisPOINT(p1);
		printf("\n");
	}
	printf("\n\ncek\n");
	for (i=0;i<14;i++){
		p1=MakePOINT((rand()-rand())%10,(rand()-rand())%10);
		sudut=(float) (rand()%360);
		
		TulisPOINT(p1);
		printf("diputar %0.0f derajat menjadi ",sudut);
		Putar(&p1,sudut);
		TulisPOINT(p1);
		printf("\n");
	}
	printf("M_PI=%f\n",M_PI);
	return 0;
}