Advertisement
Neon_Falcon

Untitled

May 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. using namespace std;
  2. #include <iomanip>
  3. #include <cstdio>
  4. #include <stdlib.h>
  5. #include <iostream>
  6. int const N = 2;
  7.  
  8. struct cars_info {
  9. char marka[10];
  10. char model[10];
  11. char tip_kuzova[10];
  12. float obiem_dvig;
  13. char korobka[10];
  14. char color[10];
  15. int price;
  16. };
  17.  
  18. void BubbleForPrice(int size, cars_info cars[]) {
  19. cars_info tmp;
  20. for (int i = 0; i < size; i++) {
  21. for (int j = (size - 1); j >= 0; j--) {
  22. if (cars[j].price < cars[j - 1].price) {
  23. tmp = cars[j];
  24. cars[j] = cars[j - 1];
  25. cars[j - 1] = tmp;
  26. }
  27. }
  28. }
  29. cout << "|" << setw(44) << "Avtomobiles" << setw(44) << "|\n";
  30. for (int i = 0; i < 84; i++) {
  31. cout << "-";
  32. }
  33. cout << "\n";
  34. cout << "|" << setw(12) << "Marka |" << setw(8) << "Model |" << setw(14) << "Tip kuzova |" << setw(18) << "Obiem dvigateli, l |" << setw(15)
  35. << "Transmissia |" << setw(9) << "Color |" << setw(10) << "Price |\n";
  36. for (int j = 0; j < 88; j++) {
  37. cout << "-";
  38. }
  39. cout << "\n";
  40. for (int i = 0; i < size; i++) {
  41. cout << "|" << setw(11) << cars[i].marka << "|" << setw(7) << cars[i].model << "|" << setw(13) << cars[i].tip_kuzova << "|"
  42. << setw(19) << cars[i].obiem_dvig << "|" << setw(14) << cars[i].korobka << "|" << setw(8) << cars[i].color << "|" << setw(8) << cars[i].price << "|\n";
  43. for (int j = 0; j < 88; j++) {
  44. cout << "-";
  45. }
  46. cout << "\n";
  47. }
  48. }
  49.  
  50. int ReturnIndx(char symbol) {
  51. char alphabet[23] = { 'A','B','C','D','E','F','G','H','I','K','L','M','N','O','P','Q','R','S','T','V','X','Y','Z' };
  52. for (int i = 0; i < 23; i++) {
  53. if (symbol == alphabet[i]) {
  54. return i;
  55. }
  56. }
  57. }
  58.  
  59. void BubbleForMarka(int size, cars_info cars[], int sym) {
  60. cars_info tmp;
  61. for (int i = 0; i < size; i++) {
  62. for (int j = (size - 1); j > 0; j--) {
  63. if (ReturnIndx(cars[j].marka[sym]) < ReturnIndx(cars[j - 1].marka[sym])) {
  64. tmp = cars[j];
  65. cars[j] = cars[j - 1];
  66. cars[j - 1] = tmp;
  67. }
  68. }
  69. }
  70. cout << "|" << setw(44) << "Avtomobiles" << setw(44) << "|\n";
  71. for (int i = 0; i < 88; i++) {
  72. cout << "-";
  73. }
  74. cout << "\n";
  75. cout << "|" << setw(12) << "Marka |" << setw(8) << "Model |" << setw(14) << "Tip kuzova |" << setw(18) << "Obiem dvigateli, l |" << setw(15)
  76. << "Transmissia |" << setw(9) << "Color |" << setw(10) << "Price |\n";
  77. for (int j = 0; j < 88; j++) {
  78. cout << "-";
  79. }
  80. cout << "\n";
  81. for (int i = 0; i < size; i++) {
  82. cout << "|" << setw(11) << cars[i].marka << "|" << setw(7) << cars[i].model << "|" << setw(13) << cars[i].tip_kuzova << "|"
  83. << setw(19) << cars[i].obiem_dvig << "|" << setw(14) << cars[i].korobka << "|" << setw(8) << cars[i].color << "|" << setw(8) << cars[i].price << "|\n";
  84. for (int j = 0; j < 88; j++) {
  85. cout << "-";
  86. }
  87. cout << "\n";
  88. }
  89. }
  90.  
  91. void main() {
  92. cars_info cars[N];
  93. for (int i = 0; i < N; i++) {
  94. cout << "Введите марку: ";
  95. cin >> cars[i].marka;
  96. cout << "Введите модель: ";
  97. cin >> cars[i].model;
  98. cout << "Введите тип кузова: ";
  99. cin >> cars[i].tip_kuzova;
  100. cout << "Введите объём двигателя: ";
  101. cin >> cars[i].obiem_dvig;
  102. cout << "Введите трансмиссию: ";
  103. cin >> cars[i].korobka;
  104. cout << "Введите цвет : ";
  105. cin >> cars[i].color;
  106. cout << "Введите цену: ";
  107. cin >> cars[i].price;
  108. }
  109. BubbleForPrice(N, cars);
  110. BubbleForMarka(N, cars, 0);
  111. system("pause");
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement