Thursday, 26 May 2016

Q: Write a program that declares a structure Book to store BookId, book name and price. it declares another structure Order that contains Orderid and an array of Book of length 5. The program should define a variable of type Order and input the values from the user. The program finally displays the values.


Program:

#include<iostream.h>
#include<conio.h>
struct Book
{
    int b_id;
    char b_name[30];
    int price;
};
struct Order
{
   int order_id;
   Book b[5];
};
void main()
{
    Order c;
    cout<<"Enter your Order Id: ";
    cin>>order_id;
    cout<<"Enter details of five books: ";
    for(int i=0;i<5;i++)
{
      cout<<"Enter 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: "<<order_id<<endl;
    cout<<" Book Id\t Book Name \t Price "<<endl;
    for(i=0;i<5;i++)
{
    cout<<c.b[i].b_id<<"\t"<<c.b[i].b_name<<"\t"<<c.b[i].price<<endl;
}
    getche();
}

2 comments:

  1. Nice one bro you are doing well .keep this work up

    ReplyDelete
  2. good brother
    i also wrote same code but my compiler did not accept this
    i dont know but why

    ReplyDelete