Advertisement
Guest User

3213

a guest
May 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. using namespace std;
  5. struct najdaljsereke
  6. {
  7. char ime[31];
  8. char celina[31];
  9. int dolzina;
  10. };
  11. void vnos (struct najdaljsereke x[],int n);
  12. void izpis (struct najdaljsereke x[],int n);
  13. void sortiranje (struct najdaljsereke x[],int n);
  14. void izpis2 (struct najdaljsereke x[],int n);
  15. int main()
  16. {
  17. struct najdaljsereke x[3];
  18. vnos (x,3);
  19. sortiranje (x,3);
  20. izpis (x,3);
  21. //izpis2 (x,3);
  22. return 0;
  23. }
  24.  
  25. void vnos (struct najdaljsereke x[],int n)
  26. {
  27. for (int i=0;i<n;i++)
  28. {
  29. fflush (stdin);
  30. cout <<"Vnesi ime reke :";
  31. gets (x[i].ime);
  32. cout <<"Vnesi celino reke :";
  33. gets (x[i].celina);
  34. cout <<"Vnesi dolzino reke :";
  35. cin>>x[i].dolzina;
  36. if(x[i].dolzina<1000)
  37. {
  38. cout<<"Saj to je potocek";
  39. i--;
  40. }
  41. }
  42. }
  43.  
  44.  
  45. void sortiranje (struct najdaljsereke x[],int n)
  46. {
  47. char pom[31];
  48. int poms;
  49. for(int i=0;i<n;i++)
  50. for (int j=n-1;j>i;j--)
  51. if(strcmp(x[j].ime,x[j-1].ime)>0)
  52. {
  53. strcpy (pom,x[j-1].ime);
  54. strcpy (x[j-1].ime,x[j].ime);
  55. strcpy (x[j].ime,pom);
  56.  
  57. strcpy (pom,x[j-1].celina);
  58. strcpy (x[j-1].celina,x[j].celina);
  59. strcpy (x[j].celina,pom);
  60.  
  61. poms=x[j-1].dolzina;
  62. x[j-1].dolzina=x[j].dolzina;
  63. x[j].dolzina=poms;
  64. }
  65. }
  66.  
  67. void izpis (struct najdaljsereke x[],int n)
  68. {
  69. for(int i=0;i<n;i++)
  70. {
  71. puts (x[i].ime);
  72. puts (x[i].celina);
  73. cout <<x[i].dolzina;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement