Last active
October 16, 2017 12:58
-
-
Save hjnowakowski/c09622181190e0e3e0e6ff3b40b5d932 to your computer and use it in GitHub Desktop.
C++ solutions, semestr 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void print_array(ostream& os, vector<int> a, int n){ | |
for (int i = 0; i < n; i++) { | |
os << a[i] << endl; | |
} | |
} | |
int main() { | |
// create a vector to store int, implement vector class | |
vector<int> vec; | |
int i; | |
//task 1 | |
// push 5 values into the vector | |
for(i = 0; i < 5; i++) { | |
vec.push_back(i); | |
} | |
print_array(cout, vec, vec.size()); | |
//task 2 | |
vec.erase (vec.begin(), vec.begin()+5); | |
print_array(cout, vec, vec.size()); | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void print_array(ostream& os, int* a, int n){ | |
for (int i = 0; i < n; i++) { | |
os << a[i] << endl; | |
} | |
} | |
int main() { | |
// task 1 | |
int n = 5; | |
int a[n]; | |
a[0] = 1; | |
a[1] = 4; | |
a[2] = 5; | |
a[3] = 6; | |
a[4] = 132; | |
print_array(cout, a, n); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int main() { | |
int * array = new int[20]; | |
int n = 100; | |
for (int i = 0; i < 20; i++) { | |
array[i] = n; | |
n++; | |
} | |
cout << array[15] << endl; | |
delete[] array; | |
int * x = new int[20]; | |
cout << x[15] << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment