In this lab you will work with processing an array of structs. First define a st
ID: 3861846 • Letter: I
Question
In this lab you will work with processing an array of structs. First define a struct called BookInfo. It should have 2 fields - a string to hold the title of a book, and a double to hold the price. Next define a second struct called Author. It should have 2 fields – a string to hold the name of the author, and an array of BookInfo (with 3 elements) to store the three books the author has written.
In main, declare an array of Author structures with 3 elements. This array should be initialized to set all the string fields (the names and the book titles) to “NONE”, and the double fields (the prices) to zero. Remember initialization means to declare and assign values to the array all in one statement ( i.e. no for loops, etc.).
Next call a function from main with the following prototype:
void showInfo(Author a[], int size);
This function should printout the content of the array on the screen Next call a function from main with the following prototype:
void getInfo(Author a[], int size);
This function should allow the user to enter values into the array. If the user types “NONE” for one of the book titles, this means that the author has less than 3 books. The user should not be prompted to enter any more titles and price info for books by that author.
Next, call the showInfo function again from main to display the user’s input on the screen.
ere is the data after initialization The author NONE The title NONE, the price: $0 The title NONE the price $0 The title NONE the price: $0 The author NONE The title NONE the price $0 The title NONE the price $0 The title NONE the price: $0 The author NONE The title NONE the price $0 The title NONE the price 50 The title NONE the price: $0 Get user's input Enter the author's nane Mr. ABC Enter title 1 Intro to C Enter price 1 $29.99 Enter title 2 Intro to Java Enter price 2 $39.99 Enter title 3 NONE Enter the author's nane Mr. DEF Enter title 1 Intro to UB Enter price 1 $35.99 Enter title 2 Intro to Cll Enter price 2 $50 Enter title 3 Intro to C Enter price 3 $40 Enter the author's nane Mr. GHI Enter title 1 Intro to CS Enter price 1 $80.99 Enter title 2 :NONE Here is the data after user's input The author Mr. ABC The title Intro to C++, the price $29.99 The title Intro to Java the price $39.99 The title NONE the price $0 The author Mr. DEF The title Intro to UB, the price: $35.99 The title Intro to Cll, the price $50 The title Intro to C, the price $40 The author Mr. GHI The title Intro to CS, the price: $80.99 The title NONE the price $0 The title NONE, the price: $0 Press any key to continueExplanation / Answer
// AuthBook.cpp : Defines the entry point for the console application. // #include "stdafx.h" // Example program #ifdef _OS_IOS_ #error "iOS version does not support c++ iostream yet." #endif #include #include using namespace std; //book structure struct BookInfo{ string title; double price; }; //Author structure struct Author { string name; BookInfo books[3]; }; //Show Author and book info void showInfo(Author a[], int size){ for(int i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.