-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditionusing4objects.cpp
More file actions
51 lines (36 loc) · 872 Bytes
/
additionusing4objects.cpp
File metadata and controls
51 lines (36 loc) · 872 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
//addition of two numbers taken from different objects and added in third object
#include <iostream>
using namespace std;
class addition{
private:
int num1, num2;
public:
void getdata();
void display(addition a1, addition a2);
void add(addition a1, addition a2);
};
void addition:: getdata(){
cout<<"enter first element:";
cin>>num1;
cout<<"enter second element:";
cin>>num2;
}
void addition::display(addition a1, addition a2){
// addition a1, a2;
cout<<a1.num1<<"\t"<<a2.num2;
}
void addition::add(addition a1, addition a2){
// addition a1, a2;
int sum=a1.num1+a2.num2;
cout<<"\nsum of "<<a1.num1<<" and "<<a2.num2<<" is: "<<sum;
}
int main()
{
addition a1, a2, a3;
// int num1, num2;
a1.getdata();
a2.getdata();
a3.display(a1, a2);
a3.add(a1, a2);
return 0;
}