Skip to content

Commit 31b4565

Browse files
updated code
1 parent 8ee1c29 commit 31b4565

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.exe
2-
2+
.vscode
3+
.gitignore

Basics/GenericClassC++/template_class.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,50 @@
44
#include <iostream>
55
using namespace std;
66

7+
template <class T>
78
class Arithematic
89
{
910
private:
10-
int A;
11-
int B;
11+
T A;
12+
T B;
1213

1314
public:
14-
Arithematic(int newA, int newB);
15-
int add();
16-
int sub();
15+
Arithematic(T newA, T newB);
16+
T add();
17+
T sub();
1718
};
1819

19-
Arithematic::Arithematic(int newA, int newB)
20+
template <class T>
21+
22+
Arithematic<T>::Arithematic(T newA, T newB)
2023
{
2124
this->A = newA;
2225
this->B = newB;
2326
}
2427

25-
int Arithematic ::add()
28+
template <class T>
29+
30+
T Arithematic<T>::add()
2631
{
2732
return A + B;
2833
}
29-
int Arithematic ::sub()
34+
35+
template <class T>
36+
37+
T Arithematic<T>::sub()
3038
{
3139
return A - B;
3240
}
3341

3442
int main()
3543
{
36-
Arithematic AR(15, 5);
37-
cout << "Sum : " << AR.add() << endl;
38-
cout << "Sub : " << AR.sub();
44+
Arithematic<int> AR1(15, 5);
45+
cout << "Sum : " << AR1.add() << endl;
46+
cout << "Sub : " << AR1.sub() << endl;
47+
48+
Arithematic<float> AR2(12.6, 5.2);
49+
cout << "Sum : " << AR2.add() << endl;
50+
cout << "Sub : " << AR2.sub();
3951
}
4052

4153
// output :

Basics/Structure/pass_by_value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct Rectangle
99
void area_of_rectangle(struct Rectangle R)
1010
{
1111
cout << R.length * R.breadth;
12-
R.breadth = 20; // modify the value of breadth won't change the actual structure
12+
R.breadth = 20; // modify the value of breadth won't change the actual structure memebers
1313
}
1414

1515
int main()

0 commit comments

Comments
 (0)