#include<iostream>
#include<string.h>
using namespace std;
class book
{
private:
int page;
string name;
float price;
public:
book()
{
price=0.0;
page=0;
name="";
}
book(int p,string n, float pr)
{
page=p;
name= n;
price=pr;
}
void setpage(int p)
{
if(p>0)
{
page=p;
}
}
void setname(string n)
{
if(n!="")
{
name=n;
}
}
void setprice(float pr)
{
if(pr>0.0)
{
price=pr;
}
}
int getpage()
{
return page;
}
string getname()
{
return name;
}
float getprice()
{
return price;
}
void input()
{
cout<<"\nEnter How Many page of Book"<<endl;
cin>>page;
cout<<"Enter Book Name"<<endl;
cin>>name;
cout<<"Enter Book Price"<<endl;
cin>>price;
}
void display(void)
{
cout<<"Book Page is"<<endl;
cout<<page<<endl;
cout<<"The Name is"<<endl;
cout<<name<<endl;
cout<<"The Price is"<<endl;
cout<<price<<endl;
}
};
int main()
{
book b1,b2;
cout<<"Enter book 1 data";
b1.input();
cout<<"Enter book 2 data";
b2.input();
cout<<"\nThe most Costly book is"<<endl;
if(b1.getprice()>=b2.getprice())
{
cout<<"Book 1"<<endl;
cout<<b1.getprice();
cout<<"Rs";
}
else
{
cout<<"Book 2"<<endl;
cout<<b2.getprice();
cout<<"Rs";
}
}
![]() |
Add caption |