Results 1 to 5 of 5
Thread: c++
Hybrid View
-
16th September 2018 10:44 #1Registered User
Join Date: Jan:2018
Location:
Posts: 9
c++
, , ,
, , . . n , . .
#include "pch.h"
#include <iostream>
#include <math.h>
using namespace std;
class Point
{
private:
double x, y;
public:
Point();
void Output();
void Input();
double getx();
double gety();
double Leught(Point a, Point b);
friend void sort(int,int);
};
Point::Point()
{
x = y = 0;
}
double Point::getx()
{
return x;
}
double Point::gety()
{
return y;
}
void Point::Input()
{
cout << "Kordinati za x = ";
cin >> x;
cout << "Kordinati za y = ";
cin >> y;
}
void Point::Output()
{
cout << "(" << x << "," << y << ")";
}
double Point::Leught(Point a ,Point b)
{
double d;
d = sqrt((a.getx() - b.getx())*(a.getx() - b.getx()) + (a.gety() - b.gety())*(a.gety() - b.gety()));
return d;
}
void sort(int a[],int n)
{
int gap,i,j,temp;
for(gap=n/2;gap>0;gap/=2)
{
for(i=gap;i<n;i+=1)
{
temp=a[i];
for(j=i;j>=gap&&a[j-gap]>temp;j-=gap)
a[j]=a[j-gap];
a[j]=temp;
}
}
}
int main()
{
int n;
cout << "Broi tochki";
cin >> n;
Point *Line = new Point[n];
for (int i = 0; i < n; i++)
{
Line[i].Input();
}
}
-
26th September 2018 12:50 #2
, , , , . - (?) - . , .
: . , . ( ) ? - ? ? , ? , ?
: , , . . , .
. , , - .Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19
-
15th October 2018 11:22 #3Registered User
Join Date: Jan:2018
Location:
Posts: 9
E , ..
#include <iostream>
#include <math.h>
#include <windows.h>
using namespace std;
class Line
{
private:
int id ;
double xa, ya, xb, yb;
public:
double length;
Line();
void Input(int tid);
void Output();
void getLength();
friend void ShellSort();
};
Line::Line()
{
xa = xb = ya = yb =id= length = 0;
}
void Line::Input(int tid)
{
id = tid;
cout << "---Line id: " << tid << endl;
cout << "Enter X coordinate for point A" << endl;
cin >> xa;
cout << "Enter Y coordinate for point A" << endl;
cin >> ya;
cout << "Enter X coordinate for point B" << endl;
cin >> xb;
cout << "Enter Y coordinate for point B" << endl;
cin >> yb;
}
void Line::Output()
{
cout << "Line : "<<id << " xA : " << xa << " yA: " << ya << " xB : " << xb << " yB: " << yb << " Length : " << length << endl;
}
void Line::getLength()
{
length = sqrt((xa - xb)*(xa - xb) + (ya - yb)*(ya - yb));
}
void ShellSort(int n, Line Array[])
{
for (int gap = n / 2; gap > 0; gap /= 2)
{
for (int i = gap; i < n; i += 1)
{
Line temp = Array[i];
int j;
for (j = i; j >= gap && Array[j - gap].length > temp.length; j -= gap)
Array[j] = Array[j - gap];
Array[j] = temp;
}
}
}
int main()
{
int nLines;
cout << "Broi tochki ";
cin >> nLines;
Line* Array = new Line[nLines];
for (int i = 0; i < nLines; i++)
{
Array[i].Input(i);
Array[i].getLength();
}
for (int i = 0; i < nLines; i++)
{
Array[i].Output();
}
Line* unsortedLines = new Line[nLines];
for (int i = 0; i < nLines; i++)
{
unsortedLines[i] = Array[i];
}
ShellSort(nLines,Array);
for ( int i =0; i < nLines; i++ )
{
cout << endl;
cout << Array[i].length<< " || " << unsortedLines[i].length;
cout << endl;
}
delete[]Array;
delete[]unsortedLines;
return 0;
}
-
24th October 2018 00:29 #4Banned
Join Date: Apr:2018
Location: .
Posts: 2,742
- , .
- vector<Line> new[] delete[].
id , .
getLength() , . , , getLength() - . , , - .
(unsortedLines).
-
24th October 2018 18:07 #5Registered User
Join Date: Jan:2018
Location:
Posts: 9
. vctor . delete
, ,
.
#include <iostream>
#include <math.h>
#include <windows.h>
using namespace std;
class Line
{
private:
double xa,ya,xb,yb;
public:
Line();
void input();
void output();
double leanght();
friend void ShellSort();
};
Line::Line()
{
xa=ya=xb=yb=0;
}
void Line::input()
{
cout<<"enter X cordinates of for point A"<<endl;
cin>>xa;
cout<<"enter Y cordinates of for point A"<<endl;
cin>>ya;
cout<<"enter X cordinates of for point B"<<endl;
cin>>xb;
cout<<"enter Y cordinates of for point B"<<endl;
cin>>yb;
}
double Line::leanght()
{
return sqrt(((xa - xb)*(xa - xb) + (ya - yb)*(ya - yb))) ;
}
void Line:
utput()
{
cout<<"xa: "<<xa<<"xb: " <<xb<<"ya: "<<ya<<"yb: "<<yb<<" length : "<<leanght()<<endl;
}
void ShellSort(int nLines, Line Array[])
{
int gap =nLines/2;
while(gap>0)
{
int j=0;
for(int i=gap; i<nLines; i++)
{
Line temp=Array[i];
for(j=i; j>=gap&&Array[j-gap].leanght()>temp.leanght(); j-=gap)
{
Array[j]=Array[j-gap];
}
Array[j]=temp;
}
gap=gap/2;
}
}
int main()
{
int nLines;
cout<<"Broi to4ki: ";
cin>>nLines;
Line * Array =new Line[nLines];
for(int i =0; i<nLines; i++)
{
Array[i].input();
Array[i].leanght();
}
cout<<endl;
for(int i=0; i<nLines; i++)
{
Array[i].output();
}
Line *UnsordetLine =new Line[nLines];
for(int i =0; i<nLines; i++)
{
UnsordetLine[i]=Array[i];
}
ShellSort(nLines,Array);
cout<<"[Arrey before sorting] "<<endl;
for(int i=0; i<nLines; i++)
{
cout<<" "<<UnsordetLine[i].leanght();
}
cout<<endl;
cout<< " [Arrey after sorting]"<<endl;
for(int i=0; i<nLines; i++)
{
cout<<" "<<Array[i].leanght();
}
delete[]Array;
delete[]UnsordetLine;
return 0;
}Last edited by aremlakve; 24th October 2018 at 18:08.




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in