Create the Class Book with the following attributes: Book ID, Title, Authors, Unit Price. Print the
current details of the book. Add a behaviour to modify the price and display the updated book details.
Display the total Amount to be paid for each Book, using unit price & 12% tax. Implement using OO
concepts.
#include<iostream>
using namespace std;
class Book{
private:
int Book_ID;
string Title, Authors;
double Unit_Price;
public:
Book(int id, string t, string a, double u){
Book_ID =id;
Title=t;
Authors =a;
Unit_Price = u;
}
void printCurrentDetails(){
cout<<"Book ID: "<<Book_ID<<"\nTitle: "<<Title<<"\nAuthors: "<<Authors<<"\n Unit Price: "<<Unit_Price<<endl;
}
void updatedDisplay(int price){
Unit_Price = price;
cout<<"Book ID: "<<Book_ID<<"\nTitle: "<<Title<<"\nAuthors: "<<Authors<<"\n Unit Price: "<<Unit_Price<<endl;
}
void totalamountPaid(){
cout<<"The total price paid is:\t"<<Unit_Price + (Unit_Price * 0.12)<<endl;
}
};
int main(){
int Book_ID;
cout<<"Enter Book ID "<<endl;
cin>>Book_ID;
string Title;
cout<<"Enter the book title "<<endl;
cin>>Title;
string Authors;
cout<<"Enter all the Book's Authors "<<endl;
cin>> Authors;
double Unit_Price;
cout<<"Enter the book unit price"<<endl;
cin>>Unit_Price;
Book b(Book_ID,Title,Authors,Unit_Price);
b.printCurrentDetails();
cout<<"Enter the new price of the book "<<endl;
int newPrice;
cin>>newPrice;
b.updatedDisplay(newPrice);
b.totalamountPaid();
}
Comments
Leave a comment