Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <memory>
- #include <iomanip>
- #include <ctime>
- using namespace std;
- struct StudentsList
- {
- StudentsList(int count) : _count(count)
- {
- cout << "Create " << count << " students\n";
- }
- const size_t _count;
- string *studentFirstName = new string[_count];
- string *studentLastName = new string[_count];
- double *result_of_exams = new double[_count];
- };
- string generate_rand_name(int length)
- {
- string _res;
- for (size_t charact = 0; charact < length; charact++)
- {
- _res += (char)(97 + static_cast <int> (rand()) / (static_cast <int> (RAND_MAX / (122 - 97))));
- }
- return _res;
- }
- bool create_new_table_of_students(StudentsList& stud)
- {
- for (size_t i = 0; i < stud._count; i++)
- {
- stud.studentFirstName[i] = generate_rand_name(5);
- stud.studentLastName[i] = generate_rand_name(5);
- stud.result_of_exams[i] =
- 2.0f + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (5.0f - 2.0f)));
- }
- return EXIT_SUCCESS;
- }
- void main()
- {
- setlocale(LC_ALL, "rus");
- srand(static_cast <unsigned> (time(NULL)));
- std::unique_ptr <StudentsList> students(new StudentsList(10));
- create_new_table_of_students(*students);
- cout << "\nТаблица студентов:\n";
- for (size_t i = 0; i < 10; i++)
- {
- cout << setw(5) <<
- students->studentFirstName[i] << " " <<
- students->studentLastName[i] << " " <<
- students->result_of_exams[i] << endl;
- }
- cout << "\nПрошли в финал:\n";
- for (size_t i = 0; i < 10; i++)
- {
- if (students->result_of_exams[i] >= 3.0f)
- cout << setw(5) <<
- students->studentFirstName[i] << " " <<
- students->studentLastName[i] << " " <<
- students->result_of_exams[i] << endl;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement