Answer to Question #247480 in C++ for Angelie Suarez

Question #247480
#include <string>
using namespace std;
struct book
{
string title;
string author;
unsigned int year;
};
int main()
{
book bookrec;
cout << “Enter Book Title:”; getline(cin,bookrec.title);
cout << “Enter Book Author:”; getline(cin,bookrec.author);
cout << “Enter Publication Year:”; cin >> bookrec.year;
cout << “The following information has been received…\n”);
cout << “Book Title:” << bookrec.title;
cout << “Book Author:” << bookrec.author;
cout << “Year Published:” << bookrec.year << “\n”;
system(“pause”);
return 0;
}


Modify Program Sample-1 by applying a structure array in the program. The program should accept 5 records of books and displays them on the screen.
The program should also include two functions: (1) a function for entering book information; and (2) a function for displaying the records.
1
Expert's answer
2021-10-06T16:33:42-0400
#include <iostream>
using namespace std;


struct book
{
    char title[50];
    char author[50];
    int roll;
    int publication;
    float marks;
} s[5];
int Input(){
    cout << "Enter information of books: " << endl;
    for(int i = 0; i < 5; ++i)
    {
        s[i].roll = i+1;
        cout << "For book" << s[i].roll << "," << endl;
        
        cout << "Enter title: ";
        cin >> s[i].title;
        
        cout << "Enter Book Author:"; 
        cin >> s[i].author;
        
        cout << "Enter Publication Year:";
        cin >> s[i].publication;


        cout << endl;	
}}
int display(){
	cout << "The following information has been received…\n";
	for(int i = 0; i < 5; ++i){
		 s[i].roll = i+1;


	cout << "\nBook Title:" << s[i].title;
	
	cout << ", Book Author:" <<s[i].author;
	
	cout << ", Year Published:" << s[i].publication << "\n";
}}
int main()
{  
Input();
display();


	}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS