Commit add7df07 authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'exe_48' into 'master'

exercise_06_48, version1

See merge request bpcarm/trainings2017!1325
parents 9d8894ca 674c1e6e
progname = exercise_06_48
CC = g++
CFLAGS = -Wall -Wextra -Werror -g3
$(progname): $(progname).o | .gitignore
$(CC) $(CFLAGS) $^ -o $@
%.ii: %.cpp
$(CC) -E $(CFLAGS) $< -o $@
%.s: %.ii
$(CC) -S $(CFLAGS) $< -o $@
%.o: %.s
$(CC) -c $(CFLAGS) $< -o $@
.gitignore:
echo $(progname) > $@
clean:
rm -f *.ii *.s *.o *.out $(progname) .gitignore
test: $(progname)
./$(progname) < $@.in > $@.out
diff $@.out $@.expected && echo PASSED || echo FAILED
.PRECIOUS: $(progname).ii $(progname).s
.SECONDARY: $(progname).ii $(progname).s
#include <iostream>
#include <cmath>
double
distance(const double x1, const double y1, const double x2, const double y2);
int
main()
{
double x1;
std::cout << "Insert first point of x coordinate. ";
std::cin >> x1;
double y1;
std::cout << "Insert first point of y coordinate. ";
std::cin >> y1;
double x2;
std::cout << "Insert second point of x coordinate. ";
std::cin >> x2;
double y2;
std::cout << "Insert second point of y coordinate. ";
std::cin >> y2;
std::cout << "The distance between to points is "
<< distance(x1, y1, x2, y2) << std::endl;
return 0;
}
double
distance(const double x1, const double y1, const double x2, const double y2)
{
const double xCoordinatesSub = x2 - x1;
const double yCoordinatesSub = y2 - y1;
const double distance = std::sqrt((xCoordinatesSub * xCoordinatesSub) + (yCoordinatesSub * yCoordinatesSub));
return distance;
}
Insert first point of x coordinate. Insert first point of y coordinate. Insert second point of x coordinate. Insert second point of y coordinate. The distance between to points is 15.6205
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment