0
Write a program that declares a structure to store book Id, price and pages of a book. Use structure and print costly book?
Write a program that declares a structure to store book Id, price and pages of a book. The structure should include functions to assign user defined values to each book and display the record of most costly book.
2 odpowiedzi
0
go through the c++ tutorial and you will be able to do this
- 1
#include<iostream>
#include<conio.h>
using namespace std;
struct Book
{
int b_id;
char b_name[30];
int price;
};
struct Order
{int i;
int order_id;
Book b[100];
};
int main()
{
Order c;
cout<<"enter number of books :";
int n;
cin>>n;
cout<<"Enter your Order Id: ";
cin>>c.order_id;
cout<<"Enter details of five books: \n";
for(int i=0;i<n;i++)
{
cout<<"\nEnter Book Id: ";
cin>>c.b[i].b_id;
cout<<"Enter Book Name: ";
cin>>c.b[i].b_name;
cout<< " Enter Price of the Book: ";
cin>>c.b[i].price;
}
cout<<"\n Order details is as follows: "<<endl;
cout<<" Order Id: "<<c.order_id<<endl;
cout<<" Book Id\t Book Name \t Price "<<endl;
for(int i=0;i<n;i++)
{
cout<<c.b[i].b_id<<"\t\t"<<c.b[i].b_name<<"\t\t"<<c.b[i].price<<endl;
}
int i ;
int x=0;
for(int i=0;i<n;i++)
if(c.b[0].price<c.b[i].price)
x=i;
cout<<"most costly book detail is :\n";
cout<<c.b[x].b_id<<"\t\t"<<c.b[x].b_name<<"\t\t"<<c.b[x].price<<endl;
}