Skip to content

Commit d216a93

Browse files
committed
update
1 parent 301e0c3 commit d216a93

File tree

7 files changed

+399
-0
lines changed

7 files changed

+399
-0
lines changed

OOPS/constructors.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#ifdef ONLINE_JUDGE
4+
#define DISABLE_STACK_SIZE_CHANGE
5+
#endif
6+
#ifndef DISABLE_STACK_SIZE_CHANGE
7+
#include <sys/resource.h>
8+
#endif
9+
typedef long long ll;
10+
const ll MOD = 1000000007;
11+
#define pb push_back
12+
#define ff first
13+
#define ss second
14+
#define nl "\n"
15+
unordered_map<int,vector<int>>adj;
16+
unordered_map<int,bool>visi;
17+
#define set_bits(x) __builtin_popcountll(x)
18+
#define all(x) (x).begin(), (x).end()
19+
#define debug(x) cerr<<#x<<" "<<x<<endl;
20+
#define loop(i,a,b) for(int i=(a);i<(b);i++)
21+
#define print(x) for(auto it:(x)) cout<<(it)<<" "; cout<<endl;
22+
#define showadj for (auto it : adj) { cout << it.ff << " ->"; for (auto i : it.ss) cout << i << " "; cout << endl; }
23+
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
24+
template<typename T> T binpow(T base,T power,T mod){ ll ans=1; base = base % mod;while(power){if(power&1) ans=(ans*base)%mod; base=((base*base)%mod); power>>=1;}return ans;}
25+
26+
class demo
27+
{
28+
int a,b;
29+
public:
30+
//default constructor called
31+
demo()
32+
{
33+
a=10;
34+
b=20;
35+
}
36+
};
37+
class demo2
38+
{
39+
int c;
40+
public:
41+
42+
}
43+
//default constructor
44+
demo2::demo2()
45+
{
46+
c=10;
47+
}
48+
49+
50+
class paraconst
51+
{
52+
int a,b;
53+
public:
54+
//parametized constructor
55+
paraconst(int n,int m)
56+
{
57+
a=n;
58+
b=m;
59+
}
60+
};
61+
class cupy
62+
{
63+
int a;
64+
public:
65+
cupy()
66+
{
67+
a=10;
68+
}//copy constructor use to copy the obj to other obj of ssame class
69+
//cupy a; cupy b(a); like this data is copied;
70+
cupy(cupy&temp)
71+
{
72+
a=temp.a;
73+
}
74+
}
75+
int main()
76+
{
77+
ios_base::sync_with_stdio(0);cin.tie(0);
78+
#ifndef DISABLE_STACK_SIZE_CHANGE
79+
rlimit rlim;
80+
if (getrlimit(RLIMIT_STACK, &rlim) != 0) {return 1;}
81+
rlim.rlim_cur = 1024 * 1024 * 1024;
82+
if (setrlimit(RLIMIT_STACK, &rlim) != 0) {return 2;}
83+
#endif
84+
85+
86+
}
87+

OOPS/heriachcal inheritance .cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#ifdef ONLINE_JUDGE
4+
#define DISABLE_STACK_SIZE_CHANGE
5+
#endif
6+
#ifndef DISABLE_STACK_SIZE_CHANGE
7+
#include <sys/resource.h>
8+
#endif
9+
typedef long long ll;
10+
const ll MOD = 1000000007;
11+
#define pb push_back
12+
#define ff first
13+
#define ss second
14+
#define nl "\n"
15+
unordered_map<int,vector<int>>adj;
16+
unordered_map<int,bool>visi;
17+
#define set_bits(x) __builtin_popcountll(x)
18+
#define all(x) (x).begin(), (x).end()
19+
#define debug(x) cerr<<#x<<" "<<x<<endl;
20+
#define loop(i,a,b) for(int i=(a);i<(b);i++)
21+
#define print(x) for(auto it:(x)) cout<<(it)<<" "; cout<<endl;
22+
#define showadj for (auto it : adj) { cout << it.ff << " ->"; for (auto i : it.ss) cout << i << " "; cout << endl; }
23+
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
24+
template<typename T> T binpow(T base,T power,T mod){ ll ans=1; base = base % mod;while(power){if(power&1) ans=(ans*base)%mod; base=((base*base)%mod); power>>=1;}return ans;}
25+
26+
class a
27+
{
28+
int x;
29+
public:
30+
int y=10;
31+
32+
};
33+
class b: public a
34+
{
35+
public:
36+
int z=10+y;
37+
};
38+
//mulit level a used by c and b both
39+
class c:public a
40+
{
41+
int a=50;
42+
public:
43+
void show()
44+
{
45+
cout<<y+a<<endl;
46+
}
47+
};
48+
49+
int main()
50+
{
51+
ios_base::sync_with_stdio(0);cin.tie(0);
52+
#ifndef DISABLE_STACK_SIZE_CHANGE
53+
rlimit rlim;
54+
if (getrlimit(RLIMIT_STACK, &rlim) != 0) {return 1;}
55+
rlim.rlim_cur = 1024 * 1024 * 1024;
56+
if (setrlimit(RLIMIT_STACK, &rlim) != 0) {return 2;}
57+
#endif
58+
c obj;
59+
obj.show();
60+
61+
62+
}
63+

OOPS/imp.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
->funtion overiding /method overiding means having same name of funtionn in both base and derived class and the funtion will show accoring to the object of which class called !!to solve this if obj is of b class to call a then obj.a::display() done!!
2+
->to change the constructors of the patent class using child as
3+
class c:public a,pubic b
4+
{
5+
c(int q,int z,int s):a(z),b(s);done!!!
6+
}

OOPS/multilevel inhertance.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#ifdef ONLINE_JUDGE
4+
#define DISABLE_STACK_SIZE_CHANGE
5+
#endif
6+
#ifndef DISABLE_STACK_SIZE_CHANGE
7+
#include <sys/resource.h>
8+
#endif
9+
typedef long long ll;
10+
const ll MOD = 1000000007;
11+
#define pb push_back
12+
#define ff first
13+
#define ss second
14+
#define nl "\n"
15+
unordered_map<int,vector<int>>adj;
16+
unordered_map<int,bool>visi;
17+
#define set_bits(x) __builtin_popcountll(x)
18+
#define all(x) (x).begin(), (x).end()
19+
#define debug(x) cerr<<#x<<" "<<x<<endl;
20+
#define loop(i,a,b) for(int i=(a);i<(b);i++)
21+
#define print(x) for(auto it:(x)) cout<<(it)<<" "; cout<<endl;
22+
#define showadj for (auto it : adj) { cout << it.ff << " ->"; for (auto i : it.ss) cout << i << " "; cout << endl; }
23+
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
24+
template<typename T> T binpow(T base,T power,T mod){ ll ans=1; base = base % mod;while(power){if(power&1) ans=(ans*base)%mod; base=((base*base)%mod); power>>=1;}return ans;}
25+
26+
class a
27+
{
28+
int x;
29+
public:
30+
int y=10;
31+
32+
};
33+
class b: public a
34+
{
35+
public:
36+
int z=10;
37+
};
38+
class c:public b
39+
{
40+
int a=50;
41+
public:
42+
void show()
43+
{
44+
cout<<y+z+a<<endl;
45+
}
46+
};
47+
48+
int main()
49+
{
50+
ios_base::sync_with_stdio(0);cin.tie(0);
51+
#ifndef DISABLE_STACK_SIZE_CHANGE
52+
rlimit rlim;
53+
if (getrlimit(RLIMIT_STACK, &rlim) != 0) {return 1;}
54+
rlim.rlim_cur = 1024 * 1024 * 1024;
55+
if (setrlimit(RLIMIT_STACK, &rlim) != 0) {return 2;}
56+
#endif
57+
c obj;
58+
obj.show();
59+
60+
61+
}
62+

OOPS/multiple inheritance.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#ifdef ONLINE_JUDGE
4+
#define DISABLE_STACK_SIZE_CHANGE
5+
#endif
6+
#ifndef DISABLE_STACK_SIZE_CHANGE
7+
#include <sys/resource.h>
8+
#endif
9+
typedef long long ll;
10+
const ll MOD = 1000000007;
11+
#define pb push_back
12+
#define ff first
13+
#define ss second
14+
#define nl "\n"
15+
unordered_map<int,vector<int>>adj;
16+
unordered_map<int,bool>visi;
17+
#define set_bits(x) __builtin_popcountll(x)
18+
#define all(x) (x).begin(), (x).end()
19+
#define debug(x) cerr<<#x<<" "<<x<<endl;
20+
#define loop(i,a,b) for(int i=(a);i<(b);i++)
21+
#define print(x) for(auto it:(x)) cout<<(it)<<" "; cout<<endl;
22+
#define showadj for (auto it : adj) { cout << it.ff << " ->"; for (auto i : it.ss) cout << i << " "; cout << endl; }
23+
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
24+
template<typename T> T binpow(T base,T power,T mod){ ll ans=1; base = base % mod;while(power){if(power&1) ans=(ans*base)%mod; base=((base*base)%mod); power>>=1;}return ans;}
25+
26+
class a
27+
{
28+
int x;
29+
public:
30+
int y=10;
31+
32+
};
33+
class b
34+
{
35+
public:
36+
int z=10;
37+
};
38+
class c:public a,public b
39+
{
40+
int a=50;
41+
public:
42+
void show()
43+
{
44+
cout<<y+z+a<<endl;
45+
}
46+
};
47+
48+
int main()
49+
{
50+
ios_base::sync_with_stdio(0);cin.tie(0);
51+
#ifndef DISABLE_STACK_SIZE_CHANGE
52+
rlimit rlim;
53+
if (getrlimit(RLIMIT_STACK, &rlim) != 0) {return 1;}
54+
rlim.rlim_cur = 1024 * 1024 * 1024;
55+
if (setrlimit(RLIMIT_STACK, &rlim) != 0) {return 2;}
56+
#endif
57+
c obj;
58+
obj.show();
59+
60+
61+
}
62+

OOPS/single inheritance.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#ifdef ONLINE_JUDGE
4+
#define DISABLE_STACK_SIZE_CHANGE
5+
#endif
6+
#ifndef DISABLE_STACK_SIZE_CHANGE
7+
#include <sys/resource.h>
8+
#endif
9+
typedef long long ll;
10+
const ll MOD = 1000000007;
11+
#define pb push_back
12+
#define ff first
13+
#define ss second
14+
#define nl "\n"
15+
unordered_map<int,vector<int>>adj;
16+
unordered_map<int,bool>visi;
17+
#define set_bits(x) __builtin_popcountll(x)
18+
#define all(x) (x).begin(), (x).end()
19+
#define debug(x) cerr<<#x<<" "<<x<<endl;
20+
#define loop(i,a,b) for(int i=(a);i<(b);i++)
21+
#define print(x) for(auto it:(x)) cout<<(it)<<" "; cout<<endl;
22+
#define showadj for (auto it : adj) { cout << it.ff << " ->"; for (auto i : it.ss) cout << i << " "; cout << endl; }
23+
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
24+
template<typename T> T binpow(T base,T power,T mod){ ll ans=1; base = base % mod;while(power){if(power&1) ans=(ans*base)%mod; base=((base*base)%mod); power>>=1;}return ans;}
25+
26+
class a
27+
{
28+
int x;
29+
public:
30+
int y=10;
31+
32+
};
33+
// now we can use the y in class b
34+
class b:public a
35+
{
36+
int z=10;
37+
public:
38+
void show()
39+
{
40+
cout<<y+z<<endl;
41+
}
42+
43+
};
44+
45+
int main()
46+
{
47+
ios_base::sync_with_stdio(0);cin.tie(0);
48+
#ifndef DISABLE_STACK_SIZE_CHANGE
49+
rlimit rlim;
50+
if (getrlimit(RLIMIT_STACK, &rlim) != 0) {return 1;}
51+
rlim.rlim_cur = 1024 * 1024 * 1024;
52+
if (setrlimit(RLIMIT_STACK, &rlim) != 0) {return 2;}
53+
#endif
54+
b obj;
55+
obj.show();
56+
57+
58+
}
59+

0 commit comments

Comments
 (0)