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.
#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;
}
Comments
Thanks for answering!!
Leave a comment