-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstr.cpp
67 lines (54 loc) · 1.47 KB
/
constr.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
// /*
// Intrduction of Constructor
// Constructor is a special member function of a class which is used to initialize the objects of its class.
// It is special because its name is the same as the class name.
// It is invoked whenever an object of its associated class is created.
// It is constructor’s responsibility to initialize the object of its class.
// It has no return type, not even void.
// */
class Student
{
int roll;
string name;
int sem;
int total_marks;
public:
Student(){
cout<<"Default Constructor Called"<<endl;
}
Student(int a,int b,int c){
cout<<"The sum of Given Number is : "<<a+b+c<<endl;
}
Student(int roll1, string name1, int sem1, int total_m)
{
roll = roll1;
name = name1;
sem = sem1;
total_marks = total_m;
}
void get_data()
{
cout << "Roll no. : " << roll << endl;
cout << "Name : " << name << endl;
cout << "Semester : " << sem << endl;
cout << "Total Marks : " << total_marks << endl;
}
~Student(){
cout<<"Destructor is called\n";
}
};
int main()
{
// Printing by Normal Method
Student s1;
// s1.set_data(1, "Yash", 3, 100);
// s1.get_data();
// Printing with the help of Constructor
Student s2(1, "Yash", 3, 100);
// s1.set_data(1, "Yash", 3, 100);
s2.get_data();
return 0;
}
// E:\Programming\CODING 2.0\C++\constr.cpp