Create a class Book that contains instance variables like BKName, BKId and BKAuthor, a
parameterized constructor to initialize its instance variables, a method BKUpdateDetails(String name,
int id, String author), that accepts new values for name, Id and author as parameters and updates
the corresponding instance variable values of that object and another method BKDisplay() to display
the book details. Create a class BookDemo and provide main method for instantiate a Book object,
display the original book details, update its details with new values, and display the updated book
details
#include <iostream>
#include <string>
using namespace std;
class Book{
string BKName, BKAuthor;
int BKId;
public:
Book(){}
Book(int BKId, string BKName, string BKAuthor){
this->BKName = BKName;
this->BKAuthor = BKAuthor;
this->BKId = BKId;
}
void BKUpdateDetails(string name, int id, string author){
this->BKName = name;
this->BKAuthor = author;
this->BKId = id;
}
void BKDisplay(){
cout<<"Book ID: "<<BKId<<endl;
cout<<"Book Name: "<<BKName<<endl;
cout<<"Book Author: "<<BKAuthor<<endl;
}
};
class BookDemo{};
int main(){
Book bookDemo(1, "The River and the Source", "Margaret A. Ogola");
bookDemo.BKDisplay();
cout<<endl;
bookDemo.BKUpdateDetails("Gifted Hands", 2, "Ben Carson MD");
bookDemo.BKDisplay();
return 0;
}
Comments
Leave a comment