-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefault, Parameterised Constructor.cpp
More file actions
58 lines (48 loc) · 1.41 KB
/
Default, Parameterised Constructor.cpp
File metadata and controls
58 lines (48 loc) · 1.41 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
#include <iostream>
#include <cstring>
using namespace std;
class Student {
private:
char name[40];
char gender[6];
char address[200]; // Increased size to accommodate longer addresses
char grade[4];
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;
}
void output() {
cout << "\nName: " << name;
cout << "\nAddress: " << address;
cout << "\nGender: " << gender;
cout << "\nAge: " << age;
cout << "\nTotal Marks: " << totalMarks;
cout << "\nPercentage: " << percentage;
cout << "\nGrade: " << grade;
}
// Destructor
~Student() {
cout << "\n\nObject destroyed";
}
};
int main() {
Student s1("Sayan Banik", "Patakura, Ranibagan, H.N. Road, Cooch Behar, West Bengal, India",
"Male", 19, 489, 97.8, "AA");
Student s2("Sohini Chakraborty", "Gandhikalani, Byangchatra Road, Cooch Behar, West Bengal, India",
"Female", 16, 492, 98.1, "AA");
s1.output();
cout << "\n";
s2.output();
return 0;
}