-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_constructor#1.cpp
47 lines (47 loc) · 1013 Bytes
/
copy_constructor#1.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
#include<iostream>
using namespace std;
class wall{
double length,height;
void display(){
cout<<"length: "<<length<<", height: "<<height<<endl;
}
public:
wall(double length,double height ){
display();
this->height=height;
this->length=length;
}
wall (wall &obj){
display();
height=obj.height;
length=obj.length;
}
wall operator +(wall &obj){
display();
height=obj.height;
length=obj.length;
}
double calc_area(){
return length*height;
}
};
int main(){
/*Method#1*/
// wall w1(10.5,8.6),w2(0,0);
// cout<<"AREA 1: "<<w1.calc_area()<<endl;
// w2 = w1;
// cout<<"AREA 2: "<<w2.calc_area()<<endl;
/*Method#2*/
// wall w1(10.5,8.6);
// cout<<"AREA 1: "<<w1.calc_area()<<endl;
// wall w2 = w1;
// cout<<"AREA 2: "<<w2.calc_area()<<endl;
/*Method#3*/
wall w1(10.5,8.6),w2(0,0);
cout<<"AREA 1: "<<w1.calc_area()<<endl;
w2+w1;
cout<<"AREA 2: "<<w2.calc_area()<<endl;
wall w3=w2;
cout<<"AREA 2: "<<w3.calc_area()<<endl;
return 0;
}