#include<iostream.h>
#include<stdio.h>
#include<conio.h>
struct info
{
char book_name[30];
float price;
int copy;
};
struct node
{
info data;
node*link;
};
node *start=NULL,*x,*y;
void add()
{
if(start==NULL)
{
start=new node;
cout<<"\nEnter book name: ";
cin>>start->data.book_name;
cout<<"Enter price: ";
cin>>start->data.price;
cout<<"Enter no. of copies: ";
cin>>start->data.copy;
start->link=NULL;
}
else
{
x=new node;
cout<<"Enter book name: ";
cin>>x->data.book_name;
cout<<"Enter price: ";
cin>>x->data.price;
cout<<"Enter no. of copies: ";
cin>>x->data.copy;
x->link=start;
start=x;
}
}
void display1()
{
x=start;
while(x!=NULL)
{
cout<<"\nName of book: "<<x->data.book_name<<endl;
cout<<"Price: "<<x->data.price<<endl;
cout<<"No. of copies: "<<x->data.copy<<"\n\n";
x=x->link;
}
}
void display2()
{
x=start;
while(x!=NULL)
{
if(x->data.price>150 && x->data.copy>10)
{
cout<<"Name of book: "<<x->data.book_name<<endl;
cout<<"Price: "<<x->data.price<<endl;
cout<<"No. of copies: "<<x->data.copy<<"\n\n";
}
else
{
cout<<"There are no books which have more than 5 copies";
cout<<"\t\tand price greater than Rs 150."<<"\n\n";
}
}
}
void main()
{
clrscr();
int ch;
start=NULL;
do
{
cout<<"1. Add at begining."<<endl;
cout<<"2. Display list."<<endl;
cout<<"3. Display particular."<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter your choice: ";
cin>>ch;
switch(ch)
{
case 1: {
add();
break;
}
case 2: {
display1();
break;
}
case 3: {
display2();
break;
}
case 4: {
break;
}
default: {
cout<<"Wrong choice entered."<<"\n";
}
}
}
while(ch!=4);
}