-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day13_AbstractClasses.cpp
68 lines (63 loc) · 1.51 KB
/
Day13_AbstractClasses.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// THE PROBLEM
// ***************************
// Given a Book class and a Solution class, write a MyBook class that does the following:
// Inherits from Book, has a constructor with title, author, price, and implements a display function to see data
// Solution Created By: Dustin Kaban
// Date: June 8th, 2020
// ***************************
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
class Book{
protected:
string title;
string author;
public:
Book(string t,string a){
title=t;
author=a;
}
virtual void display()=0;
};
// Write your MyBook class here
class MyBook{
// Parameters:
// title - The book's title.
// author - The book's author.
// price - The book's price.
protected:
string title;
string author;
int price;
public:
//Constructor
MyBook(string t, string a, int p)
{
title = t;
author = a;
price = p;
}
// Function Name: display
// Print the title, author, and price in the specified format.
void display()
{
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Price: " << price << endl;
}
};
// End class
int main() {
string title,author;
int price;
getline(cin,title);
getline(cin,author);
cin>>price;
MyBook novel(title,author,price);
novel.display();
return 0;
}