-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathes3.cpp
More file actions
35 lines (30 loc) · 1.04 KB
/
Copy pathes3.cpp
File metadata and controls
35 lines (30 loc) · 1.04 KB
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
#include <iostream>
#include <string>
using namespace std;
// Definizione della struct Libro
struct Libro {
string titolo;
string autore;
int annoPubblicazione;
};
int main() {
Libro libri[5]; // Array di 5 libri
// Inserimento dei dettagli dei libri
for (int i = 0; i < 5; i++) {
cout << "Inserisci il titolo del libro " << i + 1 << ": ";
cin.ignore(); // Ignora il carattere di newline rimasto nel buffer
getline(cin, libri[i].titolo);
cout << "Inserisci l'autore del libro " << i + 1 << ": ";
getline(cin, libri[i].autore);
cout << "Inserisci l'anno di pubblicazione del libro " << i + 1 << ": ";
cin >> libri[i].annoPubblicazione;
}
// Stampa i titoli dei libri pubblicati dopo il 2000
cout << "\nLibri pubblicati dopo il 2000:\n";
for (int i = 0; i < 5; i++) {
if (libri[i].annoPubblicazione > 2000) {
cout << libri[i].titolo << " di " << libri[i].autore << " (" << libri[i].annoPubblicazione << ")" << endl;
}
}
return 0;
}