Answer to Question #182752 in C++ for Garima

Question #182752

Define a class AUTHOR with the following specifications:

Private members of the class BOOK are:

BOOK NO integer type

BOOKTITLE 20 characters

PRICE float (price per copy)

Define functions:

INPUT() : function to read BOOK_NO,BOOKTITLE, PRICE

PURCHASE(): function to ask the user to input the number of copies to be purchased.

TOTAL_COST() : A function to calculate the total cost for N number of copies where N is passed to the function as argument.


1
Expert's answer
2021-04-18T17:28:59-0400
#include <iostream>
using namespace std;


class Author
{
public:
	int number_copyes = 0;
	void purchased() 
	{
		cout << "Input the number of copies to be purchased: ";
		cin >> number_copyes;
	}
	float total_cost() 
	{
		return number_copyes * price_float;
	}


	void input()
	{
		cout << "Enter book_no: ";
		cin >> book_no;
		cout<<"Enter book_tittle: ";
        cin >> book_tittle;
		cout << "Enter price book: ";
		cin >> price_float;
      }
private:
	int book_no;
	char book_tittle [20];
	double price_float;
};




int main()
{
	Author example;
	example.input();
	example.purchased();
	cout << "Total cost: " << example.total_cost();
	return 0;
}

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

Garima
20.04.21, 06:44

Thanks for answering!!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS