include iostream include algorithm using namespace std struct book cha

 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
47
48
49
50
#include <iostream>
#include <algorithm>
using namespace std;
struct book {
char name[100];
int year;
} books[100];
int main() {
int dimension;
printf("Enter the dimension of books array: ");
cin >> dimension;
string query;
for (int i = 0; i < dimension; ++i) {
cout << "Enter name of the book" << endl;
cin >> books[i].name;
cout << "Enter year of the book" << endl;
cin >> books[i].year;
}
cout << "Entered array:" << endl;
for (int i = 0; i < dimension; ++i) {
cout << i << " - " << books[i].name << " - " << books[i].year << endl;
}
for (int i = dimension; i >= 0; --i) {
books[i + 1] = books[i];
}
cout << "Enter name of the book" << endl;
cin >> books[0].name;
cout << "Enter year of the book" << endl;
cin >> books[0].year;
cout << "Entered array:" << endl;
for (int i = 0; i < dimension + 1; ++i) {
cout << i << " - " << books[i].name << " - " << books[i].year << endl;
}
}