-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_constructor_overloading.cpp
More file actions
43 lines (42 loc) · 994 Bytes
/
Copy path08_constructor_overloading.cpp
File metadata and controls
43 lines (42 loc) · 994 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
//example on constructor overloading through a banking system.
#include <iostream>
using namespace std;
class customer{
string name;
int account_no;
int balance;
//making constructor.
public :
customer() //this is Default Constructor.
{
cout<<"Constructor is called"<<endl;
}
customer(string n,int a,int b) //this is Parameterized Constructor.
{
name = n;
account_no = a;
balance = b;
}
//constructor overloading
customer(string n,int a)
{
name = n;
account_no = a;
balance = 0;
}
void show()
{
cout<<"Name : "<<name<<" ";
cout<<"Account Number : "<<account_no<<" ";
cout<<"Balance : "<<balance<<endl;
}
};
int main ()
{
customer objDefaultconstructor;
customer obj1("Piyush",4267,1000);
customer obj2("Infy",1234);
obj1.show();
obj2.show();
return 0;
}