-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice_07.cpp
More file actions
44 lines (44 loc) · 938 Bytes
/
Practice_07.cpp
File metadata and controls
44 lines (44 loc) · 938 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
// Write a program that overloads arithmetic assignment operator to work with user defined objects.
#include<iostream>
using namespace std;
class Read
{
private:
int days, pages;
public:
Read()
{
days = pages = 0;
}
void in()
{
cout<<"How many days have you read? ";
cin>>days;
cout<<"How many pages have yoy read?";
cin>>pages;
}
void show()
{
cout<<"You have read "<<pages<<" pages in "<<days<<" days"<<endl;
}
void operator += (Read r)
{
days = days + r.days;
pages = pages + r.pages;
}
};
int main()
{
Read r1, r2;
r1.in();
r2.in();
cout<<"\nReading number 1..."<<endl;
r1.show();
cout<<"\nReading number 2..."<<endl;
r2.show();
cout<<"\nAdding r1 to r2 using += operator..."<<endl;
r2 += r1;
cout<<"\nTotal reading is as follows: "<<endl;
r2.show();
return 0;
}