Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <fstream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8. struct samochod
  9. {
  10.     char marka[20];
  11.     int cena;
  12.     char kolor[20];
  13. };
  14.  
  15. void wprowadzenieDanych(int n, samochod t[])
  16. {
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         for (int i = 0; i<n; i++)
  20.         {
  21.             cout << "Podaj marke: "; cin >> t[i].marka;
  22.             cout << "Podaj kolor: "; cin >> t[i].kolor;
  23.             cout << "Podaj cene: "; cin >> t[i].cena;
  24.         }
  25.     }
  26. }
  27.  
  28. bool kolor_sorter(samochod const& l, samochod const& r) {
  29.     if (l.kolor != r.kolor)
  30.         return l.kolor < r.kolor;
  31.     else
  32.         return false;
  33. }
  34.  
  35. bool marka_sorter(samochod const& l, samochod const& r) {
  36.     if (l.marka != r.marka)
  37.         return l.marka < r.marka;
  38.     else
  39.         return false;
  40. }
  41.  
  42.  
  43. void sortuj(samochod t[], int n)
  44. {
  45.     cout << "Sortowanie po" << endl;
  46.     cout << "[0] - kolorze" << endl;
  47.     cout << "[1] - marce" << endl;
  48.     int w;
  49.     cin >> w;
  50.     switch (w)
  51.     {
  52.     case 0:
  53.         sort(t, t + n, &kolor_sorter);
  54.         break;
  55.     case 1:
  56.         sort(t, t + n, &marka_sorter);
  57.         break;
  58.  
  59.     default:
  60.         cout << "Zly wybor" << endl;
  61.     }
  62. }
  63.  
  64. void zlicz(samochod t[], int n)
  65. {
  66.     int * zliczenia;
  67.     zliczenia = new int[n];
  68. }
  69.  
  70. int main()
  71. {
  72.     samochod *tab;
  73.     int n;
  74.     cout << "Podaj ilosc samochodow..."; cin >> n;
  75.     tab = new samochod[n];
  76.     wprowadzenieDanych(n, tab);
  77.     sortuj(tab, n);
  78.     zlicz(tab, n);
  79.     getch();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement