-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloworld.cpp
More file actions
98 lines (91 loc) · 1.69 KB
/
helloworld.cpp
File metadata and controls
98 lines (91 loc) · 1.69 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<iostream>
using namespace std;
class student{
public :
int rollnum;
private:
int age;
public:
// default constructor
student(){
cout<<"constructor called"<<endl;
}
//parametrized
student(int r){
cout<<"constrctor 2"<<endl;
rollnum=r;
}
//
student(int a,int r){
cout<<"this : "<<this<<endl;
cout<<"constructor called"<<endl;
age = a;
rollnum = r;
}
void display()
{
cout<<age<<" "<<rollnum<<endl;
}
int getAge(){
return age;
}
void setAge(int a,int password){
if(password != 123){
return;
}
if (a<0){
return;
}
age = a;
}
};
/*
int main(){
student s1;
s1.display();
student s2;
student *s3 = new student;
s3->display();
cout<<"parametrized constructor demo "<<endl;
student s4(10);
s4.display();
student s6(20,102);
cout<<"cons 3 called"<<endl;
s6.display();
}
*/
/*int main(){
student s1;
student *s2 = new student;
s1.setAge(20);
s2->setAge(24);
s1.display();
s2->display();
}*/
/*
int main()
{
//statically alloctaion
student s1;
student s2;
// s1.age=14;
s1.rollnum=45;
//s2.rollnum=47;
cout<<"s1 age :"<<s1.getAge<<endl;
cout<<"s1 rollnum :"<<s1.rollnum<<endl;
s1.display();
s2.display();
//s2.age=15;
// dyanmically allocation
student *s6 = new student;
// (*s6).age=47;
(*s6).rollnum=54;
(*s6).display();
cout<<"s6 age :"<<s6->getAge<<endl;
s6->rollnum=104;
s6->display();
}*/
int main(){
student s1(10,155);
cout<<" address of this"<<&s1<<endl;
}