Advertisement
NickAndNick

Массив структур.

Jan 11th, 2013
1,988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <string>
  5. #define BUF 40
  6. using namespace std;
  7.  
  8. struct people {    
  9.     wchar_t fio[BUF];
  10.     int number_grup;
  11.     double progress_bal;
  12.     friend bool operator<(const people & _a, const people & _b) { return _a.fio < _b.fio; };
  13. };
  14.  
  15. void in_students (people *, size_t);
  16. void out_students (people *, size_t);
  17. void ru();
  18.  
  19. int main () {
  20.     ru();
  21.     const size_t size = 2;
  22.     people students[size];
  23.  
  24.     wcout << setw(30) << L"Ввод студентов\n\n";
  25.     in_students(students, size);
  26.     cout << setw(59) << setfill('_') << ' ' << endl << endl;
  27.  
  28.     sort(students, students + size);
  29.     out_students(students, size);
  30.  
  31.     cin.get(); cin.get();
  32.     return 0;
  33. }
  34.  
  35. void in_students(people * _st , size_t _size) {
  36.     if (_st)
  37.         for (size_t n = 0; n < _size; n++) {
  38.             wcout << L"\tСтудент " << n + 1 << ':';
  39.             fflush(stdin);
  40.             wcout << L"\n Ф.И.О.       -> "; wcin.getline(_st[n].fio, BUF);
  41.             wcout << L" Номер группы -> ";   cin>>_st[n].number_grup;
  42.             wcout << L" Успеваемость -> ";   cin>>_st[n].progress_bal;
  43.             cout << endl;
  44.         }
  45. }
  46.  
  47. void out_students(people * _st , size_t _size) {
  48.     if (_st)
  49.         for (size_t n = 0; n < _size; n++) {
  50.             wcout << L"\tСтудент " << n + 1 << ':';
  51.             wcout << L"\n Ф.И.О.:       "; wcout << _st[n].fio;
  52.             wcout << L"\n Номер группы: "; cout << _st[n].number_grup;
  53.             wcout << L"\n Успеваемость: "; cout << _st[n].progress_bal;
  54.             cout << endl;
  55.         }
  56. }
  57.  
  58. void ru() {
  59.     wcout.imbue(locale("rus_rus.866"));
  60.     wcin.imbue(locale("rus_rus.866"));
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement