Python 3 I Overview This checkpoint is intended to help you

Python 3 I. Overview This checkpoint is intended to help you practice the syntax of basic inheritance. In looking at the collection of books next to your bed, you notice that they fall into a few different categories. First, you have your regular books and novels, second, your textbooks, and finally, your collection of picture books You quickly recognize that they all have many things in common, but there are some light differences in the properties of these different kinds of books. In particular, all books seem to have the following: title string author: string publicationYear: int

Solution

#include <iostream>
#include <string>
using namespace std;

class Book
{
public:
string title,author;
int publicationYear;

void promptBookInfo()
{
cout<<\"\ Title : \";
cin>>title;
cout<<\"\ Author : \";
cin>>author;
cout<<\"\ Publication Year : \";
cin>>publicationYear;
}

void displayBookInfo()
{
cout<<\"\ \"<<title<<\" (\"<<publicationYear<<\") by \"<<author;
}
};

class TextBook:public Book
{
string subject;

public:
void promptSubject()
{
cout<<\"\ Subject : \";
cin>>subject;
}

void displaySubject()
{
cout<<\"\ Subject : \"<<subject;
}

};

class PictureBook:public Book
{
string illustrator;

public:
void promptIllustrator()
{
cout<<\"\ \ Illustrator : \";
cin>>illustrator;
}

void displayIllustrator()
{
cout<<\"\ Illustrated by \"<<illustrator;
}

};


int main()
{
Book book;
book.promptBookInfo();
book.displayBookInfo();

cout<<endl;
TextBook textBook;
textBook.promptBookInfo();
textBook.promptSubject();
cout<<endl;
textBook.displayBookInfo();
textBook.displaySubject();

cout<<endl;
PictureBook pictureBook;
pictureBook.promptBookInfo();
pictureBook.promptIllustrator();
cout<<endl;
pictureBook.displayBookInfo();
pictureBook.displayIllustrator();

return 0;
}

 Python 3 I. Overview This checkpoint is intended to help you practice the syntax of basic inheritance. In looking at the collection of books next to your bed,
 Python 3 I. Overview This checkpoint is intended to help you practice the syntax of basic inheritance. In looking at the collection of books next to your bed,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site