-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyConstructor.cpp
More file actions
61 lines (52 loc) · 1.39 KB
/
CopyConstructor.cpp
File metadata and controls
61 lines (52 loc) · 1.39 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
#include <iostream>
#include <cstring>
using namespace std;
class Student {
private:
char name[40];
char gender[10];
char address[40];
char grade[10];
int age;
int totalMarks;
float percentage;
public:
Student() {} // Default Constructor
Student(char n[], char a[], char g[], int ag, int tot, float p, char gr[]) {
// Parameterised Constructor
strcpy(name, n);
strcpy(address, a);
strcpy(gender, g);
strcpy(grade, gr);
age = ag;
totalMarks = tot;
percentage = p;
}
//Copy Constructor
Student(Student &s) {
strcpy(name, s.name);
strcpy(address, s.address);
strcpy(gender, s.gender);
strcpy(grade, s.grade);
age = s.age;
totalMarks = s.totalMarks;
percentage = s.percentage;
}
void output() {
cout << "\nName: " << name << "\nAddress: " << address << "\nGender: " << gender
<< " Age: " << age << " Total Marks: " << totalMarks << " Percentage: " << percentage
<< " Grade: " << grade;
}
// Destructor
~Student() {
cout << "\nObject Destroyed";
}
};
int main() {
Student s1("Sayan Banik", "Coochbehar, West Bengal", "Male", 19, 489, 97.8, "AA");
Student s2(s1);
s1.output();
cout << "\n";
s2.output();
return 0;
}