Hello Guys. I did something but it's not correct. Can you adjust? Here is my question : Create array with 10 books(title, author, price, year of publication). Create functions for: entering data, printing data and output the book with min price and output the book with publication year after 1980.
#include<iostream>
#include<string>
usingnamespace std;
struct book {
string title;
string author;
double price;
int year;
};
void create_data(book something[]);
void findabook(book something[]);
void findminprice(book something[]);
int main() {
book something[10];
create_data(something);
cout << endl;
findabook(something);
findminprice(something);
}
void create_data(book something[])
{
for (int i = 0; i < 10; i++)
{
cout << endl << "Please enter Book Title: ";
getline(cin, something[i].title);
cout << endl << "Please enter Book Author: ";
getline(cin, something[i].author);
cout << endl << "Please enter Book Price: ";
cin >> something[i].price;
cout << endl << "Please enter Book Year of Publication: ";
cin >> something[i].year;
cin.ignore(1000, '\n');
}
}
void findabook(book something[])
{
for (int i = 0; i < 10; i++)
if (something[i].year > 1980)
{
cout << endl << "Author of the book with publication year after 1980 is:" << something[i].author;
cout << endl << "Title of the book with publication year after 1980 is:" << something[i].title;
cout << endl << "Price of the book with publication year after 1980 is:" << something[i].price;
cout << endl << "The book publication year is:" << something[i].year;
}
}
void findminprice(book something[])
{
book min;
min = something[0];
for (int i = 1; i < 10; i++)
if (something[i].price < min.price)
min = something[i];
cout << endl << "Book with min price is : " << min.price;
}