Answer to Question #345377 in C++ for rashid

Question #345377

Write a program that declares a structure to store BookID, price and pages of a book. It defines two structure variables and inputs values. It displays the record of most costly book.


1
Expert's answer
2022-05-26T16:55:31-0400
#include<iostream>
using namespace std;

struct book {
    int BookID;
    float price;
    int pages;
};

int main() {
    book b1, b2;
    b1.BookID = 10;
    b1.pages= 100;
    b1.price = 10.50;
    
    b2.BookID = 20;
    b2.pages= 200;
    b2.price = 20.87;
    
    cout<<"1. "<<"ID " <<b1.BookID<<"; pages  "<<b1.pages<<"; price "<<b1.price<<endl;
    cout<<"2. "<<"ID " <<b2.BookID<<"; pages  "<<b2.pages<<"; price "<<b2.price<<endl<<endl;        
    
    cout<<"The record of most costly book:"<<endl;
    if(b1.price>b2.price)
        cout<<"ID " <<b1.BookID<<"; pages  "<<b1.pages<<"; price "<<b1.price;
    else
        cout<<"ID " <<b2.BookID<<"; pages  "<<b2.pages<<"; price "<<b2.price;
    cout<<endl;    
}

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
APPROVED BY CLIENTS