Answer to Question #178357 in C++ for Varshini

Question #178357

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.


1
Expert's answer
2021-04-05T04:22:32-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS