In: Computer Science
The most common attributes of a book are the Book Title, and ISBN. The most common functions are to set the Book Title, and ISBN,
Write the code to implement this problem.
1. Write the UML Diagram that represents this class Book
2. Use code blocks editor and in C++
Write a header file Book with these properties.
Write the implementation file for the member functions.
cpp code:
book.h
#ifndef BOOK_H_INCLUDED
#define BOOK_H_INCLUDED
//class
class Book
{
//attribute
std::string title;
std::string ISBN;
public:
//methods
Book();
void setBook(std::string t,std::string i);
std::string getTitle();
std::string getISBN();
};
#endif // BOOK_H_INCLUDED
book.cpp
#include <iostream>
#include "book.h"
using namespace std;
//default constructor
Book::Book()
{
this->title="";
this->ISBN="";
}
//set title and isbn no
void Book::setBook(string t,string i)
{
this->title=t;
this->ISBN=i;
}
//return title
string Book::getTitle()
{
return title;
}
//return isbn
string Book::getISBN()
{
return ISBN;
}
main.cpp
#include <iostream>
#include "book.h"
using namespace std;
int main()
{
//object for book class
Book bk;
//set values
bk.setBook("OOPS","123-423-5003");
//print values
cout <<"Title: "<< bk.getTitle() << endl;
cout <<"\nISBN: "<< bk.getISBN() << endl;
return 0;
}
output:
UML for Book:
//for any clarification , please do comments, if you found this
solution useful,please give me thumbs up