Skip to content

Commit b534080

Browse files
committed
initial commit
0 parents  commit b534080

25 files changed

+1624
-0
lines changed

2D_vector.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
template<class T>
8+
void print_2D( const vector< vector<T> > & );
9+
10+
11+
int main() {
12+
vector< vector<int> > matrix = { {1,2,3},
13+
{4,5,6},
14+
{7,8,9}};
15+
16+
17+
print_2D<int> ( matrix );
18+
19+
return 0;
20+
}
21+
22+
23+
template<class T>
24+
void print_2D( const vector<vector<T>> &vect ) {
25+
// 1st way of elements access - printing
26+
/*
27+
for(auto& row : vect) {
28+
for(auto& col : row) {
29+
cout << col << " ";
30+
}
31+
cout << endl;
32+
}
33+
*/
34+
// 2nd way of elements access - printing
35+
for( auto row = begin(vect); row != end(vect); row++ ) {
36+
for( auto col = row->begin(); col != row->end(); col++ ) {
37+
cout << *col << " ";
38+
}
39+
cout << endl;
40+
}
41+
// 3rd way of elements access - printing
42+
/*
43+
for(size_t i=0; i<vect.size(); i++) {
44+
for(size_t j=0; j<vect[i].size(); j++) {
45+
cout << vect[i][j] << " ";
46+
}
47+
cout << "\n";
48+
}
49+
*/
50+
}

Being_ex.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <iostream>
2+
//#include <deque>
3+
#include <string>
4+
5+
using namespace std;
6+
7+
template<class T1, class T2, class T3>
8+
class Being {
9+
private:
10+
string name;
11+
T1 age;
12+
T2 height;
13+
T3 weight;
14+
public:
15+
Being(string newName, T1 newAge, T2 newHeight, T3 newWeight)
16+
: name(newName), age(newAge), height(newHeight), weight(newWeight) {}
17+
~Being() {}
18+
string getName() const { return name; }
19+
T1 getAge() const { return age; }
20+
T2 getHeight() const { return height; }
21+
T3 getWeight() const { return weight; }
22+
virtual void hello() {
23+
cout << "Hello WOrld!\n";
24+
}
25+
};
26+
27+
template<class T1, class T2, class T3>
28+
class Person : public Being<T1,T2,T3> {
29+
private:
30+
string city;
31+
public:
32+
Person(string nm, T1 ag, T2 hg, T3 wg, string newCity)
33+
: Being<T1, T2, T3>(nm, ag, hg, wg)
34+
{
35+
city = newCity;
36+
}
37+
~Person() {}
38+
void hello()
39+
{
40+
cout << "\nName: " << Being<T1,T2,T3>::getName() << "\n"
41+
<< "Age: " << Being<T1,T2,T3>::getAge() << "\n"
42+
<< "Height: " << Being<T1,T2,T3>::getHeight() << "\n"
43+
<< "Weight: " << Being<T1,T2,T3>::getWeight() << "\n"
44+
<< "City: " << city << "\n\n";
45+
}
46+
};
47+
48+
49+
50+
int main()
51+
{
52+
Person<int, double, double> diman("Dimos", 26, 1.78, 78.2, "Agrinio");
53+
Person<int, double, double> * dim = &diman;
54+
//diman.hello();
55+
//dim->hello();
56+
57+
const int SIZE = 3;
58+
Person<int, double, double> *arr[SIZE] = {
59+
new Person<int, double, double> ("Dimos", 26, 1.78, 78.2, "Agrinio"),
60+
new Person<int, double, double> ("George", 29, 1.70, 89.5, "Agrinio"),
61+
new Person<int, double, double> ("Andrew", 56, 1.74, 88.4, "Agrinio")
62+
};
63+
64+
for(unsigned i=0; i<SIZE; ++i) {
65+
arr[i]->hello();
66+
}
67+
68+
return 0;
69+
}

0 commit comments

Comments
 (0)