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, 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.
Note : You are also required to give detailed function definitions.
#include<iostream>
#include<string>
using namespace std;
class BOOK
{
int book_no;
string book_title;
float price;
float TOTAL_COST(int N)
{
return N*price;
}
public:
void INPUT()
{
cout<<"Enter Book Number : ";
cin>>book_no;
cout<<"Enter Book Title : ";
getline(cin,book_title);
getline(cin,book_title);
cout<<"Enter price : ";
cin>>price;
}
void PURCHASE()
{
int n;
cout<<"\nEnter the number of copies to be purchased : ";
cin>>n;
float total_price=TOTAL_COST(n);
cout<<"Total Price : "<<total_price;
}
void SHOWINFO()
{
cout<<"Book Number : "<<book_no;
cout<<"\nBook Title : "<<book_title;
cout<<"\nPrice : "<<price;
PURCHASE();
}
};
int main()
{
BOOK b1;
b1.INPUT();
b1.SHOWINFO();
}
Comments
Leave a comment