-
Notifications
You must be signed in to change notification settings - Fork 0
/
contructor 2 l16.cpp
45 lines (44 loc) · 993 Bytes
/
contructor 2 l16.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
//constructor 2(parameterised constructor) l-15-16
//Note : Constructor is executed once for an object :: ek object ke liye ek hi baar execute hoga
#include<iostream>
using namespace std;
class car//class named car
{
private://access specifier
float petrol,distance;//instance variable:made for objects
public://access specifier
car(); //Default contructor
// defining inside class {
// petrol=70;//initializing
// distance=0;
// }
car(float a)//single parameterized
{
petrol=a;
distance=0;
}
car(float a,float b)//multiple parameterized contructor or constructor overloading)
{
petrol=a;
distance=b;
}
void show();
};
car::car()//defining outside class
{
petrol=0;//initializing
distance=0;
}
void car::show()
{
cout<<"Gaadi mein "<<petrol<<" litre petrol hai"<<endl;
cout<<"Gaadi "<<distance<<" km chali hai"<<endl;
}
int main()
{
car hondacity(5,10),civic,swift(1);//objects
hondacity.show();
civic.show();
swift.show();
return 0;
}