-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog13.cpp
More file actions
60 lines (47 loc) · 977 Bytes
/
prog13.cpp
File metadata and controls
60 lines (47 loc) · 977 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
52
53
54
55
56
57
58
59
60
/*
Write a C++ Program to create a class Data with integer, character and float
data members. Demostrate constructor overloading on this class with all types of
contructors including default argument constructor.
*/
#include <iostream>
using namespace std;
class Data {
private:
int i;
char c;
float f;
public:
Data() {
i = 1;
c = 'a';
f = 1.21;
}
Data(int i, char c, float f) {
this->i = i;
this->c = c;
this->f = f;
}
Data(Data &d) {
i = d.i;
c = d.c;
f = d.f;
}
void display() { cout << "i: " << i << "\tc: " << c << "\tf: " << f << endl; }
};
int main() {
int i;
char c;
float f;
cout << "Enter an integer, char, and a float" << endl;
cin >> i >> c >> f;
cout << "Default constructor: " << endl;
Data d1;
d1.display();
cout << "Parameterized constructor: " << endl;
Data d2(i, c, f);
d2.display();
cout << "Copy Constructor: " << endl;
Data d3(d2);
d3.display();
return 0;
}