The fall 2022 exam from the "C++ for programmers" (INFT2503) course.
Counts towards 100% of the final grade in the subject.
Create the necessary functions so that the following:
cout << concat("hello", "world") << endl;
cout << concat(1, 2) << endl;
cout << concat({"a", "b", "c"}) << endl;
Outputs this:
helloworld
12
abc
Create the necessary classes so that the following:
vector<unique_ptr<Animal>> animals;
animals.emplace_back(make_unique<Elephant>());
animals.emplace_back(make_unique<Elephant>());
animals.emplace_back(make_unique<Pig>());
for(auto &a : animals)
cout << a->makeNoise() << endl;
Outputs this:
Toot!
Toot!
Honk!
Create the necessary functions so that the following:
cout << map_f<int, int>({1, 2, 3}, [](int a){return a * 2;}) << endl;
cout << map_f<float, float>({1, 2.3, 3}, [](float a){return a /2;}) << endl;
cout << map_f<string, string>({"hello", "world"}, [](string s){return s + ".";}) << endl;
cout << map_f<string, int>({"hello", "world"}, [](string s){return s.size();}) << endl;
Outputs this:
{ 2, 4, 6 }
{ 0.5, 1.15, 1.5 }
{ hello., world. }
{ 5, 5 }
Create the necessary classes so that the following:
Matrix<int> m_a({{1, 2}, {3, 4}, {5, 6}});
Matrix<int> m_b({{1, 2, 3}, {4, 5, 6}});
cout << m_a << endl;
cout << m_b << endl;
cout << m_a * m_b << endl;
cout << m_b * m_a << endl;
Matrix<int> m_c({{1, 2}});
Matrix<int> m_d({{2}, {2}});
cout << m_c * m_d << endl;
cout << m_d * m_c << endl;
Outputs this:
[ 1 2 ]
[ 3 4 ]
[ 5 6 ]
[ 1 2 3 ]
[ 4 5 6 ]
[ 9 12 15 ]
[ 19 26 33 ]
[ 29 40 51 ]
[ 22 28 ]
[ 49 64 ]
[ 6 ]
[ 2 4 ]
[ 2 4 ]