#include<iostream>
using namespace std;
// Struct student contain roll number, name, year of joining
struct student {
    int roll_number{}, year_of_joining{};
    string name;
};
// Function to print the names of all students who joined in a given year
void print_by_year(student students[], int n, int year) {
    cout << "Student(s) joined in " << year << " year:\n";
    for (int i = 0; i < n; i++)
        if (students[i].year_of_joining == year)
            cout << students[i].roll_number << " " << students[i].name << "\n";
    cout << endl;
}
// Function to print the details of student of given roll number
void print_by_roll_number(student students[], int n, int roll) {
    cout << "Student(s) with " << roll << " roll number:\n";
    for (int i = 0; i < n; i++)
        if (students[i].roll_number == roll) {
            cout << students[i].name << " " << students[i].year_of_joining << endl;
        }
}
int main() {
    student students[5];
    students[0].name = "Jacob Williams";
    students[0].roll_number = 1;
    students[0].year_of_joining = 2018;
    students[1].name = "Michael Davis";
    students[1].roll_number = 2;
    students[1].year_of_joining = 2018;
    students[2].name = "Andrew Robinson";
    students[2].roll_number = 3;
    students[2].year_of_joining = 2019;
    students[3].name = "Emma Davis";
    students[3].roll_number = 4;
    students[3].year_of_joining = 2020;
    students[4].name = "Ethan Wright";
    students[4].roll_number = 5;
    students[4].year_of_joining = 2018;
    print_by_year(students, 5, 2018);
    print_by_roll_number(students, 5, 4);
}Output:
Comments
thank you so much very helpful :D