-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor.cpp
More file actions
33 lines (28 loc) · 759 Bytes
/
constructor.cpp
File metadata and controls
33 lines (28 loc) · 759 Bytes
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
#include <bits/stdc++.h>
using namespace std;
class Student
{
public:
int roll;
int cls;
double gpa;
Student(int roll, int cls, double gpa)
{
// Using Arrow sign
// this->roll = roll;
// this->cls = cls;
// this->gpa = gpa;
// Using dot symbol (without arrow sign (`this` keyword is a pointer of this class))
(*this).roll = roll;
(*this).cls = cls;
(*this).gpa = gpa;
}
};
int main()
{
Student rahim(45, 9, 2.00);
Student karim(46, 10, 3.50);
cout << rahim.cls << " " << fixed << setprecision(2) << rahim.gpa << " " << rahim.roll << endl;
cout << karim.cls << " " << fixed << setprecision(2) << karim.gpa << " " << karim.roll << endl;
return 0;
}