C/C++

Такая лаба мне попалась.. Не шарю в структурах, кому не сложно помогите пожалуйста

Описати структуру STUDENT, що містить наступні поля:
номер студентського квитка;
прізвище;
ім’я;
по батькові;
номер групи;
середній бал.
2. Створити масив елементів типу STUDENT.
3. Організувати послідовний пошук за полем номер групи.
4. Організувати бінарний пошук за полем номер студентського квитка.

//
Описать структуру STUDENT, содержащую следующие поля:
номер студенческого билета;
фамилия;
имя;
отчество;
номер группы;
средний балл.
2. Создать массив элементов типа STUDENT.
3. Организовать последовательный поиск по полю номера группы.
4. Организовать бинарный поиск по полю номера студенческого билета.
DM
Dani M
95
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
struct Student {
string name;
string surname;
string patronymic;
unsigned group;
unsigned number;
double average;
friend istream& operator>>(istream& inp, Student& st) {
cout << "Фамилия: ";
getline(inp, st.surname);
cout << "Имя: ";
getline(inp, st.name);
cout << "Отчество: ";
getline(inp, st.patronymic);
cout << "Номер группы: ";
inp >> st.group;
cout << "Номер студенческого билета: ";
inp >> st.number;
cout << "Средний балл: ";
inp >> st.average;
inp.ignore(numeric_limits<streamsize>::max(), '\n');
return inp;
}
friend ostream& operator<<(ostream& out, const Student& st) {
out << st.surname << ' ' << st.name << ' ' << st.patronymic
<< "\n\tНомер студенческого билета: " << st.number
<< "\n\tНомер группы: " << st.group
<< "\n\tСредний балл: " << st.average;
return out;
}
friend bool operator<(const Student& a, const Student& b) {
return a.number < b.number;
}
};
int main() {
system("chcp 1251 > nul");
array<Student, 12> students;
for (auto& student : students) {
cin >> student;
cout.put('\n');
}
system("cls");
copy(students.begin(), students.end(), ostream_iterator<Student>(cout, "\n"));
cout.put('\n');
vector<Student> groupbox;
cout << "Номер группы для поиска: ";
unsigned group;
cin >> group;
cout.put('\n');
auto group_equal = [group](const Student& st) { return st.group == group; };
copy_if(students.begin(), students.end(), back_inserter(groupbox), group_equal);
if (groupbox.empty()) puts("Ничего не найдено!");
else copy(groupbox.begin(), groupbox.end(), ostream_iterator<Student>(cout, "\n"));
sort(students.begin(), students.end());
cout << "Номер студенческого билета для поиска: ";
Student student;
cin >> student.number;
cout.put('\n');
if (!binary_search(students.begin(), students.end(), student)) {
puts("Ничего не найдено!");
} else {
auto number_equal = [student](const Student& st) { return st.number == student.number; };
student = *find_if(students.begin(), students.end(), number_equal);
cout << student << '\n';
}
system("pause > nul");
}
Александр Головко
Александр Головко
79 416
Лучший ответ
Виктор Аникин и ведь не лень за других работу делать =) завидую вашей простоте
https://pastebin.com/cDUkpHh0
#include < iostream >
#include < vector >

using namespace std;

struct student{
string id,name,surname,patr;
int group_number;
double av_score;
};

bool comp(student &a, student &b){
return a.id < b.id;
}

vector find_group(vector &a, int &need_group){
vector b;
for(int i = 0; i < a.size(); i++)
if(a[i].group_number == need_group)
b.push_back(a[i]);
return b;
}

student find_id(vector &a, string &need_id){
int l = 0, r = a.size();
while(l <= r){
int m = (l+r)/2;
if(a[m].id > need_id)
r = m - 1;
else if(a[m].id < need_id)
l = m + 1;
else if(a[m].id == need_id)
return a[m];
}
}

signed main(){
int n; // amount of students
cin >> n;
vector a(n);
for(int i = 0; i < n; i++)
cin >> a[i].id >> a[i].name >> a[i].surname >> a[i].patr >> a[i].group_number >> a[i].av_score;
int x; // need group
cin >> x;
vector b = find_group(a,x); // vector of students with needed group number (task 3)
sort(a.begin(),a.end(),comp);
string s; // need id
cin >> s;
student c = find_id(a,s); // student with needed id (task 4)
}
Александр Головко signed main() – это круто!!!