Skip to content

Commit 3147b05

Browse files
committed
populated tutorials
1 parent 030a39b commit 3147b05

File tree

177 files changed

+22704
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+22704
-1
lines changed

00_Versioning/00_Versioning.pptx

302 KB
Binary file not shown.

00_Versioning/code/testDocument.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
second commit

01_Setup/01_Setup.pptx

99.4 KB
Binary file not shown.

01_Setup/code/hello_world.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
\brief 01_CMake: Introducing CMake to the wild
3+
*/
4+
#include <algorithm>
5+
#include <iostream>
6+
7+
int main()
8+
{
9+
std::cout << "Hello World!\n";
10+
11+
return EXIT_SUCCESS;
12+
}

02_CMake/CMake.pptx

98.9 KB
Binary file not shown.

02_CMake/code/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
2+
3+
# Assign a separate variable for project name
4+
SET( PROJECT_NAME CMake_Tutorial )
5+
6+
# Change this if you want different executable name
7+
SET( EXE_NAME ${PROJECT_NAME} )
8+
9+
# Add definitions to use inside source code
10+
ADD_DEFINITIONS( -DPROJECT_NAME="${PROJECT_NAME}" )
11+
12+
# Set project name
13+
PROJECT( ${PROJECT_NAME}
14+
VERSION 1.0.0
15+
)
16+
17+
# Add all include directories
18+
INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src )
19+
20+
ADD_EXECUTABLE(
21+
${EXE_NAME} # executable or library name here
22+
${PROJECT_SOURCE_DIR}/src/main.cxx # the file which contains the entry to the program
23+
)

02_CMake/code/src/main.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
\brief 01_CMake: Introducing CMake to the wild
3+
*/
4+
#include <algorithm>
5+
#include <iostream>
6+
7+
int main()
8+
{
9+
std::cout << "Hello World!\n";
10+
11+
return EXIT_SUCCESS;
12+
}

03_OOP/03_OOP.pptx

142 KB
Binary file not shown.

03_OOP/code/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
3+
# Assign a separate variable for project name
4+
SET( PROJECT_NAME OOP_Tutorial )
5+
6+
# Change this if you want different executable name
7+
SET( EXE_NAME ${PROJECT_NAME} )
8+
9+
# Add definitions to use inside source code
10+
ADD_DEFINITIONS( -DPROJECT_NAME="${PROJECT_NAME}" )
11+
12+
# Set project name
13+
PROJECT( ${PROJECT_NAME} )
14+
15+
# Set source code directory
16+
SET( SOURCE_DIRECTORY ${PROJECT_SOURCE_DIR}/src )
17+
SET( CLASS_DIRECTORY ${SOURCE_DIRECTORY}/classes )
18+
19+
# Add all include directories
20+
INCLUDE_DIRECTORIES(
21+
${CMAKE_CURRENT_BINARY_DIR}
22+
${CMAKE_CURRENT_SOURCE_DIR}
23+
${SOURCE_DIRECTORY}
24+
${CLASS_DIRECTORY}
25+
)
26+
27+
# Add sources to executable
28+
ADD_EXECUTABLE( ${EXE_NAME} ${SOURCE_DIRECTORY}/main.cxx)

03_OOP/code/src/classes/add.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include "base.h"
4+
5+
6+
class add:
7+
public base // add class inherits from "base"
8+
{
9+
public:
10+
//! Default Constructor
11+
explicit add();
12+
13+
//! Actual Constructor
14+
explicit add(int n1, int n2): base(n1, n2)
15+
{
16+
}
17+
18+
//! Implement the virtual function
19+
void op()
20+
{
21+
m_result = m_num1 + m_num2;
22+
}
23+
24+
//! Since destructor is virtual, it need to be implemented
25+
virtual ~add()
26+
{
27+
}
28+
};

03_OOP/code/src/classes/base.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
//! Stadard headers
4+
#include <stdio.h>
5+
#include <iostream>
6+
7+
class base
8+
{
9+
public: //! interface of "base"
10+
11+
//! Default Constructor
12+
explicit base();
13+
14+
//! Actual Constructor
15+
explicit base(int n1, int n2)
16+
{
17+
m_num1 = n1;
18+
m_num2 = n2;
19+
}
20+
21+
//! Destructor
22+
virtual ~base()
23+
{
24+
}
25+
26+
//! set the new variables
27+
void setNewVariables( int n1, int n2 )
28+
{
29+
m_num1 = n1;
30+
m_num2 = n2;
31+
}
32+
33+
//! Pure virtual function
34+
virtual void op() = 0;
35+
36+
//! Output function
37+
int getResult()
38+
{
39+
return m_result;
40+
}
41+
42+
protected:
43+
int m_num1, m_num2, m_result;
44+
};

03_OOP/code/src/classes/difference.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include "base.h"
4+
#include <math.h>
5+
6+
class difference:
7+
public base
8+
{
9+
public:
10+
//! Default Constructor
11+
explicit difference();
12+
13+
//! Actual Constructor
14+
explicit difference(int n1, int n2): base(n1, n2)
15+
{
16+
}
17+
18+
//! Implement the virtual function
19+
void op()
20+
{
21+
m_result = std::abs(m_num1 - m_num2);
22+
}
23+
24+
//! Since destructor is virtual, it need to be implemented
25+
virtual ~difference()
26+
{
27+
}
28+
};

03_OOP/code/src/main.cxx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
\brief 03_OOP: Object oriented programming example
3+
4+
This program illustrates some basic OOP concepts like classes, inheritance,
5+
encapsulation, etc.
6+
*/
7+
#include "base.h"
8+
#include "add.h"
9+
#include "difference.h"
10+
11+
int main()
12+
{
13+
int x,y;
14+
std::cout << "\nEnter two numbers separated by space {press Ctrl+Z to Exit}:\n";
15+
std::cin >> x >> y;
16+
add addition_object(x, y);
17+
difference difference_object(x,y);
18+
19+
base *m;
20+
m = &addition_object;
21+
m->op();
22+
m->getResult();
23+
std::cout << "Result of Addition operation = " << m->getResult() << std::endl;
24+
25+
m = &difference_object;
26+
m->op();
27+
m->getResult();
28+
std::cout << "Result of Difference operation = " << m->getResult() << std::endl;
29+
30+
m = NULL;
31+
32+
std::cin.ignore();
33+
std::cin.get();
34+
35+
return EXIT_SUCCESS;
36+
}

04_STL/STL.pptx

123 KB
Binary file not shown.

04_STL/code/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
3+
# Assign a separate variable for project name
4+
SET( PROJECT_NAME STL_Tutorial )
5+
6+
# Change this if you want different executable name
7+
SET( EXE_1 Template_Tutorial )
8+
SET( EXE_2 STL_Tutorial )
9+
10+
# Add definitions to use inside source code
11+
ADD_DEFINITIONS( -DPROJECT_NAME="${PROJECT_NAME}" )
12+
13+
# Set project name
14+
PROJECT( ${PROJECT_NAME} )
15+
16+
# Set source code directory
17+
SET( SOURCE_DIRECTORY ${PROJECT_SOURCE_DIR}/src )
18+
19+
# Add all include directories
20+
INCLUDE_DIRECTORIES(
21+
${CMAKE_CURRENT_BINARY_DIR}
22+
${CMAKE_CURRENT_SOURCE_DIR}
23+
${SOURCE_DIRECTORY}
24+
)
25+
26+
# Add sources to executable
27+
ADD_EXECUTABLE( ${EXE_1} ${SOURCE_DIRECTORY}/template.cxx)
28+
29+
# Add sources to executable
30+
ADD_EXECUTABLE( ${EXE_2} ${SOURCE_DIRECTORY}/stl.cxx)

04_STL/code/src/stl.cxx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
\brief 07_STL: STL example
3+
4+
This program illustrates some basic STL concepts like vectors and some of its functions
5+
*/
6+
#include <iostream>
7+
#include <vector>
8+
9+
#include <string>
10+
#include <algorithm>
11+
12+
using namespace std;
13+
14+
template<typename TContainerType>
15+
bool findInVector( std::vector<TContainerType> &vector_to_search_in,
16+
TContainerType element_to_search_for )
17+
{
18+
typename std::vector<TContainerType>::const_iterator iterator =
19+
std::find(vector_to_search_in.begin(), vector_to_search_in.end(), element_to_search_for);
20+
if( iterator != vector_to_search_in.end() )
21+
{
22+
return true;
23+
}
24+
else
25+
return false;
26+
}
27+
28+
int main()
29+
{
30+
// create a vector to store int
31+
vector<int> vec;
32+
33+
// display the original size of vec
34+
cout << "vector size = " << vec.size() << endl;
35+
36+
// push 5 values into the vector
37+
for (unsigned int i = 0; i < 5; i++)
38+
{
39+
vec.push_back(i);
40+
}
41+
42+
// display extended size of vec
43+
cout << "extended vector size = " << vec.size() << endl;
44+
45+
// access 5 values from the vec
46+
for (auto i = 0; i < 5; i++)
47+
{
48+
cout << "value of vec [" << i << "] = " << vec[i] << endl;
49+
}
50+
51+
// use iterator to access the values
52+
vector<int>::iterator v = vec.begin();
53+
while ( v != vec.end())
54+
{
55+
cout << "value of v = " << *v << endl;
56+
v++;
57+
}
58+
59+
for (auto it = vec.begin(); it != vec.end(); ++it)
60+
{
61+
cout << "another way to get value of v = " << *it << endl;
62+
}
63+
64+
if (findInVector<int>(vec, 2))
65+
cout << "found!\n";
66+
67+
return 0;
68+
}

04_STL/code/src/template.cxx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
\file template.cxx
3+
4+
\brief 07_STL: Template example
5+
6+
This program illustrates usage of function template
7+
*/
8+
#include <iostream>
9+
10+
// define template function
11+
template <typename VarType>
12+
VarType add( VarType a, VarType b )
13+
{
14+
return (a+b);
15+
}
16+
17+
int main()
18+
{
19+
// initialize variables
20+
int a = 1, b = 2;
21+
float x = 1.0, y = 2.0;
22+
double m = 3.0, n = 4.0;
23+
char p = 1, q = 2;
24+
25+
// perform operation
26+
int c = add< int >( a, b );
27+
float z = add< float >( x, y );
28+
double o = add< double >( m, n );
29+
char r = add< char >( p, q );
30+
31+
// display results
32+
std::cout << "Int result between " << a << " and " << b << " : " << c << "\n";
33+
std::cout << "Float result " << x << " and " << y << " : " << z << "\n";
34+
std::cout << "Double result " << m << " and " << n << " : " << o << "\n";
35+
std::cout << "Char result " << p << " and " << q << " : " << r << "\n";
36+
37+
return EXIT_SUCCESS;
38+
}
39+

05_CPP11/CPP11_contd.pptx

109 KB
Binary file not shown.

05_CPP11/code/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
2+
3+
SET( PROJECT_NAME CPP11_Tutorial ) # change project name here
4+
5+
SET( SOURCE_DIRECTORY ${PROJECT_SOURCE_DIR}/src )
6+
7+
IF( CMAKE_COMPILER_IS_GNUCXX )
8+
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
9+
ENDIF()
10+
11+
INCLUDE_DIRECTORIES(
12+
${CMAKE_CURRENT_BINARY_DIR}
13+
${CMAKE_CURRENT_SOURCE_DIR}
14+
)
15+
16+
ADD_EXECUTABLE(
17+
UniquePtr_Test
18+
${SOURCE_DIRECTORY}/uniqueptr.cxx
19+
)
20+
21+
ADD_EXECUTABLE(
22+
SharedPtr_Test
23+
${SOURCE_DIRECTORY}/sharedptr.cxx
24+
)
25+
26+
ADD_EXECUTABLE(
27+
LambdaFunc_Test
28+
${SOURCE_DIRECTORY}/lambda.cxx
29+
)

0 commit comments

Comments
 (0)