A program to declare a structure Library with the following data members:

a)

book_no

integer

b)

name

character array

c)

author

character array

d)

address_publisher

variable of structure address having three data members

street

character array

city

character array

state

character array

pincode

long integer

 

#include<iostream.h>
#include<stdio.h>
#include<conio.h>

struct library
{
public:

int book_no;
char name[50];
char author[20];
struct address_publisher
{
char street[100];
char city[20];
char state[20];
long pincode;
}add;
}book1;

void getdata()
{
cout<<"Enter book no.: ";
cin>>book1.book_no;
cout<<"Enter name of book: ";
gets(book1.name);
cout<<"Enter name of author: ";
gets(book1.author);
cout<<"Enter address of publisher:"<<endl;
cout<<"Street: ";
gets(book1.add.street);
cout<<"City: ";
gets(book1.add.city);
cout<<"State: ";
cin>>book1.add.state;
cout<<"Pincode: ";
cin>>book1.add.pincode;
}

void display()
{
cout<<"\n\n***********************************\n\n";

cout<<"Book no.: "<<book1.book_no<<endl;
cout<<"Name of book: ";
puts(book1.name);
cout<<"Name of author: ";
puts(book1.author);
cout<<"Address of publisher: "<<endl;
cout<<" Street: ";
puts(book1.add.street);
cout<<" City: ";
puts(book1.add.city);
cout<<" State: ";
puts(book1.add.state);
cout<<" Pincode: "<<book1.add.pincode<<endl;
}

void main()
{
clrscr();

getdata();

display();

getch();
}

 

< Back