Answer to Question #206784 in C++ for python

Question #206784

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.


1
Expert's answer
2021-06-14T13:11:55-0400
#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();
}

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