Structures and Arrays: Assignment C++ Your program will be creating 10 library b
ID: 3682212 • Letter: S
Question
Structures and Arrays: Assignment
C++
Your program will be creating 10 library books. Each library book will have title, author and publishing year. Each library book will be stored as a structure and your program will have an array of library books (an array of structures).
You will create a corresponding array of book genres: Mystery, Romance, Fantasy, Technology, Children, etc. If the first element of the array is storing information about a book titled : "More about Paddington", then the corresponding first element of book genre would indicate 'Children'.
The user of your program should be able to select what they want to do from a menu of the following things and your program needs to do what the menu selection indicates:
* Print the entire list of library books (including the title, author, publishing year and book genre)
* Display a count of how many books exist per genre
* Find all books where the publishing year is greater than the year they put in
* Print the titles of the books where the Genre may be indicated by a 'C' for Children, or 'M' for Mystery
Explanation / Answer
#include<iostream>
using namespace std;
struct book//structure declarations...
{
char title[100],author[100];
int pyear;
};
int main()
{
struct book b[10];//declaring structure array...10 library books...
char genre[10][100];//genre for each book...
int i;
for(i=0;i<10;i++)//taking user inputs...
{
cout<<i+1;
cout<<" Enter book title:-";cin>>b[i].title;
cout<<" Enter book Author:-";cin>>b[i].author;
cout<<" Enter book Published year:-";cin>>b[i].pyear;
cout<<" Enter book genre:--";cin>>genre[i];
}
cout<<" TITLE AUTHOR published year Genre ";
for(i=0;i<10;i++)//printing all books inforamtion...
{
cout<<" ";
cout<<i+1;
cout<<" ";
cout<<b[i].title;cout<<" ";
cout<<b[i].author;cout<<" ";
cout<<b[i].pyear; cout<<" ";
cout<<genre[i];cout<<" ";
}
int cc=0;
cout<<"The number of books for each genre is:-";
for(int j=0;j<10;j++)
{for(i=0;i<10;i++)
{
if(genre[i][0]==genre[j][0])cc++;
}
cout<<"for genre";
cout<<genre[j];
cout<<" ";
cout<<cc;
cout<<" ";
}
int year;
cout<<"Enter year ";
cin>>year;
cout<<"The books are:-";//The books that have greater publishing year than give year...
for(i=0;i<10;i++)
{
if(b[i].pyear>year)cout<<b[i].title<<' ';
}
cout<<" ";
char c[100];
cout<<"Enter genre ";
cin>>c;
cout<<"The books for given genre is:-";
for(i=0;i<10;i++)
{
if(c[0]==genre[i][0])cout<<b[i].title<<' ';
}
cout<<" ";
return 0;
}