File tree Expand file tree Collapse file tree 3 files changed +26
-13
lines changed Expand file tree Collapse file tree 3 files changed +26
-13
lines changed Original file line number Diff line number Diff line change 1
1
* .exe
2
-
2
+ .vscode
3
+ .gitignore
Original file line number Diff line number Diff line change 4
4
#include < iostream>
5
5
using namespace std ;
6
6
7
+ template <class T >
7
8
class Arithematic
8
9
{
9
10
private:
10
- int A;
11
- int B;
11
+ T A;
12
+ T B;
12
13
13
14
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 ();
17
18
};
18
19
19
- Arithematic::Arithematic (int newA, int newB)
20
+ template <class T >
21
+
22
+ Arithematic<T>::Arithematic(T newA, T newB)
20
23
{
21
24
this ->A = newA;
22
25
this ->B = newB;
23
26
}
24
27
25
- int Arithematic ::add ()
28
+ template <class T >
29
+
30
+ T Arithematic<T>::add()
26
31
{
27
32
return A + B;
28
33
}
29
- int Arithematic ::sub ()
34
+
35
+ template <class T >
36
+
37
+ T Arithematic<T>::sub()
30
38
{
31
39
return A - B;
32
40
}
33
41
34
42
int main ()
35
43
{
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 ();
39
51
}
40
52
41
53
// output :
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ struct Rectangle
9
9
void area_of_rectangle (struct Rectangle R)
10
10
{
11
11
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
13
13
}
14
14
15
15
int main ()
You can’t perform that action at this time.
0 commit comments