-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassTemplate.cpp
74 lines (67 loc) · 1.57 KB
/
classTemplate.cpp
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
/*
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
*/
// problem : https://www.hackerrank.com/challenges/c-class-templates/problem
// sloution =============================================
/*
template<typename t> class AddElements {
public:
t e1;
string estr;
AddElements(t ef1) :e1(ef1) {
this->estr = ef1;
}
t add(t ei2) {
this->e1 += ei2;
return (this->e1);
}
string concatenate(string el2) {
return (estr + el2);
}
~AddElements() {
}
};
int start_up() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}
int r = start_up();
#define endl '\n';
*/
// ==================================================
/*
int main() {
int n, i;
cin >> n;
for (i = 0; i < n; i++) {
string type;
cin >> type;
if (type == "float") {
double element1, element2;
cin >> element1 >> element2;
AddElements<double> myfloat(element1);
cout << myfloat.add(element2) << endl;
}
else if (type == "int") {
int element1, element2;
cin >> element1 >> element2;
AddElements<int> myint(element1);
cout << myint.add(element2) << endl;
}
else if (type == "string") {
string element1, element2;
cin >> element1 >> element2;
AddElements<string> mystring(element1);
cout << mystring.concatenate(element2) << endl;
}
}
return 0;
}
*/