Answer to Question #224834 in C++ for snr

Question #224834

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


1
Expert's answer
2021-08-15T04:06:01-0400
#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;
}

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