Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <iomanip>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. struct kniga {
  10. char naz[50];
  11. char avtor[50];
  12. int god;
  13. int str;
  14. }*base;
  15.  
  16. void show(int, kniga[]);
  17. void showw(int, kniga[]);
  18. void enter(int, kniga[]);
  19. void QuickSort(int, int);
  20.  
  21. int main()
  22. {
  23. cout << "Vvedite kolvo knig: ";
  24. int n;
  25. cin >> n;
  26. base = new kniga[n];
  27.  
  28. enter(n, base);
  29.  
  30. for (int i = 0; i < n; i++) {
  31. show(i, base);
  32. }
  33.  
  34.  
  35. showw(n, base);
  36. QuickSort(0, n - 1);
  37. for (int i = 0; i < n; ++i) {
  38. cout << "======================================" << endl;
  39. cout << setw(12) << " Nazvanie |" << setw(12) << " Kolvo str " << endl;
  40. cout << "======================================" << endl;
  41. cout << setw(12) << base[i].naz << "|" << setw(12) << base[i].str<<endl;
  42. }
  43. system("pause");
  44. return 0;
  45. }
  46.  
  47.  
  48. void show(int i, kniga base[]) {
  49. cout << "=============================================" << endl;
  50. cout << setw(12) << " Nazvanie |" << setw(12) << " Avtor |" << " God |" << setw(12) << " Kolvo str " << endl;
  51. cout << "=============================================" << endl;
  52. cout << setw(12) << base[i].naz << "|" << setw(12) << base[i].avtor << "|" << setw(12) << base[i].god << "|" << setw(12) << base[i].str << endl;
  53.  
  54. }
  55.  
  56.  
  57. void enter(int n, kniga base[]) {
  58. for (int i = 0; i < n; i++) {
  59. cout << "Vvedite nazvanie " << i + 1 << ": "; cin >> base[i].naz;
  60. cout << "Vvedite avtora " << i + 1 << ": "; cin >> base[i].avtor;
  61. cout << "Vvedite god " << i + 1 << ": "; cin >> base[i].god;
  62. cout << "Vvedite kolvo stranits " << i + 1 << ": "; cin >> base[i].str;
  63. cout << endl;
  64. }
  65. }
  66.  
  67.  
  68.  
  69. void QuickSort(int Left, int Right) {
  70. int i,j;
  71. kniga SR = base[(Left + Right) / 2], buf;
  72. i = Left;
  73. j = Right;
  74. do {
  75. while ((base[i].str < SR.str) && (i < Right)) {
  76. i++;
  77. }
  78. while ((base[j].str > SR.str) && (j > Left)) {
  79. j--;
  80. }
  81. if (i <= j) {
  82. buf = base[i];
  83. base[i] = base[j];
  84. base[j] = buf;
  85. i++;
  86. j--;
  87. }
  88. } while (i <= j);
  89. if (i < Right) {
  90. QuickSort(i, Right);
  91. }
  92. if (j > Left) {
  93. QuickSort(Left, j);
  94. }
  95. }
  96.  
  97. void showw(int n, kniga base[]) {
  98. for (int i = 0; i < n; i++) {
  99. if (base[i].god < 1990) {
  100. cout << setw(12) << " Nazvanie " << "|" << setw(12) << base[i].naz << endl<<endl;
  101. }
  102.  
  103.  
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement