Answer to Question #255446 in C++ for Agy

Question #255446
Question 5 [15 Marks] Write a C++ programme to create a class by name Book Data Members of the class BOOK are BOOK_NO integer BOOK_NAME 20 characters BOOK_PRICE float TOTAL_COST() Calculate the cost of N books where N is passed as an argument. Member Functions of the class BOOK are INPUT() function to read BOOK_NO. BOOK_NAME, BOOK_PRICE PURCHASE() Get an input for the number of copies to be purchased. It uses TOTAL_COST() function to calculate the cost of N books and prints the total cost to be paid by the user. Create the necessary object for this class to run this program effectively. (Implement the OOPS concepts Polymorphism, inheritance, and Friend function wherever it is necessary) Question 6
1
Expert's answer
2021-10-23T23:31:38-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();
}

Output:


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