Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in book information into a Book structure for the loc

ID: 3691822 • Letter: W

Question

Write a program that reads in book information into a Book structure for the local library and then calculate some Information for them (See Sample Output below). Each Book should have a title, publishing year, number of page*, and a number of copies. Store the items into an array of 3 structures. The program should output the total number of books, the name of the oldest book, and the name of book with the longest number of pages. Book data should be stored In a struct variable of the type Book, which has four components: There are 3 books. Use an array with 3 elements of the data type Book. Read the item information into the structure array from the console. Calculate the total number of copies of all 3 books. Find the index of the oldest book (based on publishing year). Find the index of longest book (based on number of pages).

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

struct book

{

String title;

int pyear;

int pages;

int copies;

};

int main()

{

//creating three book structure variables using array

book b[2];

int total=0;

int oldest=0;

for(i=0;i<=2;i++)

{

cout <<"Book #"<<(i+1);

cout <<"Enter title";

cin>>b[i].title;

cout <<"Enter publishing year";

cin>>b[i].pyear;

cout< <"Enter number of pages";

cin>>b[i].pages;

cout <<"Enter number of copies";

cin>>b[i].copies;

}

for(i=0;i<=2;i++)

{

total=total+b[i].copies;

}

cout<<"Total number of books "<<total;

//finding oldest book

if((b[0].pyear<b[1].pyear)&& (b[0].pyear<b[2].pyear))

{

cout<<"oldest book is"<<b[0].title;

}

elseIf((b[1].pyear<b[0].pyear)&& (b[1].pyear<b[2].pyear))

{

cout<<"oldest book is"<<b[1].title;

}

else

{

cout<<"oldest book is"<<b[2].title;

}

//finding long book

if((b[0].pages>b[1].pages)&& (b[0].pages>b[2].pages))

{

cout<<"longest book is"<<b[0].title;

}

elseIf((b[1].pages>b[0].pages)&& (b[1].pages>b[2].pages))

{

cout<<"longest book is"<<b[1].title;

}

else

{

cout<<"longest book is"<<b[2].title;

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote