#include <iostream>
using namespace std;
class Book
{
private:
string author, title, publisher;
int price, stockPos;
public:
Book(string au, string ti, string pub, int pri, int stock) {
this -> author=au;
this -> title=ti;
this -> publisher=pub;
this -> price=pri;
this -> stockPos=stock;
}
void enter() {
cout << "Input a book author: ";
cin >> author;
cout << "Input a book title: ";
cin >> title;
cout << "Input a book publisher: ";
cin >> publisher;
cout << "Input a book price: ";
cin >> price;
cout << "Input a book stock position: ";
cin >> stockPos;
}
void display() {
cout << "Author: " << author << '\n';
cout << "Title: " << title << '\n';
cout << "Publisher: " << publisher << '\n';
cout << "Price: " << price << '\n';
cout << "Stock position: " << stockPos << '\n';
}
};
int main()
{
Book *harry = new Book("J.K. Rowling", "Harry Potter book 1", "Bloomsbury", 16, 1);
harry->display();
return 0;
}
Example:
Author: J.K. Rowling
Title: Harry Potter book 1
Publisher: Bloomsbury
Price: 16
Stock position: 1
Comments
Leave a comment