아하
검색 이미지
생활꿀팁 이미지
생활꿀팁생활
생활꿀팁 이미지
생활꿀팁생활
특출난하마152
특출난하마15221.05.20

c언어 과제인데 모르겠어요. 도와주세요

아래 포인터 배우는 중인데 두번째 함수랑 마지막 함수를 잘 모르겠어요... 두번째는 만들었는데 포인터 쓰라고 해서 오류뜨고 마지막은 모르겠어요... 설명해주세요 첫번째가 문제고 두번째가 제가 적은거에요

Q1. 2차원 평면 상의 좌표를 다루는 함수들을 정의하고, 다음의 프로그램을 완성하시오.

‣ display_point() 함수 - x축과 y축 좌표값을 전달받아 좌표 형태로 출력하는 함수(실행 예 참고)

‣ compute_distance() 함수 - 두 점의 좌표를 전달받아 두 점 사이의 거리를 계산해서 반환해주는 함수(출력문 없음) - 두 점사이의 거리 =[대충 (x2-x1)^2 ..... 그거요..]

move_point() 함수 - x축과 y축 좌표값, 그리고 이동량을 전달받아 x축과 y축 좌표값을 각각 이동량만큼 변경하는 함수

#include

#include

[빈칸]// 각 함수의 선언

int main() {

int x1, x2, y1, y2, move;

double distance; printf("p1 좌표 입력(x축, y축 좌표값 입력): "); scanf("%d %d", &x1, &y1);

printf("p2 좌표 입력(x축, y축 좌표값 입력): "); scanf("%d %d", &x2, &y2); printf("p1 = "); display_point(x1, y1);

printf("p2 = "); display_point(x2, y2);

[빈칸] // compute_distance()를 호출하여 두 점 사이의 거리를 계산한 후 출력(실행 예 참고)

printf("좌표 이동량 입력: ");

scanf("%d", &move);

[빈칸]//move_point()를 호출하여 move만큼 p2에 해당하는 좌표값 변경

printf("p2을 x축과 y축으로 각각 %d 만큼 이동 = ", move);

display_point(x2, y2); return 0;

}

[빈칸]// 각 함수의 정의

#include <stdio.h>

#include <math.h>

#pragma warning(disable:6031)

#pragma warning(disable:4996)

void display_point(int x, int y);

double compute_distance(int x1, int y1, int x2, int y2);

void move_point(int x, int y, int move);

int main()

{

int x1, x2, y1, y2, move;

double distance;

printf("");

scanf("%d %d", &x1, &y1);

printf("");

scanf("%d %d", &x2, &y2);

printf("p1 = ");

display_point(x1, y1);

printf("p1 = ");

display_point(x2, y2);

printf("두 점 사이의 거리 = %f\n", compute_distance(x1, y1, x2, y2));

printf("좌표 이동량 입력: ");

scanf("%d", &move);

printf("", move);

display_point(x2, y2);

return 0;

}

void display_point(int x, int y)

{

printf("(x, y)");

return;

}

double compute_distance(int x1, int y1, int x2, int y2)

{

double dist;

dist = sqrt((x2 - x1)(x2 - x1) + (y2 - y1)(y2 - y1));

return dist;

}

void move_point(int x, int y, int move)

{

}

55글자 더 채워주세요.
답변의 개수1개의 답변이 있어요!
  • 참고 : https://prosto.tistory.com/253

    [수정 소스]

    #include <stdio.h>

    #include <math.h>

    #include <stdlib.h> // system 함수 사용을 위해

    #pragma warning(disable:6031)

    #pragma warning(disable:4996)

    void display_point(int x, int y);

    double compute_distance(int x1, int y1, int x2, int y2);

    void move_point(int x, int y, int move);

    int main(){

    int x1, x2, y1, y2, move;

    double distance;

    printf("p1 좌표 입력(x축, y축 좌표값 입력): ");

    scanf("%d %d", &x1, &y1);

    printf("p2 좌표 입력(x축, y축 좌표값 입력): ");

    scanf("%d %d", &x2, &y2);

    printf("p1 = ");

    display_point(x1, y1);

    printf("p2 = ");

    display_point(x2, y2);

    distance = compute_distance(x1, y1, x2, y2);

    printf("두 점 사이의 거리 = %f\n", distance);

    printf("좌표 이동량 입력: ");

    scanf("%d", &move);

    move_point(&x2, &y2, move);

    scanf("p2을 x축과 y축으로 각각 %d 만큼 이동 = ", &move);

    display_point(x2, y2);

    system("pause");

    return 0;

    }

    void display_point(int x, int y){

    printf("(%d, %d)\n", x, y);

    }

    double compute_distance(int x1, int y1, int x2, int y2){

    // compute_distance() 함수 - 두 점의 좌표를 전달받아 두 점 사이의 거리를 계산해서 반환해주는 함수(출력문 없음)

    // - 두 점사이의 거리 = 루트[대충(x2 - x1) ^ 2 .....그거요..]

    double dist;

    dist = sqrt((x2 - x1)(x2 - x1) + (y2 - y1)(y2 - y1));

    return dist;

    }

    void move_point(int x, int y, int move){

    //move_point() 함수 - x축과 y축 좌표값, 그리고 이동량을 전달받아 x축과 y축 좌표값을 각각 이동량만큼 변경하는 함수

    *x += move;

    *y += move;

    }

    [실행결과 캡쳐]