Advertisement
Qwarri

Ex#Number#1

Oct 22nd, 2018
95
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 <string>
  3. #include <memory>
  4. #include <iomanip>
  5. #include <ctime>
  6. using namespace std;
  7.  
  8. struct StudentsList
  9. {
  10.     StudentsList(int count) : _count(count)
  11.     {
  12.         cout << "Create " << count << " students\n";
  13.     }
  14.  
  15.     const size_t _count;
  16.  
  17.     string *studentFirstName = new string[_count];
  18.     string *studentLastName  = new string[_count];
  19.     double *result_of_exams  = new double[_count];
  20. };
  21.  
  22.  
  23. string generate_rand_name(int length)
  24. {
  25.     string _res;
  26.  
  27.     for (size_t charact = 0; charact < length; charact++)
  28.     {
  29.         _res += (char)(97 + static_cast <int> (rand()) / (static_cast <int> (RAND_MAX / (122 - 97))));
  30.     }
  31.  
  32.     return _res;
  33. }
  34.  
  35.  
  36. bool create_new_table_of_students(StudentsList& stud)
  37. {
  38.     for (size_t i = 0; i < stud._count; i++)
  39.     {
  40.         stud.studentFirstName[i] = generate_rand_name(5);
  41.         stud.studentLastName[i]  = generate_rand_name(5);
  42.         stud.result_of_exams[i] =
  43.             2.0f + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (5.0f - 2.0f)));
  44.     }
  45.    
  46.     return EXIT_SUCCESS;
  47. }
  48.  
  49.  
  50. void main()
  51. {
  52.     setlocale(LC_ALL, "rus");
  53.  
  54.     srand(static_cast <unsigned> (time(NULL)));
  55.    
  56.     std::unique_ptr <StudentsList> students(new StudentsList(10));
  57.  
  58.     create_new_table_of_students(*students);
  59.  
  60.     cout << "\nТаблица студентов:\n";
  61.     for (size_t i = 0; i < 10; i++)
  62.     {
  63.         cout << setw(5) <<
  64.             students->studentFirstName[i] << "  " <<
  65.             students->studentLastName[i]  << "  " <<
  66.             students->result_of_exams[i]  << endl;
  67.     }
  68.  
  69.     cout << "\nПрошли в финал:\n";
  70.     for (size_t i = 0; i < 10; i++)
  71.     {
  72.         if (students->result_of_exams[i] >= 3.0f)
  73.         cout << setw(5) <<
  74.             students->studentFirstName[i] << "  " <<
  75.             students->studentLastName[i] << "  " <<
  76.             students->result_of_exams[i] << endl;
  77.     }
  78.  
  79.     system("pause");
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement