Define a class Book with the following specifications:
Private members of the class BOOK are
BOOK NO integer type BOOKTITLE 20 characters PRICE float (price per copy) TOTAL_COST() A function to calculate the total cost for N number of copies where N is passed to the function as argument.
Public members of the class BOOK are
INPUT() function to read BOOK_NO, BOOKTITLE and PRICE. PURCHASE() function to ask the user to input the number of copies to be purchased. It invokes TOTAL_COST() and prints the total cost to be paid by the user.
#include<iostream.h>
#include<conio.h>
class book
{
private:
int bno;
char btytle[20];
float price;
float total_cost(int x)
{
float total;
total=price*x;
return total;
}
public:
void input()
{
cout<<"\nEnter book no\tbook tytle\tprice of the book"<<"\n";
cin>>bno;
cin>>btytle;
cin>>price;
}
void purchase()
{
cout<<"Enter the number of copies to be purchased"<<"\n";
int n;
cin>>n;
float total;
total=total_cost(n);
cout<<"Total cost to be paid by the user:"<<total<<"/- rupees"<<"\n";
}
};
void main()
{
clrscr();
book b;
b.input();
b.purchase();
getch();
}
Comments
Leave a comment