Skip to content

Commit 0a0f2f3

Browse files
committed
concepts+code
1 parent 977ccc2 commit 0a0f2f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2006
-0
lines changed

OOPS/Bank.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <iostream>
2+
using namespace std;
3+
class Bank
4+
{
5+
private:
6+
float amount;
7+
public:
8+
void openAccount()
9+
{
10+
amount = 250;
11+
}
12+
13+
void deposit(float amt)
14+
{
15+
if( amt >= 10000)
16+
amt = amt - ( amt * 0.02 ) ; // 2% education tax
17+
amount = amount + amt;
18+
}
19+
20+
void withdraw( float amt )
21+
{
22+
if ( amount - amt < 250 )
23+
cout <<"Not enough balance" << endl;
24+
else
25+
amount = amount - amt;
26+
}
27+
28+
void getBalance()
29+
{
30+
cout << "Balance = " << amount << endl;
31+
}
32+
};
33+
34+
int main()
35+
{
36+
Bank sam , alan;
37+
sam.openAccount();
38+
alan.openAccount();
39+
sam.deposit(50000);
40+
41+
sam.getBalance();
42+
alan.getBalance();
43+
44+
return 0;
45+
}
46+
47+
48+

OOPS/Mobile.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
using namespace std;
3+
class Mobile
4+
{
5+
private:
6+
int curr;
7+
public:
8+
void activate()
9+
{
10+
curr = 10;
11+
}
12+
13+
void recharge( int v )
14+
{
15+
curr = curr + v;
16+
}
17+
18+
int myBalance()
19+
{
20+
return curr;
21+
}
22+
};
23+
24+
int main()
25+
{
26+
Mobile s1 , s2;
27+
s1.activate(); // 10 rs
28+
s2.activate();
29+
s1.recharge( 10 );
30+
cout << s1.myBalance( );
31+
return 0;
32+
}
33+
34+
35+

OOPS/Time.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
using namespace std;
3+
class Time
4+
{
5+
private:
6+
int h , m , s;
7+
public:
8+
void setTime( int hour , int min , int sec )
9+
{
10+
if( hour <=24 )
11+
h = hour;
12+
else
13+
h = 0;
14+
15+
if( min <= 60 )
16+
m = min;
17+
else
18+
m = 0;
19+
20+
if( sec <= 60 )
21+
s = sec;
22+
else
23+
s = 0;
24+
}
25+
26+
void printMessage()
27+
{
28+
if( h < 12 )
29+
cout << "Good morning" << endl;
30+
else if( h < 16 )
31+
cout << "Good afternoon" << endl;
32+
else
33+
cout << "Good evening" << endl;
34+
}
35+
};
36+
37+
int main()
38+
{
39+
Time t;
40+
t.setTime( 10 , 29 , 30 );
41+
t.printMessage();
42+
return 0;
43+
}
44+
45+
46+
File renamed without changes.

main.cpp basic-programs/main.cpp

File renamed without changes.
File renamed without changes.
File renamed without changes.

classes/compare_time.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include<iostream>
2+
using namespace std;
3+
class Time
4+
{
5+
private:
6+
int h , m , s;
7+
void Increment()
8+
{
9+
s++;
10+
if( s == 60 )
11+
{
12+
s = 0;
13+
m++;
14+
if( m == 60 )
15+
{
16+
m = 0;
17+
h++;
18+
if( h == 24 )
19+
h = 0;
20+
}
21+
}
22+
}
23+
public:
24+
void setTime( int hour , int min , int sec )
25+
{
26+
h = hour;
27+
m = min;
28+
s = sec;
29+
}
30+
31+
void operator ++( ) // preincrement
32+
{
33+
Increment();
34+
cout << h << ":" << m << ":" << s << endl;
35+
}
36+
37+
void operator ++(int) // post increment
38+
{
39+
cout << h << ":" << m << ":" << s << endl;
40+
Increment();
41+
}
42+
43+
void display()
44+
{
45+
cout << h << ":" << m << ":" << s << endl;
46+
}
47+
48+
int operator == ( Time arg)
49+
{
50+
return h==arg.h && m==arg.m && s==arg.s ? 1 : 0;
51+
}
52+
};
53+
54+
55+
int main()
56+
{
57+
Time alarm , systime;
58+
alarm.setTime( 11 , 30 , 45 );
59+
systime.setTime( 23 , 20 , 50);
60+
61+
for( ; ; )
62+
{
63+
systime++;
64+
systime.display();
65+
if( systime == alarm)
66+
{
67+
cout << "Ding dong....." << endl;
68+
break;
69+
}
70+
}
71+
72+
}
73+
74+
75+
76+
77+
78+

classes/constructor.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class Myclass
5+
{
6+
public:
7+
Myclass(){
8+
cout<<"Non parameterized constructor called.. "<<endl;
9+
}
10+
Myclass(int a){
11+
cout<<"Parameterized constructor called.. "<<endl;
12+
}
13+
};
14+
15+
int main()
16+
{
17+
Myclass m1;
18+
Myclass m2(10);
19+
}

classes/op_overloading.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include<iostream>
2+
using namespace std;
3+
class Employ
4+
{
5+
private:
6+
int empno , sal , exp;
7+
public:
8+
friend istream& operator >> ( istream &in , Employ &arg)
9+
{
10+
cout << "Enter employ number, experience, and salary"<< endl;
11+
in >> arg.empno >> arg.exp >> arg.sal;
12+
return in;
13+
}
14+
15+
friend ostream& operator << ( ostream &out , Employ &arg)
16+
{
17+
out << "---------------------------" << endl;
18+
out << "Employ number :" << arg.empno << endl;
19+
out << "Experience :" << arg.exp << endl;
20+
out << "Salary :" << arg.sal << endl;
21+
out << "---------------------------" << endl;
22+
return out;
23+
}
24+
25+
int operator == ( Employ arg )
26+
{
27+
return exp == arg.exp ? 1 : 0;
28+
}
29+
30+
int operator != ( Employ arg )
31+
{
32+
return exp != arg.exp ? 1 : 0;
33+
}
34+
35+
int operator < ( Employ arg )
36+
{
37+
return exp < arg.exp ? 1 : 0;
38+
}
39+
40+
int operator > ( Employ arg )
41+
{
42+
return exp > arg.exp ? 1 : 0;
43+
}
44+
45+
void operator +=( int val )
46+
{
47+
sal = sal + val;
48+
}
49+
};
50+
51+
int main()
52+
{
53+
Employ e1 , e2;
54+
cin >> e1 >> e2;
55+
if( e1 != e2 )
56+
{
57+
if( e1 > e2 )
58+
e1+=5000;
59+
else
60+
e2+=5000;
61+
}
62+
else
63+
{
64+
e1+=5000;
65+
e2+=5000;
66+
}
67+
cout << e1 << e2;
68+
return 0;
69+
}
70+
71+
72+
73+
74+
75+

classes/op_overloadingbest.cpp

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include<iostream>
2+
using namespace std;
3+
class Employ
4+
{
5+
private:
6+
int empno , sal , exp;
7+
public:
8+
void read()
9+
{
10+
cout << "Enter employ number, experience and salary"<< endl;
11+
cin >> empno >> exp >> sal;
12+
}
13+
void write()
14+
{
15+
cout << "---------------------------" << endl;
16+
cout << "Employ number :" << empno << endl;
17+
cout << "Experience :" << exp << endl;
18+
cout << "Salary :" << sal << endl;
19+
cout << "---------------------------" << endl;
20+
}
21+
22+
int operator == ( Employ arg )
23+
{
24+
return exp == arg.exp ? 1 : 0;
25+
}
26+
27+
int operator != ( Employ arg )
28+
{
29+
return exp != arg.exp ? 1 : 0;
30+
}
31+
32+
int operator < ( Employ arg )
33+
{
34+
return exp < arg.exp ? 1 : 0;
35+
}
36+
37+
int operator > ( Employ arg )
38+
{
39+
return exp > arg.exp ? 1 : 0;
40+
}
41+
42+
void operator +=( int val )
43+
{
44+
sal = sal + val;
45+
}
46+
47+
Employ operator + ( int val )
48+
{
49+
sal = sal + val;
50+
return *this;
51+
}
52+
};
53+
54+
int main()
55+
{
56+
Employ e1 , e2;
57+
e1.read();
58+
e2.read();
59+
if( e1 != e2 )
60+
{
61+
if( e1 < e2 )
62+
e2+=5000;
63+
else
64+
e1+=5000;
65+
}
66+
else
67+
{
68+
e1+=5000;
69+
e2 = e2 + 5000;
70+
}
71+
72+
e1.write();
73+
e2.write();
74+
75+
return 0;
76+
}
77+
78+
79+
80+
81+
82+

0 commit comments

Comments
 (0)