Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- constexpr auto Size = 3;
- using namespace std;
- struct Dot {
- double x;
- double y;
- void createDot() {
- cout << "Enter your x : ";
- cin >> x;
- cout << "Enter your y : ";
- cin >> y;
- }
- };
- void printDot(Dot* a, int n) {
- for (int i = 0; i < n; i++) {
- cout <<i <<" point with coordinates = ( " << a[i].x << " , " << a[i].y <<" ) "<< endl;
- }
- }
- double getDistance(Dot* a,int n) {
- double t = 0;
- for (int i = 0; i < n; i++) {
- t = t + abs( sqrt((pow(a[i+1].x, 2) - pow(a[i].x, 2)) + (pow(a[i+1].y, 2) - pow(a[i].y, 2))));
- }
- cout << "t" << " = " << t << endl;
- return t;
- }
- double getMaxDot(Dot* a, int n) {
- double maxX = 0, maxY = 0, d = 0;
- double First = 0;
- for (int i = 1; i < n; i++) {
- double d = abs(sqrt((pow(a[i+1].x, 2) - pow(a[i].x, 2)) + (pow(a[i+1].y, 2) - pow(a[i].y, 2))));
- if (d > First) {
- d = First;
- maxX = a[i].x ;
- maxY = a[i].y ;
- }
- }
- cout << "Max x = " << maxX << endl;
- cout << "Max y = " << maxY << endl;
- return maxX && maxY;
- }
- void insertionSort(Dot* a, int n) {
- double sortX, sortY, distance1;
- double distance;
- for (int j = 0; j < n - 1;j++) {
- for (int i = 0; i < n-j-1; i++) {
- distance = abs(sqrt((pow(a[i].x, 2) * pow(a[i].x, 2)) + (pow(a[i].y, 2) * pow(a[i].y, 2))));
- distance1 = abs(sqrt((pow(a[i + 1].x, 2) - pow(a[i].x, 2)) + (pow(a[i + 1].y, 2) - pow(a[i].y, 2))));
- if (distance < distance1) {
- sortX = a[i].x;
- a[i].x = a[i + 1].x;
- a[i + 1].x = sortX;
- sortY = a[i].y;
- a[i].y = a[i + 1].y;
- a[i + 1].y = sortY;
- }
- }
- }
- for (int i = 0; i < n; i++) {
- cout << "After sort " << i << " = ( " << a[i].x << " , " << a[i].y << " ) " << endl;
- }
- }
- int main()
- {
- Dot mas[5];
- for (int i = 0; i < Size; i++) {
- mas[i].createDot();
- }
- printDot(mas, Size);
- getDistance(mas, Size);
- getMaxDot(mas, Size);
- insertionSort(mas, Size);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement