-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipleconstructor.cpp
More file actions
69 lines (54 loc) · 1.68 KB
/
multipleconstructor.cpp
File metadata and controls
69 lines (54 loc) · 1.68 KB
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
68
69
#include <iostream>
#include <string>
using namespace std;
class Student {
public:
string name;
int marks;
char grade;
// Constructors
Student() {}
Student(string n) {
name = n;
}
Student(string n, int m) {
name = n;
marks = m;
}
Student(string n, int m, char g) {
name = n;
marks = m;
grade = g;
}
Student(char g, int m, string n) {
name = n;
marks = m;
grade = g;
}
};
int main() {
Student s1; // default constructor
s1.name = "John";
s1.marks = 85;
s1.grade = 'A';
Student s2("Pikku"); // string constructor
s2.marks = 90;
s2.grade = 'B';
Student s3("Pikku", 90); // string + int
s3.grade = 'B';
Student s4("Atul", 95, 'A'); // string, int, char
Student s5('C', 95, "Amit"); // char, int, string
Student s6 = s1; // copy constructor (default)
s6.name = "Vipin";
Student s7(s2); // another copy
s7.name = "Khushi";
// Print all students
cout << "Name: " << s1.name << ", Marks: " << s1.marks << ", Grade: " << s1.grade << endl;
cout << "Name: " << s2.name << ", Marks: " << s2.marks << ", Grade: " << s2.grade << endl;
cout << "Name: " << s3.name << ", Marks: " << s3.marks << ", Grade: " << s3.grade << endl;
cout << "Name: " << s4.name << ", Marks: " << s4.marks << ", Grade: " << s4.grade << endl;
cout << "Name: " << s5.name << ", Marks: " << s5.marks << ", Grade: " << s5.grade << endl;
cout << "Name: " << s6.name << ", Marks: " << s6.marks << ", Grade: " << s6.grade << endl;
cout << "Name: " << s7.name << ", Marks: " << s7.marks << ", Grade: " << s7.grade << endl;
return 0;
}