Question

In: Computer Science

C++ programming Complete the code to input and store all the information in the structure Book:...

C++ programming

Complete the code to input and store all the information in the structure Book: title, author, year and pages.

Complete the function print() with arguments and code to print a Book variable in the following format:

Book title: <title>
Book author: <name>
Published in <year>
Number of pages: <pages>

#include <iostream>

using namespace std;

struct Book {
string title;
string author;
string year;
int pages;
};

void print(/*arguments*/)
{
//Complete function
}

int main() {

//Declare structure variable

//Get 4 inputs

//Call print function to generate output
}

Solutions

Expert Solution

Code:

#include<iostream>
using namespace std;
struct Book
   {
   string title;
   string author;
   string year;
   int pages; //structure declaration
   };
void print(struct Book input[]) //print function
   {
       int i;
       cout << "All Books Details\n"; //printing all books details
       for (i=0;i<4;i++) //iterating loop to print the books details
           {
           cout << input[i].title << endl << input[i].author << endl << input[i].year << endl << input[i].pages << endl;
           }
   }
int main()
{
   struct Book input[4]; //structure Book input array taking 4 books details
   int i;
   char ch;
   for (i=0;i<4;i++) // taking 4 books details
       {
       cout << "Enter the Book Title : ";
       getline(cin,input[i].title); //taking book title from user
         
       cout << "Enter the Book Author : ";
       getline(cin,input[i].author); //taking author from user
      
       cout << "Enter the Year when book was published : ";
       getline(cin,input[i].year); //taking year from user
      
       cout << "Enter the no of pages in Book : ";
       cin >> input[i].pages; //taking pages from user
       cin.ignore(); //ignore the new lines
       cout << endl;
       }
   print(input); //calling print() function
   return 0;
}

Code and Outputs Screenshots:

Note : if you have any queries please post a comment thanks a lot...always available to help you...


Related Solutions

[ Write in C not C++] 1. Define a C structure Covid19Info to store the information...
[ Write in C not C++] 1. Define a C structure Covid19Info to store the information of COVID 19 cases of countries around the world. It keeps the name of the country, number of COVID 19 cases, number of deaths, current test positive rate, etc. After defining the structure, declare a variable of Covid19Info type with some initial values for Bangladesh. [8]
in the c programming language input is given in the form The input will be of...
in the c programming language input is given in the form The input will be of the form [number of terms] [coefficient k] [exponent k] … [coefficient 1] [exponent 1] eg. 5 ─3 7 824 5 ─7 3 1 2 9 0 in this there are 5 terms with -3x^7 being the highest /* Initialize all coefficients and exponents of the polynomial to zero. */ void init_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE...
Complete the following assignment in C programming language. Get the user’s first name and store it...
Complete the following assignment in C programming language. Get the user’s first name and store it to a char array Declare a character array to hold at least 20 characters. Ask for the user’s first name and store the name into your char array. Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces. Get 3 exam scores from the user: Declare an array of 3 integers Assume the scores are out...
Complete the following Java code. Compute the average of all the numbers in nums and store...
Complete the following Java code. Compute the average of all the numbers in nums and store it in a variable called average      public static void main(String[] args){                         int[] nums = <some array values>;
Complete the following exercises using C programming language. Take screenshots of the code and its output...
Complete the following exercises using C programming language. Take screenshots of the code and its output where specified and paste them into in a well-labeled Word document for submission. Scenario Assume you are the CIO of an organization with three different IT department locations with separate costs. You want a program to perform simple IT expenditure calculations. Your IT expenditure target is $35,000 per site. Site expenditures: Site 1 – $35,000. Site 2 – $37,500. Site 3 – $42,500. Exercise...
C++ programming To store the information about a city and its weather forecast, create a struct...
C++ programming To store the information about a city and its weather forecast, create a struct that holds the city's name (string), population (int), and a forecast array storing 7 string elements representing the city's weather in the next 7 days. The program will then accept user input to enter the name and population of the city, then it accepts 7 string inputs to store into the forecast array. Then the program will output the city's name, population, and forecast...
C++ C++ We are prompting input from the users. Users input "I like the book "The...
C++ C++ We are prompting input from the users. Users input "I like the book "The little prince" very much" I want to separate this sentence by the order "I" "like" "the" "book" "the little prince" "very" "much". (Keep the quotation mark of little prince, because it is the way the user entered) and adding this to a arraylist in c++  
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
Using the Prelude to Programming book, complete Programming Challenge 2 on page 463. Save your file...
Using the Prelude to Programming book, complete Programming Challenge 2 on page 463. Save your file as LASTNAME_FIRSTNAME_M07HW2. (worth 15 points) Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of email addresses where the address is of the following form: [email protected]. please help!!!!
C code please This program will store roster and rating information for a soccer team. Coaches...
C code please This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output these arrays (i.e., output the roster). (3 pts) Ex: Enter player 1's jersey number: 84...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT