-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook class.cpp
More file actions
51 lines (38 loc) · 1011 Bytes
/
book class.cpp
File metadata and controls
51 lines (38 loc) · 1011 Bytes
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
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class book{
private:
string title;
string author;
int page;
float price;
public://constructor
book(string t,string a,int p,float pr)
:title(t),author(a),page(p),price(pr){}
//mathod display
void displayinfo()
{
cout<<"title:"<<title<<"\n"<<"author:"<<author<<"\n"<<"page:"<<page<<"\n"<<"price:"<<fixed<<setprecision(2)<<price<<"\n\n";
}
void applydiscount(float discount)
{
price-=price*(discount/100);
}
};//end of ----
int main()
{
book book1( "the greatest gatsby","f.scott",218,10.99f);
book book2( "1984","geoage",328,1599);
book book3( "to kill a mokingbard","harper lee",281,12.99f);
//display
book1.displayinfo();
book2.displayinfo();
book3.displayinfo();
//applyy discount
cout<<"after applying discount:"<<"\n";
book1.applydiscount(10);
book1.displayinfo();
return 0;
}