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>
using namespace std;
class Book {
public:
string BkName;
int BkId;
string BkAuthor;
/* Book (string x, int y, string z){
BkName = x;
BkId = y;
BkAuthor = z;
}
*/
void BKUpdateDetails()
{
cout<<"Enter Book Name: "; cin>>BkName;
cout<<"Enter Book ID: "; cin>>BkId;
cout<<"Enter Book Author: "; cin>>BkAuthor;
}
void BKDisplay()
{
cout<<"BookName"<<" "<<"BookId"<<" "<<"BookAuthor"<<endl;
cout<<BkName<<" "<<BkId<<" "<<BkAuthor<<endl;
}
};
int main()
{
class Book b;
b.BKUpdateDetails();
b.BKDisplay();
cin.get();
return 0;
}
Part 2
Comments
Leave a comment