-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday21.cpp
More file actions
55 lines (43 loc) · 1.07 KB
/
day21.cpp
File metadata and controls
55 lines (43 loc) · 1.07 KB
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
/**
Write a single generic function named printArray;
this function must take an array of generic elements as a parameter
(the exception to this is C++, which takes a vector).
The locked Solution class in your editor tests your function.
Note: You must use generics to solve this challenge. Do not write overloaded functions.
**/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/**
* Name: printArray
* Print each element of the generic vector on a new line. Do not return anything.
* @param A generic vector
**/
// Write your code here
template <class myType>
void printArray (vector<myType> a){
for(int j=0; j < a.size(); j++){
cout << a[j] <<endl;
}
}
int main() {
int n;
cin >> n;
vector<int> int_vector(n);
for (int i = 0; i < n; i++) {
int value;
cin >> value;
int_vector[i] = value;
}
cin >> n;
vector<string> string_vector(n);
for (int i = 0; i < n; i++) {
string value;
cin >> value;
string_vector[i] = value;
}
printArray<int>(int_vector);
printArray<string>(string_vector);
return 0;
}