-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent2.cpp
63 lines (57 loc) · 1.25 KB
/
Student2.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
#include <iostream>
using namespace std;
int obj;
class Student2
{
private:
char name[100];
double marks[3];
double total;
public:
void display();
Student2()
{
cout << "\nConstructor " << ++obj << " called.";
cout << "\nEnter name of Student: ";
cin >> name;
for (int i = 0; i < 3; i++)
{
cout << "Enter marks of Subject " << i + 1 << " : ";
cin >> marks[i];
}
total = 0.0;
}
Student2(double mrks[3])
{
cout << "\nConstructor " << ++obj << "called.";
cout << "\nEnter name of Student: ";
cin >> name;
for (int i = 0; i < 3; i++)
{
marks[i] = mrks[i];
}
}
~Student2()
{
cout << "Destructor " << obj-- << " called." << endl;
}
};
void Student2::display()
{
cout << "\nStudent Name : " << name;
for (int i = 0; i < 3; i++)
{
total += marks[i];
}
cout << "\nTotal marks = " << total << endl;
}
int main()
{
double mr[] = {80, 90, 100};
Student2 s1(mr);
s1.display();
cout << "\n------------------------------------------";
Student2 s2;
s2.display();
return 0;
}