include iostream using namespace std struct books char name 40 int yea

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
struct books {
char name[40];
int year;
};
int main() {
size_t dimension;
printf("Enter the dimension of books array: ");
cin >> dimension;
struct books book[dimension];
int query;
for (int i = 0; i < dimension; ++i) {
cout << "Enter name" << endl;
cin >> book[i].name;
cout << "Enter year" << endl;
cin >> book[i].year;
}
cout << "Entered array:" << endl;
for (int i = 0; i < dimension; ++i) {
cout << i << " - " << book[i].name << " - " << book[i].year << endl;
}
cout << "Enter the year of the book you want to search." << endl;
cin >> query;
for (int i = 0; i < dimension; ++i) {
if (book[i].year == query) {
cout << "Book named " << query << " found." << endl;
cout << "Name: " << book[i].name << endl << "Year: " << book[i].year << endl;
break;
}
}
return 0;
}