-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstractClasses.cpp
More file actions
50 lines (44 loc) · 1.12 KB
/
abstractClasses.cpp
File metadata and controls
50 lines (44 loc) · 1.12 KB
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
#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;
};
class MyBook : public Book {
public: // since do not have some methods that access this var, only a disply() that prints
int priceOfBook;
MyBook(string title, string author, int price):
Book(title, author)
{
title = title;
author = author;
priceOfBook = price;
}
void display() {
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Price: " << priceOfBook << endl;
}
};
int main() {
string title,author;
int price;
getline(cin,title);
getline(cin,author);
cin>>price;
MyBook novel(title,author,price);
novel.display();
return 0;
}