-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.cpp
90 lines (70 loc) · 2.15 KB
/
class.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <vector>
#include <iostream>
class book{
public :
static int get_book_count(){
return book_count ;
}
std::string title ;
std::string author ;
int no_of_pages ;
book(){
book_count ++ ;
title = "No title" ;
author = "No author" ;
no_of_pages = 0 ;
}
//Constructor
book(std::string title_, std::string author_ ,int no_of_pages_){
book_count ++ ;
title = title_ ;
author = author_ ;
no_of_pages = no_of_pages_ ;
}
book(std::string title, std::string author){
book_count++ ;
this->title = title ;
this->author = author;
}
~book(){ //destructor
book_count -- ;
std::cout << "Destructer\n" ;
}
void set_publisher(std::string publisher_name){
publisher = publisher_name ;
}
std::string get_publisher(){
return publisher ;
}
void set_meta_data(std::string meta_data){
this->meta_data = meta_data ;
}
std::string get_meta_data(){
return meta_data ;
}
private :
std::string publisher ;
static int book_count ;
protected :
std::string meta_data ;
} ;
int book::book_count = 0;
int main(){
book book_0 = book("SHERLOCK H.." ,"Sir. AUTHOR..") ;
book_0 = book("SHERLOCK H.." ,"Sir. AUTHOR..") ;
book_0.set_publisher("Steam") ;
book book_1("SHERLOCK H.." ,"Sir. AUTHOR..") ;
book_1.set_publisher("Steam") ;
std::cout << book_1.title << "\n" ;
std::cout << book_1.author << "\n" ;
std::cout << book_1.get_publisher() << "\n" ;
//get count when public
//std::cout << book_1.book_count << "\n" ;
//std::cout << book::book_count << "\n" ;
//get count when provate
std::cout << book_0.get_book_count() << "\n" ;
std::cout << book::get_book_count() << "\n" ;
book_0.~book() ; // destructor called
std::cout << book::get_book_count() << "\n" ;
book books_array[5] ; // static array
}