diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da4819e --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.idea* +*.o +*~ +*CMakeFiles +*CMakeCache.txt +Makefile +cmake_install.cmake +.project +.cproject +cmake-build-debug \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ae029c8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 2.6) +project(PCSC-Exercises) + +set(CMAKE_CXX_STANDARD 11) +# set(CMAKE_CXX_FLAGS "-DNDEBUG") + +add_subdirectory(work) +add_subdirectory(solutions) + diff --git a/exercises_pdfs/exo-clion.pdf b/exercises_pdfs/exo-clion.pdf new file mode 100644 index 0000000..2289491 Binary files /dev/null and b/exercises_pdfs/exo-clion.pdf differ diff --git a/exercises_pdfs/exo-git.pdf b/exercises_pdfs/exo-git.pdf new file mode 100644 index 0000000..9970304 Binary files /dev/null and b/exercises_pdfs/exo-git.pdf differ diff --git a/exercises_pdfs/exo-linux.pdf b/exercises_pdfs/exo-linux.pdf new file mode 100644 index 0000000..bb8f46a Binary files /dev/null and b/exercises_pdfs/exo-linux.pdf differ diff --git a/lectures/week1/code_snippets/CMakeLists.txt b/lectures/week1/code_snippets/CMakeLists.txt new file mode 100644 index 0000000..610d3a2 --- /dev/null +++ b/lectures/week1/code_snippets/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 2.6) +project(snippet) + +set(CMAKE_CXX_STANDARD 14) + +file(GLOB SOURCES ${PROJECT_SOURCE_DIR}/*.cpp) +foreach(f ${SOURCES}) + get_filename_component(basename ${f} NAME_WE) + get_filename_component(dir ${f} DIRECTORY) + add_executable(${basename} ${f}) +endforeach() diff --git a/lectures/week1/code_snippets/arrays.cpp b/lectures/week1/code_snippets/arrays.cpp new file mode 100644 index 0000000..40ad35d --- /dev/null +++ b/lectures/week1/code_snippets/arrays.cpp @@ -0,0 +1,21 @@ +int main() { + + int array1[2]; + double array2[2][3]; + + array1[0] = 1; + array1[1] = 10; + + array2[0][0] = 6.4; + array2[0][1] = -3.1; + array2[0][2] = 55.0; + array2[1][0] = 63.0; + array2[1][1] = -100.9; + array2[1][2] = 50.8; + + array2[1][2] = array2[0][1] + array2[1][0]; + + // Declaration and initialization + double array3[3] = {5.0, 1.0, 2.0}; + int array4[2][3] = {{1, 6, -4}, {2, 2, 2}}; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/ascii.cpp b/lectures/week1/code_snippets/ascii.cpp new file mode 100644 index 0000000..f26b4f9 --- /dev/null +++ b/lectures/week1/code_snippets/ascii.cpp @@ -0,0 +1,10 @@ +#include + +int main(int argc, char *argv[]) { + char letter; + letter = 'a'; // note the single quotation marks + + std::cout << "The character is " << letter << "\n"; + + return 0; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/assert.cpp b/lectures/week1/code_snippets/assert.cpp new file mode 100644 index 0000000..f371bd7 --- /dev/null +++ b/lectures/week1/code_snippets/assert.cpp @@ -0,0 +1,15 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + double a; + + std::cout << "Enter a non-negative number\n"; + std::cin >> a; + assert(a >= 0.0); + std::cout << "The square root of " << a; + std::cout << " is " << sqrt(a) << "\n"; + + return 0; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/bool.cpp b/lectures/week1/code_snippets/bool.cpp new file mode 100644 index 0000000..4315762 --- /dev/null +++ b/lectures/week1/code_snippets/bool.cpp @@ -0,0 +1,5 @@ +int main() { + bool flag1, flag2; + flag1 = true; + flag2 = false; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/console_output.cpp b/lectures/week1/code_snippets/console_output.cpp new file mode 100644 index 0000000..84d9c43 --- /dev/null +++ b/lectures/week1/code_snippets/console_output.cpp @@ -0,0 +1,15 @@ +#include + +int main() { + std::cout << "Hello World!\n"; + + // Output multiple variables at the same time: + + int x = 1, y = 2; + std::cout << "x = " << x << " and y = " << y << "\n"; + + // Output is buffered, to force output: + + std::cout << "Hello World\n"; + std::cout.flush(); +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/hello.cpp b/lectures/week1/code_snippets/hello.cpp new file mode 100644 index 0000000..6e2237c --- /dev/null +++ b/lectures/week1/code_snippets/hello.cpp @@ -0,0 +1,11 @@ +#include + +int main(int argc, char *argv[]) { + /* This is a comment and will be ignored by the compiler + Comments are useful to explain in English what + the program does */ + + // Print "Hello World" to the screen + std::cout << "Hello World\n"; + return 0; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/keyboard_input.cpp b/lectures/week1/code_snippets/keyboard_input.cpp new file mode 100644 index 0000000..6cbc5a1 --- /dev/null +++ b/lectures/week1/code_snippets/keyboard_input.cpp @@ -0,0 +1,14 @@ +#include + +int main() { + int pin; + std::cout << "Enter your PIN, then hit RETURN\n"; + std::cin >> pin; + + // Read multiple variables at one: + + int account_number; + std::cout << "Enter your account number\n"; + std::cout << "and then your PIN, each followed by RETURN\n"; + std::cin >> account_number >> pin; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/operations.cpp b/lectures/week1/code_snippets/operations.cpp new file mode 100644 index 0000000..8006207 --- /dev/null +++ b/lectures/week1/code_snippets/operations.cpp @@ -0,0 +1,22 @@ +#include +int main(int argc, char *argv[]) { + int a = 5, b = 2, c; + + c = a + b; // integer addition + c = a - b; // integer substraction + c = a * b; // integer multiplication + c = a / b; // integer division (careful!) + c = a % b; // modulo operation + + double x = 1.0, y = 2.0, z; + + z = (double)a / (double)b; // cast integer to a float + + z = x / y; // floating point division + z = sqrt(x); // square root + z = exp(y); // exponential function + z = pow(x, y); // x to the power of y + z = M_PI; // z stores the value of pi + + return 0; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/string.cpp b/lectures/week1/code_snippets/string.cpp new file mode 100644 index 0000000..04575a9 --- /dev/null +++ b/lectures/week1/code_snippets/string.cpp @@ -0,0 +1,17 @@ +#include +#include + +int main(int argc, char *argv[]) { + std::string city; // note the std:: + city = "Oxford"; // note the double quotation marks + + std::cout << "String length = " << city.length() << "\n"; + std::cout << "Third character = " << city.at(2) << "\n"; + std::cout << "Third character = " << city[2] << "\n"; + // Prints the string in city + std::cout << city << "\n"; + // Also prints city + std::cout << city.c_str() << "\n"; + + return 0; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/string_input.cpp b/lectures/week1/code_snippets/string_input.cpp new file mode 100644 index 0000000..0b68ce7 --- /dev/null +++ b/lectures/week1/code_snippets/string_input.cpp @@ -0,0 +1,11 @@ +#include +#include + +int main(int argc, char *argv[]) { + std::string name; + std::cout << "Enter your name and then hit RETURN\n"; + std::getline(std::cin, name); + std::cout << "Your name is " << name << "\n"; + + return 0; +} \ No newline at end of file diff --git a/lectures/week1/code_snippets/variables.cpp b/lectures/week1/code_snippets/variables.cpp new file mode 100644 index 0000000..6c85821 --- /dev/null +++ b/lectures/week1/code_snippets/variables.cpp @@ -0,0 +1,24 @@ +int main() { + + int row, column; + double temperature; + row = 1; + column = 2; + temperature = 3.0; + + double tolerance1 = 0.0001; + double tolerance2 = 1e-4; + + const double density = 45.621; + + int integer1; + short int integer2; + long int integer3; + + signed long int integer4; + unsigned int integer5; + + float x1; + double x2; + long double x3; +} \ No newline at end of file diff --git a/lectures/week1/getting-started.pdf b/lectures/week1/getting-started.pdf new file mode 100644 index 0000000..41c9874 Binary files /dev/null and b/lectures/week1/getting-started.pdf differ diff --git a/lectures/week1/program.pdf b/lectures/week1/program.pdf new file mode 100644 index 0000000..b7848c1 Binary files /dev/null and b/lectures/week1/program.pdf differ diff --git a/lectures/week2/git.pdf b/lectures/week2/git.pdf new file mode 100644 index 0000000..0cc9747 Binary files /dev/null and b/lectures/week2/git.pdf differ diff --git a/lectures/week2/program.pdf b/lectures/week2/program.pdf new file mode 100644 index 0000000..338c6b3 Binary files /dev/null and b/lectures/week2/program.pdf differ diff --git a/solutions/CMakeLists.txt b/solutions/CMakeLists.txt new file mode 100644 index 0000000..09cff2a --- /dev/null +++ b/solutions/CMakeLists.txt @@ -0,0 +1,3 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +add_subdirectory(chapter-01) diff --git a/solutions/chapter-01/CMakeLists.txt b/solutions/chapter-01/CMakeLists.txt new file mode 100644 index 0000000..1d73fe4 --- /dev/null +++ b/solutions/chapter-01/CMakeLists.txt @@ -0,0 +1,8 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +# The next lines represent a list of all the executables in the folder (chapter) +# There is typically one executable per exercise. +# As you solve exercises, you need to add them here. +# The syntax is add_executable(executable_name source_file_name) + +add_executable(ch-01-ex-01-solution ch-01-ex-01-solution.cpp) diff --git a/solutions/chapter-01/ch-01-ex-01-solution.cpp b/solutions/chapter-01/ch-01-ex-01-solution.cpp new file mode 100644 index 0000000..5dab5ea --- /dev/null +++ b/solutions/chapter-01/ch-01-ex-01-solution.cpp @@ -0,0 +1,24 @@ +/* + * exercise-01.cpp + * + * Hello, World! + * + * Created on: Jul 26, 2012 + * Author: Radu Popescu + */ + +/* Reading and writing operations require the following header + * to be included + */ +#include + +int main(int argc, char *argv[]) { + /* This is a comment and will be ignored by the compiler. + * Comments are useful to explain in English what the program does. + */ + + // Print "Hello World" to the screen + std::cout << "Hello World\n"; + + return 0; +} diff --git a/work/CMakeLists.txt b/work/CMakeLists.txt new file mode 100644 index 0000000..cddc849 --- /dev/null +++ b/work/CMakeLists.txt @@ -0,0 +1,3 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +add_executable(exercise-template exercise-template.cpp) diff --git a/work/exercise-template.cpp b/work/exercise-template.cpp new file mode 100644 index 0000000..c592b3e --- /dev/null +++ b/work/exercise-template.cpp @@ -0,0 +1,21 @@ +/* + * exercise-template.cpp <--- The name of the source file goes here + * + * <--- Description of the program goes here. + * + * Created on: September 02, 2015 <--- Fill in the date here + * Author: Davide Forti <--- Fill in your name + * (and e-mail) here + */ + +/* + * Any headers you need to include should be specified on the next lines + */ +#include + +int main(int argc, char *argv[]) { + /* + * The body of the program goes here + */ + return 0; +}