Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. struct Point {
  6. float x;
  7. float y;
  8. };
  9. void init_point(Point &p,float x, float y) {
  10. p.x = x;
  11. p.y = y;
  12. }
  13.  
  14. struct Path {
  15. Point *tablica;
  16. };
  17.  
  18. void print_point(Point p) {
  19. cout << "(" << p.x << ", " << p.y << ")";
  20. }
  21.  
  22. float dist(Point p1, Point p2) {
  23. return sqrt(pow((p1.x - p2.x),2)+ pow((p1.y - p2.y),2));
  24. }
  25.  
  26. float length(Point Path[],int size) {
  27. float length = 0;
  28. for(int i = 0; i < size; i++)
  29. length = length + dist(p.x[i],p.y[i+1]);
  30. return length;
  31. }
  32.  
  33. add_point(Path *path, Point p)
  34. {
  35. int x,y;
  36. std::cout<<"x:";
  37. std::cin >> x ;
  38. cout<<"y:";
  39. std::cin>> y;
  40. p.x=x;
  41. p.y=y;
  42. }
  43.  
  44. void init_path (Path* patch, int size){
  45. Point *tablica = new Point[size];
  46.  
  47. }
  48.  
  49. void del_path(*Path){
  50. delete [] *Path;
  51. }
  52.  
  53. int main() {
  54. Path path;
  55. int size;
  56. std::cout << "Podaj ilosc punktow: ";
  57. std::cin >> size;
  58. init_path(&path,size);
  59. for(int i=0;i<n;i++){
  60. add_point(patch, tablica[i].x )
  61. add_point(patch, tablica[i].y )
  62. }
  63.  
  64. for (int i = 0; i < size; ++i){
  65. print_point(Path[i]);
  66. std::cout << endl;
  67. }
  68. cout << "Calkowita dlugosc sciezki: "; cout << length(Path,size)<<endl;
  69. del_path(&Path);
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement