Created
December 10, 2019 11:21
-
-
Save uhmseohun/df0bf81e20dfb8546d4816ca5c75a6ca to your computer and use it in GitHub Desktop.
ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
/** Error Messages **/ | |
const char undefinedCmd[100] = "Undefined Command."; | |
void swap (int *a, int *b) { | |
int tmp = *a; | |
*a = *b; | |
*b = tmp; | |
} | |
char boolToSignal (bool signal) { | |
return signal ? '+' : '-'; | |
} | |
int absValue (int value) { | |
return value > 0 ? value : -value; | |
} | |
struct Point { | |
int x, y; | |
char name; | |
void initialize (int X, int Y, char NAME) { | |
x = X, y = Y, name = NAME; | |
} | |
char* repr () { | |
char* stringValue = (char *) malloc(sizeof(char) * 100); | |
sprintf(stringValue, "%c(%d, %d)", name, x, y); | |
return stringValue; | |
} | |
void output () { | |
printf("%c(%d, %d)\n", name, x, y); | |
} | |
void symmetricTrsp (char base) { | |
switch (base) { | |
case 'x': | |
y = -y; | |
break; | |
case 'y': | |
x = -x; | |
break; | |
case 'o': | |
x = -x, y = -y; | |
break; | |
case '=': | |
swap(&x, &y); | |
break; | |
default: | |
printf("%s\n", undefinedCmd); | |
} | |
} | |
void parallelTlsl (int amountX, int amountY) { | |
x += amountX, y += amountY; | |
} | |
double distanceToPoint (Point p) { | |
return sqrt(pow(x - p.x, 2) + pow(y - p.y, 2)); | |
} | |
}; | |
struct Equation { | |
int xCof, yCof, constVal; | |
bool ySgn, constSgn; // true -> +, false -> - | |
void initialize (int XCof, int YCof, int ConstVal) { | |
xCof = XCof, yCof = YCof, constVal = ConstVal; | |
ySgn = xCof > 0, constSgn = ConstVal > 0; | |
} | |
char* repr () { | |
char* stringValue = (char *) malloc(sizeof(char) * 100); | |
int absY = absValue(xCof), absConst = absValue(constVal); | |
sprintf(stringValue, "%dx %c %dy %c %d = 0", | |
xCof, boolToSignal(ySgn), absY, boolToSignal(constSgn), absConst); | |
return stringValue; | |
} | |
void output () { | |
int absY = absValue(yCof), absConst = absValue(constVal); | |
printf("%dx %c %dy %c %d = 0\n", | |
xCof, boolToSignal(ySgn), absY, boolToSignal(constSgn), absConst); | |
} | |
double distanceToPoint (Point p) { | |
double dist = absValue(p.x * xCof + p.y * yCof + constVal) / (double) sqrt(xCof * xCof + yCof * yCof); | |
return dist; | |
} | |
}; | |
int main () { | |
Point a; | |
a.initialize(3, 3, 'A'); | |
Point b; | |
b.initialize(5, 9, 'B'); | |
/* Print Distance From Point A To Point B */ | |
printf("점 %s와 점 %s 간의 거리 : %.2lf\n", a.repr(), b.repr(), a.distanceToPoint(b)); | |
Equation c; | |
c.initialize(3, 2, 5); | |
printf("점 A를 x축에 대해 대칭이동 하기 전 좌표 : %s\n", a.repr()); | |
a.symmetricTrsp('x'); | |
printf("점 A를 x축에 대해 대칭이동 한 후의 좌표 : %s\n", a.repr()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment