Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iomanip>
- #include <cstdio>
- #include <stdlib.h>
- #include <iostream>
- int const N = 2;
- struct cars_info {
- char marka[10];
- char model[10];
- char tip_kuzova[10];
- float obiem_dvig;
- char korobka[10];
- char color[10];
- int price;
- };
- void BubbleForPrice(int size, cars_info cars[]) {
- cars_info tmp;
- for (int i = 0; i < size; i++) {
- for (int j = (size - 1); j >= 0; j--) {
- if (cars[j].price < cars[j - 1].price) {
- tmp = cars[j];
- cars[j] = cars[j - 1];
- cars[j - 1] = tmp;
- }
- }
- }
- cout << "|" << setw(44) << "Avtomobiles" << setw(44) << "|\n";
- for (int i = 0; i < 84; i++) {
- cout << "-";
- }
- cout << "\n";
- cout << "|" << setw(12) << "Marka |" << setw(8) << "Model |" << setw(14) << "Tip kuzova |" << setw(18) << "Obiem dvigateli, l |" << setw(15)
- << "Transmissia |" << setw(9) << "Color |" << setw(10) << "Price |\n";
- for (int j = 0; j < 88; j++) {
- cout << "-";
- }
- cout << "\n";
- for (int i = 0; i < size; i++) {
- cout << "|" << setw(11) << cars[i].marka << "|" << setw(7) << cars[i].model << "|" << setw(13) << cars[i].tip_kuzova << "|"
- << setw(19) << cars[i].obiem_dvig << "|" << setw(14) << cars[i].korobka << "|" << setw(8) << cars[i].color << "|" << setw(8) << cars[i].price << "|\n";
- for (int j = 0; j < 88; j++) {
- cout << "-";
- }
- cout << "\n";
- }
- }
- int ReturnIndx(char symbol) {
- 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' };
- for (int i = 0; i < 23; i++) {
- if (symbol == alphabet[i]) {
- return i;
- }
- }
- }
- void BubbleForMarka(int size, cars_info cars[], int sym) {
- cars_info tmp;
- for (int i = 0; i < size; i++) {
- for (int j = (size - 1); j > 0; j--) {
- if (ReturnIndx(cars[j].marka[sym]) < ReturnIndx(cars[j - 1].marka[sym])) {
- tmp = cars[j];
- cars[j] = cars[j - 1];
- cars[j - 1] = tmp;
- }
- }
- }
- cout << "|" << setw(44) << "Avtomobiles" << setw(44) << "|\n";
- for (int i = 0; i < 88; i++) {
- cout << "-";
- }
- cout << "\n";
- cout << "|" << setw(12) << "Marka |" << setw(8) << "Model |" << setw(14) << "Tip kuzova |" << setw(18) << "Obiem dvigateli, l |" << setw(15)
- << "Transmissia |" << setw(9) << "Color |" << setw(10) << "Price |\n";
- for (int j = 0; j < 88; j++) {
- cout << "-";
- }
- cout << "\n";
- for (int i = 0; i < size; i++) {
- cout << "|" << setw(11) << cars[i].marka << "|" << setw(7) << cars[i].model << "|" << setw(13) << cars[i].tip_kuzova << "|"
- << setw(19) << cars[i].obiem_dvig << "|" << setw(14) << cars[i].korobka << "|" << setw(8) << cars[i].color << "|" << setw(8) << cars[i].price << "|\n";
- for (int j = 0; j < 88; j++) {
- cout << "-";
- }
- cout << "\n";
- }
- }
- void main() {
- cars_info cars[N];
- for (int i = 0; i < N; i++) {
- cout << "Введите марку: ";
- cin >> cars[i].marka;
- cout << "Введите модель: ";
- cin >> cars[i].model;
- cout << "Введите тип кузова: ";
- cin >> cars[i].tip_kuzova;
- cout << "Введите объём двигателя: ";
- cin >> cars[i].obiem_dvig;
- cout << "Введите трансмиссию: ";
- cin >> cars[i].korobka;
- cout << "Введите цвет : ";
- cin >> cars[i].color;
- cout << "Введите цену: ";
- cin >> cars[i].price;
- }
- BubbleForPrice(N, cars);
- BubbleForMarka(N, cars, 0);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement