-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23.2.0 (C++) Parametrized Constructor function().cpp
More file actions
53 lines (43 loc) · 1.23 KB
/
23.2.0 (C++) Parametrized Constructor function().cpp
File metadata and controls
53 lines (43 loc) · 1.23 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
/// Parametrized Constructor function()
#include <iostream>
using namespace std;
class Student
{
public:
int id; float gpa; // Variable _Declare
Student(int x, float y); // Parametrized_Constructor _Declare
Student(); // Default_Constructor _Declare
void display(); // Function _Declare
};
// ClassName + Parametrized_Constructor
Student :: Student(int x, float y)
{
id = x; gpa = y;
}
// ClassName + Default_Constructor
Student :: Student()
{
cout<<" Default Contractor \n";
}
// ClassName + FunctionName_with_ReturnType
void Student :: display()
{
cout<<" Student's ID: "<<id<<" & GPA: "<<gpa<<endl;
}
int main()
{
Student Abir(161722, 3.16); // Initialize values Parametrized Constructor
Abir.display();
Student Himel(161723, 3.45); // Initialize values Parametrized Constructor
Himel.display();
Student DeObj; // Create Object & Call Default_Constructor
return 0;
}
/* ===== Output/Result:
Input:___________________
(Initialization values within a program code)
Output:_________________
Student's ID: 161722 & GPA: 3.16
Student's ID: 161723 & GPA: 3.45
Default Contractor
*/