<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.itcollege.ee/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jtominga</id>
	<title>ICO wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.itcollege.ee/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jtominga"/>
	<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php/Special:Contributions/Jtominga"/>
	<updated>2026-05-08T08:24:01Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128814</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128814"/>
		<updated>2018-01-02T21:12:29Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  vector&amp;lt;Person&amp;gt; people&lt;br /&gt;
  {&lt;br /&gt;
    Person { 11, &amp;quot;Jack&amp;quot;},&lt;br /&gt;
    Person { 43, &amp;quot;John Doe&amp;quot;},&lt;br /&gt;
    Person { 42, &amp;quot;Melissa&amp;quot;}&lt;br /&gt;
  };&lt;br /&gt;
  int idToFind = 43;&lt;br /&gt;
  auto location = find_if(begin(people), end(people), [idToFind](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id == idToFind;&lt;br /&gt;
  });&lt;br /&gt;
  if (location != end(people))&lt;br /&gt;
  {&lt;br /&gt;
    // Person found!&lt;br /&gt;
    Person found = *location;&lt;br /&gt;
  }&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
  vector&amp;lt;int&amp;gt; ints{ -1, 2, -3, 4, -5, 6, -7, 8 };&lt;br /&gt;
  auto firstToRemove = remove_if(begin(ints), end(ints), [](int value) &lt;br /&gt;
  {&lt;br /&gt;
    return value &amp;lt; 0;&lt;br /&gt;
  });&lt;br /&gt;
  ints.erase(firstToRemove, end(ints));&lt;br /&gt;
* Remove all people whose name is longer than 4 characters and whose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  // Remove people whose id is odd and name longer than 4 characters&lt;br /&gt;
  auto lambda = [](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id % 2 == 1 &amp;amp;&amp;amp; person.name.length() &amp;gt; 4;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://drive.google.com/open?id=1Hd80rp7kQtOeO7r4avLXPLa2SnLW9BVU simple_data.json]&lt;br /&gt;
&lt;br /&gt;
  ifstream simple_file(&amp;quot;simple_data.json&amp;quot;);&lt;br /&gt;
  nlohmann::json simple_json;&lt;br /&gt;
  simple_file &amp;gt;&amp;gt; simple_json;&lt;br /&gt;
  simple_file.close();&lt;br /&gt;
  int integer = simple_json[&amp;quot;integer&amp;quot;];&lt;br /&gt;
  string str = simple_json[&amp;quot;string&amp;quot;];&lt;br /&gt;
  bool b = simple_json[&amp;quot;boolean&amp;quot;];&lt;br /&gt;
  vector&amp;lt;int&amp;gt; manyInts = simple_json[&amp;quot;ints&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
  // Another way&lt;br /&gt;
  int integer2 = simple_json.at(&amp;quot;integer&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
&lt;br /&gt;
[https://drive.google.com/open?id=1DUKCKLRabTcJ6d2_JpCj-v-o8vU88w60 rectangle.json]&lt;br /&gt;
&lt;br /&gt;
  struct Rectangle&lt;br /&gt;
  {&lt;br /&gt;
    int width; &lt;br /&gt;
    int height;&lt;br /&gt;
  };&lt;br /&gt;
  void from_json(const nlohmann::json&amp;amp; j, Rectangle&amp;amp; r) {&lt;br /&gt;
    r.width = j.at(&amp;quot;width&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
    r.height = j.at(&amp;quot;height&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  ifstream rectangle_file(&amp;quot;rectangle.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangle_json;&lt;br /&gt;
  rectangle_file &amp;gt;&amp;gt; rectangle_json;&lt;br /&gt;
  rectangle_file.close();&lt;br /&gt;
  Rectangle rect = rectangle_json;&lt;br /&gt;
* Open a json file that contains an array of items from the previous assignment&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Rectangle&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://drive.google.com/open?id=1e9rNgP6_QPg88NhM5LpEm7i75twWPjB1 rectangles.json]&lt;br /&gt;
&lt;br /&gt;
  ifstream rectangles_file(&amp;quot;rectangles.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangles_json;&lt;br /&gt;
  rectangles_file &amp;gt;&amp;gt; rectangles_json;&lt;br /&gt;
  rectangles_file.close();&lt;br /&gt;
  vector&amp;lt;Rectangle&amp;gt; rects = rectangles_json;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128813</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128813"/>
		<updated>2018-01-02T21:08:00Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  vector&amp;lt;Person&amp;gt; people&lt;br /&gt;
  {&lt;br /&gt;
    Person { 11, &amp;quot;Jack&amp;quot;},&lt;br /&gt;
    Person { 43, &amp;quot;John Doe&amp;quot;},&lt;br /&gt;
    Person { 42, &amp;quot;Melissa&amp;quot;}&lt;br /&gt;
  };&lt;br /&gt;
  int idToFind = 43;&lt;br /&gt;
  auto location = find_if(begin(people), end(people), [idToFind](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id == idToFind;&lt;br /&gt;
  });&lt;br /&gt;
  if (location != end(people))&lt;br /&gt;
  {&lt;br /&gt;
    // Person found!&lt;br /&gt;
    Person found = *location;&lt;br /&gt;
  }&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
  vector&amp;lt;int&amp;gt; ints{ -1, 2, -3, 4, -5, 6, -7, 8 };&lt;br /&gt;
  auto firstToRemove = remove_if(begin(ints), end(ints), [](int value) &lt;br /&gt;
  {&lt;br /&gt;
    return value &amp;lt; 0;&lt;br /&gt;
  });&lt;br /&gt;
  ints.erase(firstToRemove, end(ints));&lt;br /&gt;
* Remove all people whose name is longer than 4 characters and whose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  // Remove people whose id is odd and name longer than 4 characters&lt;br /&gt;
  auto lambda = [](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id % 2 == 1 &amp;amp;&amp;amp; person.name.length() &amp;gt; 4;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
  ifstream simple_file(&amp;quot;simple_data.json&amp;quot;);&lt;br /&gt;
  nlohmann::json simple_json;&lt;br /&gt;
  simple_file &amp;gt;&amp;gt; simple_json;&lt;br /&gt;
  simple_file.close();&lt;br /&gt;
  int integer = simple_json[&amp;quot;integer&amp;quot;];&lt;br /&gt;
  string str = simple_json[&amp;quot;string&amp;quot;];&lt;br /&gt;
  bool b = simple_json[&amp;quot;boolean&amp;quot;];&lt;br /&gt;
  vector&amp;lt;int&amp;gt; manyInts = simple_json[&amp;quot;ints&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
  // Another way&lt;br /&gt;
  int integer2 = simple_json.at(&amp;quot;integer&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
  struct Rectangle&lt;br /&gt;
  {&lt;br /&gt;
    int width; &lt;br /&gt;
    int height;&lt;br /&gt;
  };&lt;br /&gt;
  void from_json(const nlohmann::json&amp;amp; j, Rectangle&amp;amp; r) {&lt;br /&gt;
    r.width = j.at(&amp;quot;width&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
    r.height = j.at(&amp;quot;height&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  ifstream rectangle_file(&amp;quot;rectangle.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangle_json;&lt;br /&gt;
  rectangle_file &amp;gt;&amp;gt; rectangle_json;&lt;br /&gt;
  rectangle_file.close();&lt;br /&gt;
  Rectangle rect = rectangle_json;&lt;br /&gt;
* Open a json file that contains an array of items from the previous assignment&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Rectangle&amp;gt;&lt;br /&gt;
  ifstream rectangles_file(&amp;quot;rectangles.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangles_json;&lt;br /&gt;
  rectangles_file &amp;gt;&amp;gt; rectangles_json;&lt;br /&gt;
  rectangles_file.close();&lt;br /&gt;
  vector&amp;lt;Rectangle&amp;gt; rects = rectangles_json;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128812</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128812"/>
		<updated>2018-01-02T21:07:33Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  vector&amp;lt;Person&amp;gt; people&lt;br /&gt;
  {&lt;br /&gt;
    Person { 11, &amp;quot;Jack&amp;quot;},&lt;br /&gt;
    Person { 43, &amp;quot;John Doe&amp;quot;},&lt;br /&gt;
    Person { 42, &amp;quot;Melissa&amp;quot;}&lt;br /&gt;
  };&lt;br /&gt;
  int idToFind = 43;&lt;br /&gt;
  auto location = find_if(begin(people), end(people), [idToFind](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id == idToFind;&lt;br /&gt;
  });&lt;br /&gt;
  if (location != end(people))&lt;br /&gt;
  {&lt;br /&gt;
    // Person found!&lt;br /&gt;
    Person found = *location;&lt;br /&gt;
  }&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
  vector&amp;lt;int&amp;gt; ints{ -1, 2, -3, 4, -5, 6, -7, 8 };&lt;br /&gt;
  auto firstToRemove = remove_if(begin(ints), end(ints), [](int value) &lt;br /&gt;
  {&lt;br /&gt;
    return value &amp;lt; 0;&lt;br /&gt;
  });&lt;br /&gt;
  ints.erase(firstToRemove, end(ints));&lt;br /&gt;
* Remove all people whose name is longer than 4 characters and whose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  // Remove people whose id is odd and name longer than 4 characters&lt;br /&gt;
  auto lambda = [](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id % 2 == 1 &amp;amp;&amp;amp; person.name.length() &amp;gt; 4;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
  ifstream simple_file(&amp;quot;simple_data.json&amp;quot;);&lt;br /&gt;
  nlohmann::json simple_json;&lt;br /&gt;
  simple_file &amp;gt;&amp;gt; simple_json;&lt;br /&gt;
  simple_file.close();&lt;br /&gt;
  int integer = simple_json[&amp;quot;integer&amp;quot;];&lt;br /&gt;
  string str = simple_json[&amp;quot;string&amp;quot;];&lt;br /&gt;
  bool b = simple_json[&amp;quot;boolean&amp;quot;];&lt;br /&gt;
  vector&amp;lt;int&amp;gt; manyInts = simple_json[&amp;quot;ints&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
  // Another way&lt;br /&gt;
  int integer2 = simple_json.at(&amp;quot;integer&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
  struct Rectangle&lt;br /&gt;
  {&lt;br /&gt;
    int width; &lt;br /&gt;
    int height;&lt;br /&gt;
  };&lt;br /&gt;
  void from_json(const nlohmann::json&amp;amp; j, Rectangle&amp;amp; r) {&lt;br /&gt;
    r.width = j.at(&amp;quot;width&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
    r.height = j.at(&amp;quot;height&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  ifstream rectangle_file(&amp;quot;rectangle.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangle_json;&lt;br /&gt;
  rectangle_file &amp;gt;&amp;gt; rectangle_json;&lt;br /&gt;
  rectangle_file.close();&lt;br /&gt;
  Rectangle rect = rectangle_json;&lt;br /&gt;
* Open a json file that contains an array of items from the previous assignment&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  ifstream rectangles_file(&amp;quot;rectangles.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangles_json;&lt;br /&gt;
  rectangles_file &amp;gt;&amp;gt; rectangles_json;&lt;br /&gt;
  rectangles_file.close();&lt;br /&gt;
  vector&amp;lt;Rectangle&amp;gt; rects = rectangles_json;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128811</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128811"/>
		<updated>2018-01-02T21:05:53Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  vector&amp;lt;Person&amp;gt; people&lt;br /&gt;
  {&lt;br /&gt;
    Person { 11, &amp;quot;Jack&amp;quot;},&lt;br /&gt;
    Person { 43, &amp;quot;John Doe&amp;quot;},&lt;br /&gt;
    Person { 42, &amp;quot;Melissa&amp;quot;}&lt;br /&gt;
  };&lt;br /&gt;
  int idToFind = 43;&lt;br /&gt;
  auto location = find_if(begin(people), end(people), [idToFind](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id == idToFind;&lt;br /&gt;
  });&lt;br /&gt;
  if (location != end(people))&lt;br /&gt;
  {&lt;br /&gt;
    // Person found!&lt;br /&gt;
    Person found = *location;&lt;br /&gt;
  }&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
  vector&amp;lt;int&amp;gt; ints{ -1, 2, -3, 4, -5, 6, -7, 8 };&lt;br /&gt;
  auto firstToRemove = remove_if(begin(ints), end(ints), [](int value) &lt;br /&gt;
  {&lt;br /&gt;
    return value &amp;lt; 0;&lt;br /&gt;
  });&lt;br /&gt;
  ints.erase(firstToRemove, end(ints));&lt;br /&gt;
* Remove all people whose name is longer than 4 characters and whose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  // Remove people whose id is odd and name longer than 4 characters&lt;br /&gt;
  auto lambda = [](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id % 2 == 1 &amp;amp;&amp;amp; person.name.length() &amp;gt; 4;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
  ifstream simple_file(&amp;quot;simple_data.json&amp;quot;);&lt;br /&gt;
  nlohmann::json simple_json;&lt;br /&gt;
  simple_file &amp;gt;&amp;gt; simple_json;&lt;br /&gt;
  simple_file.close();&lt;br /&gt;
  int integer = simple_json[&amp;quot;integer&amp;quot;];&lt;br /&gt;
  string str = simple_json[&amp;quot;string&amp;quot;];&lt;br /&gt;
  bool b = simple_json[&amp;quot;boolean&amp;quot;];&lt;br /&gt;
  vector&amp;lt;int&amp;gt; manyInts = simple_json[&amp;quot;ints&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
  // Another way&lt;br /&gt;
  int integer2 = simple_json.at(&amp;quot;integer&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
  struct Rectangle&lt;br /&gt;
  {&lt;br /&gt;
    int width; &lt;br /&gt;
    int height;&lt;br /&gt;
  };&lt;br /&gt;
  void from_json(const nlohmann::json&amp;amp; j, Rectangle&amp;amp; r) {&lt;br /&gt;
    r.width = j.at(&amp;quot;width&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
    r.height = j.at(&amp;quot;height&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  ifstream rectangle_file(&amp;quot;rectangle.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangle_json;&lt;br /&gt;
  rectangle_file &amp;gt;&amp;gt; rectangle_json;&lt;br /&gt;
  rectangle_file.close();&lt;br /&gt;
  Rectangle rect = rectangle_json;&lt;br /&gt;
* Open a json file that contains an array of items with two values (&amp;quot;name&amp;quot; and &amp;quot;ID&amp;quot;)&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  ifstream rectangles_file(&amp;quot;rectangles.json&amp;quot;);&lt;br /&gt;
  nlohmann::json rectangles_json;&lt;br /&gt;
  rectangles_file &amp;gt;&amp;gt; rectangles_json;&lt;br /&gt;
  rectangles_file.close();&lt;br /&gt;
  vector&amp;lt;Rectangle&amp;gt; rects = rectangles_json;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128810</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128810"/>
		<updated>2018-01-02T21:03:58Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  vector&amp;lt;Person&amp;gt; people&lt;br /&gt;
  {&lt;br /&gt;
    Person { 11, &amp;quot;Jack&amp;quot;},&lt;br /&gt;
    Person { 43, &amp;quot;John Doe&amp;quot;},&lt;br /&gt;
    Person { 42, &amp;quot;Melissa&amp;quot;}&lt;br /&gt;
  };&lt;br /&gt;
  int idToFind = 43;&lt;br /&gt;
  auto location = find_if(begin(people), end(people), [idToFind](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id == idToFind;&lt;br /&gt;
  });&lt;br /&gt;
  if (location != end(people))&lt;br /&gt;
  {&lt;br /&gt;
    // Person found!&lt;br /&gt;
    Person found = *location;&lt;br /&gt;
  }&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
  vector&amp;lt;int&amp;gt; ints{ -1, 2, -3, 4, -5, 6, -7, 8 };&lt;br /&gt;
  auto firstToRemove = remove_if(begin(ints), end(ints), [](int value) &lt;br /&gt;
  {&lt;br /&gt;
    return value &amp;lt; 0;&lt;br /&gt;
  });&lt;br /&gt;
  ints.erase(firstToRemove, end(ints));&lt;br /&gt;
* Remove all people whose name is longer than 4 characters and whose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  // Remove people whose id is odd and name longer than 4 characters&lt;br /&gt;
  auto lambda = [](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id % 2 == 1 &amp;amp;&amp;amp; person.name.length() &amp;gt; 4;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
  ifstream simple_file(&amp;quot;simple_data.json&amp;quot;);&lt;br /&gt;
  nlohmann::json simple_json;&lt;br /&gt;
  simple_file &amp;gt;&amp;gt; simple_json;&lt;br /&gt;
  simple_file.close();&lt;br /&gt;
  int integer = simple_json[&amp;quot;integer&amp;quot;];&lt;br /&gt;
  string str = simple_json[&amp;quot;string&amp;quot;];&lt;br /&gt;
  bool b = simple_json[&amp;quot;boolean&amp;quot;];&lt;br /&gt;
  vector&amp;lt;int&amp;gt; manyInts = simple_json[&amp;quot;ints&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
  // Another way&lt;br /&gt;
  int integer2 = simple_json.at(&amp;quot;integer&amp;quot;).get&amp;lt;int&amp;gt;();&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
* Open a json file that contains an array of items with two values (&amp;quot;name&amp;quot; and &amp;quot;ID&amp;quot;)&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128809</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128809"/>
		<updated>2018-01-02T21:01:25Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  vector&amp;lt;Person&amp;gt; people&lt;br /&gt;
  {&lt;br /&gt;
    Person { 11, &amp;quot;Jack&amp;quot;},&lt;br /&gt;
    Person { 43, &amp;quot;John Doe&amp;quot;},&lt;br /&gt;
    Person { 42, &amp;quot;Melissa&amp;quot;}&lt;br /&gt;
  };&lt;br /&gt;
  int idToFind = 43;&lt;br /&gt;
  auto location = find_if(begin(people), end(people), [idToFind](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id == idToFind;&lt;br /&gt;
  });&lt;br /&gt;
  if (location != end(people))&lt;br /&gt;
  {&lt;br /&gt;
    // Person found!&lt;br /&gt;
    Person found = *location;&lt;br /&gt;
  }&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
  vector&amp;lt;int&amp;gt; ints{ -1, 2, -3, 4, -5, 6, -7, 8 };&lt;br /&gt;
  auto firstToRemove = remove_if(begin(ints), end(ints), [](int value) &lt;br /&gt;
  {&lt;br /&gt;
    return value &amp;lt; 0;&lt;br /&gt;
  });&lt;br /&gt;
  ints.erase(firstToRemove, end(ints));&lt;br /&gt;
* Remove all people whose name is longer than 4 characters and whose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
  // Remove people whose id is odd and name longer than 4 characters&lt;br /&gt;
  auto lambda = [](Person const&amp;amp; person)&lt;br /&gt;
  {&lt;br /&gt;
    return person.id % 2 == 1 &amp;amp;&amp;amp; person.name.length() &amp;gt; 4;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
* Open a json file that contains an array of items with two values (&amp;quot;name&amp;quot; and &amp;quot;ID&amp;quot;)&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128808</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128808"/>
		<updated>2018-01-02T20:49:37Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 6 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
* Remove all people whose name is longer than 5 characters and wose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
* Open a json file that contains an array of items with two values (&amp;quot;name&amp;quot; and &amp;quot;ID&amp;quot;)&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128807</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128807"/>
		<updated>2018-01-02T20:49:23Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
std::algorithm continued, nlohmann::json (consuming header only libraries)&lt;br /&gt;
&lt;br /&gt;
[https://www.w3resource.com/JSON/structures.php json structure]&lt;br /&gt;
&lt;br /&gt;
1. Create a struct Person that has two fields: a name and an ID number&lt;br /&gt;
&lt;br /&gt;
2. Using std::algorithm&lt;br /&gt;
* Find a person by name from a std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Find a person by the ID number from a vector&amp;lt;Person&amp;gt;&lt;br /&gt;
* Erase all negative values from a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
** Use std::remove_if to move all elements to be kept to the beginning of vector&lt;br /&gt;
** Use std::vector.erase() to erase the unnecessary elements from the end of the vector&lt;br /&gt;
* Remove all people whose name is longer than 5 characters and wose ID is odd from an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Consuming header only libraries (the simplest way)&lt;br /&gt;
* Download the necessary header file&lt;br /&gt;
* Move the header file to a well-known folder (project folder, some subfolder, etc)&lt;br /&gt;
* #include the header file by specifying a relative path to the header&lt;br /&gt;
&lt;br /&gt;
4. Using the nlohmann::json library&lt;br /&gt;
* Open a .json file and read it into a nlohmann::json object in memory&lt;br /&gt;
* Open a json file that contains some simple data (int, string, bool, array of ints)&lt;br /&gt;
** Read an integer from the json into an int&lt;br /&gt;
** Read a string from the json into an std::string&lt;br /&gt;
** Read a boolean from the json into a bool&lt;br /&gt;
** Read an array of ints from the json into an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Open a json file that contains a single item with two integral values (&amp;quot;width&amp;quot; and &amp;quot;height&amp;quot;)&lt;br /&gt;
** Read the object from the json into a struct Rectangle { int width; int height; }&lt;br /&gt;
* Open a json file that contains an array of items with two values (&amp;quot;name&amp;quot; and &amp;quot;ID&amp;quot;)&lt;br /&gt;
** Read the array from the json into an std::vector&amp;lt;Person&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128806</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128806"/>
		<updated>2018-01-02T20:16:08Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
function pointers, std::function, lambdas, std::algorithm&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Store the function in a function pointer&lt;br /&gt;
* Call the function via the function pointer&lt;br /&gt;
* Store the function in an std::function&lt;br /&gt;
* Call the function via the std::function variable&lt;br /&gt;
&lt;br /&gt;
2. Re-implement the odd function counter as a lambda&lt;br /&gt;
* Store the lambda in an std::function&lt;br /&gt;
* Store the lambda in auto&lt;br /&gt;
* Call the lambda&lt;br /&gt;
&lt;br /&gt;
3. Exercise: Create a lambda that returns the position of the first negative number in a std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Lambda capture modes&lt;br /&gt;
* Default by value&lt;br /&gt;
* Default by reference&lt;br /&gt;
* Named by value&lt;br /&gt;
** Create a lambda that calculates the factorial of an int that is captured by value&lt;br /&gt;
* Named by reference&lt;br /&gt;
** Create a lambda that counts the number of negative numbers in an std::vector&amp;lt;int&amp;gt; that is captured by reference&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if:&lt;br /&gt;
* Takes a reference to a container of ints as its first argument&lt;br /&gt;
* Takes a comparison function as its second argument (std::function&amp;lt;bool(int)&amp;gt;)&lt;br /&gt;
* Returns void&lt;br /&gt;
* Sets each such value to 0 in the container for which the function returns true&lt;br /&gt;
&lt;br /&gt;
6. std::algorithm (Without looping!)&lt;br /&gt;
* Find the largest element in an std::vector&amp;lt;int&amp;gt;&lt;br /&gt;
* Sort a vector of ints&lt;br /&gt;
** ascending&lt;br /&gt;
** descending, using a custom comparer&lt;br /&gt;
* Count the number of strings that have a length of over 5 characters in std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
* Reverse all strings in a std::vector&amp;lt;std::string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128805</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128805"/>
		<updated>2018-01-02T19:51:01Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
dynamic inheritance, (constructor) overloading, simple templates&lt;br /&gt;
&lt;br /&gt;
1. Dynamic inheritance&lt;br /&gt;
* Create a base class for several shape types, called Shape with:&lt;br /&gt;
** virtual default destructor&lt;br /&gt;
** an abstract function that returns the Shape&#039;s area&lt;br /&gt;
** an abstract function that returns the Shape&#039;s name&lt;br /&gt;
* Create classes Rectangle and Shape that override the Shape and implement its methods&lt;br /&gt;
* Use the classes in an std::vector&amp;lt;std::unique_ptr&amp;lt;Shape&amp;gt;&amp;gt; to find the names and areas of several mixed Shapes&lt;br /&gt;
* Add an overloaded constructor to Rectangle that enables the user to customize the name of some Rectangles&lt;br /&gt;
&lt;br /&gt;
2. Exercise&lt;br /&gt;
* Create a hierarchy of Animals similarly to the Shapes (with animal names and sounds)&lt;br /&gt;
* Provide an overloaded constructor for some Animal&lt;br /&gt;
&lt;br /&gt;
3. Simple templates&lt;br /&gt;
* Create a Queue of ints, that uses an std::deque as an underlying datatype&lt;br /&gt;
* Provide methods to queue and dequeue values&lt;br /&gt;
* Convert the Queue to a template class&lt;br /&gt;
&lt;br /&gt;
4. Exercise&lt;br /&gt;
* Create an Accumulator of ints&lt;br /&gt;
** stores an int as a member variable&lt;br /&gt;
** initial value of the accumulator is specified via the constructor&lt;br /&gt;
** has a member function that adds a value to the stored value (using the operator +=)&lt;br /&gt;
** has a member function that fetches the stored value&lt;br /&gt;
* Template the Accumulator to store and add any type of values&lt;br /&gt;
* (optional) Create a class Distance that can be used with the Accumulator&lt;br /&gt;
** wraps some value (like an int or a double) in a class&lt;br /&gt;
** overloads the operator+=&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128526</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128526"/>
		<updated>2017-12-15T21:46:31Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: [https://drive.google.com/open?id=18RY7Nnynd0LmHa74O2NJ_yzAf6fdIcXz recipes.json], [https://drive.google.com/open?id=1RS4ju4d9FTFkN4IjXWQBmHOx-TAQy_qH ingredients.json] and [https://drive.google.com/open?id=1CjoGQ-luAUoyFGpBHEG_Y8pb1PTu3BGp prices.json]. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128471</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=128471"/>
		<updated>2017-12-15T16:33:22Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
&lt;br /&gt;
Descending date order.&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c002b483-d428-4249-842a-9e92fdebfce8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/7efb0957-f384-4eb1-85ad-dd713fe4d65d/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/bba448ab-8a38-405c-b2a2-5353e227265f/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/df9ae848-a582-4ba2-999a-8df18d3132c6/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/02aa7ba3-4bcc-4ace-b676-fd04b58eeff8/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/8c1485c5-61f3-4062-851d-916906503fd3/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2e7e5c6a-10af-4b8c-8303-2e6e4650a206/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/3917eeef-a127-4338-85e5-207d692504b7/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/54f0ef26-6ef2-4bc7-9637-c3cde6a27aaa/public&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/e099b072-a8ab-4c4b-9c3e-532715cc2d7e/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/6f39d546-5572-4cda-ad97-e61b968506ff/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c02ce02d-9e01-45dd-9f54-3be66a1dc2b2/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/2cb53a4e-f2b7-44b7-9bd6-93d90b26043b/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/d366f877-b4ae-4fcc-a90c-0d433772252a/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/35cd1108-141b-4a1a-8fb2-63e5f3a5b766/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/befc74e4-5873-4c34-a65f-84ebd00e3370/public&lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/media/c3a24815-2b5c-4e3c-8649-bebde59784a3/public&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
==== Pizza Shop: ====&lt;br /&gt;
&lt;br /&gt;
Write a program that calculates the prices for pizzas and tells the pizza shop owner if they have enough ingredients to fill the order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You are provided 3 files: recipes.json, ingredients.json and prices.json. These are all example files and your code must work with any kind of such file that matches the object syntax.&lt;br /&gt;
&lt;br /&gt;
Each file contains a list of objects whose schema is defined below.&lt;br /&gt;
&lt;br /&gt;
Prices contains the ids and prices for each price.&lt;br /&gt;
&lt;br /&gt;
Ingredients contains the names, stock counts (total available quantity) and priceTypes for each ingredient - this is the amount of ingredients available for you during one program run. Ingredient priceType is matched with a Price from prices.json file (match them by their id number). &lt;br /&gt;
&lt;br /&gt;
Recipes contains pizzas with ingredients - these are the same ingredients as in ingredients.json file (match them by their name). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your program must read all .json files and provide console input where you can enter a pizza (pizza name) to be made. You can make any number of pizzas (at least until there are enough ingredients left).&lt;br /&gt;
&lt;br /&gt;
==== Program usage: ====&lt;br /&gt;
&lt;br /&gt;
1. Console asks for pizza name to be made&lt;br /&gt;
&lt;br /&gt;
2. User enters pizza name&lt;br /&gt;
&lt;br /&gt;
3.a. When the pizza can be made (is made):&lt;br /&gt;
&lt;br /&gt;
		Print to console the total price of the pizza.&lt;br /&gt;
&lt;br /&gt;
		Ingredients used must be taken off your stock.&lt;br /&gt;
&lt;br /&gt;
3.b. When the pizza cannot be made:&lt;br /&gt;
&lt;br /&gt;
		Print out which ingredients are missing and how many.&lt;br /&gt;
&lt;br /&gt;
4. --Return to step 1--&lt;br /&gt;
&lt;br /&gt;
==== Datatypes (schema): ====&lt;br /&gt;
&lt;br /&gt;
===== Pizza: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
ingredients - list of strings&lt;br /&gt;
&lt;br /&gt;
===== Ingredient: =====&lt;br /&gt;
&lt;br /&gt;
name - string&lt;br /&gt;
&lt;br /&gt;
quantity - integer&lt;br /&gt;
&lt;br /&gt;
priceType - integer&lt;br /&gt;
&lt;br /&gt;
===== Price: =====&lt;br /&gt;
&lt;br /&gt;
id - integer&lt;br /&gt;
&lt;br /&gt;
price - double&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126283</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126283"/>
		<updated>2017-11-08T18:33:44Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126282</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126282"/>
		<updated>2017-11-08T18:33:35Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Lectures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126281</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126281"/>
		<updated>2017-11-08T18:33:24Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Code from lectures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
Recordings of lectures and practices: &lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126280</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126280"/>
		<updated>2017-11-08T18:33:17Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Code from lectures ===&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
Recordings of lectures and practices: &lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126279</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126279"/>
		<updated>2017-11-08T18:32:50Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings of lectures and practices ===&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
Recordings of lectures and practices: &lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126278</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126278"/>
		<updated>2017-11-08T18:32:04Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Lecturers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video recordings ===&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
Recordings of lectures and practices: &lt;br /&gt;
&lt;br /&gt;
https://echo360.org.uk/section/d5161b62-4e7a-4b54-9578-10d86353e3d0/home&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
&lt;br /&gt;
http://enos.itcollege.ee/~rliiv/&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126182</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=126182"/>
		<updated>2017-11-06T22:42:12Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
6. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
file i/o, command line parameters, new/delete, classes, constructors/destructors, smart pointers&lt;br /&gt;
&lt;br /&gt;
1. Read strings from a file into a std::vector&amp;lt;std::string&amp;gt;, then print them out to another file.&lt;br /&gt;
&lt;br /&gt;
2. Modify the last program to read two file names from the command line and use these file names for files.&lt;br /&gt;
&lt;br /&gt;
3. Create a class that logs its creation and destruction via std::cout. Use a custom defined constructor and destructor for that.&lt;br /&gt;
Observe how actions are logged in different scenarios of instance creation and destruction, including smart pointers.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124956</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124956"/>
		<updated>2017-10-22T10:14:09Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
====== Practice 3 (second half) ======&lt;br /&gt;
C++ console i/o, std::string, std::vector, references, range based for, auto&lt;br /&gt;
&lt;br /&gt;
1. Write a Hello, World! program in C++&lt;br /&gt;
&lt;br /&gt;
2. Write a program that performs an addition operation based on user input. A sample input string: &amp;quot;2+2&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3. Write a program that asks the user for his name, stores it in an std::string and outputs the name back to the console window.&lt;br /&gt;
&lt;br /&gt;
4. Write a program that asks the user for several strings and stores them in an std::vector. Upon receiving the last string, the program should output all strings in the order they were received.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program by adding a function to modify a string by reference. Use that function on all input strings.&lt;br /&gt;
&lt;br /&gt;
5. Modify the last program to output the strings using a range based for loop. Bind the values to an auto&amp;amp;.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124953</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124953"/>
		<updated>2017-10-22T10:01:26Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124952</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124952"/>
		<updated>2017-10-22T10:01:08Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 (first half) ======&lt;br /&gt;
insertion sort, sorting structs&lt;br /&gt;
&lt;br /&gt;
1. Implement insertion sort to sort an array of integers in ascending order.&lt;br /&gt;
&lt;br /&gt;
2. Create a struct to hold integral key-value pairs. Modify the insertion sort algorithm to sort an array of these structs instead.&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124949</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124949"/>
		<updated>2017-10-22T09:37:19Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Lectures C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124422</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124422"/>
		<updated>2017-09-25T22:44:31Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124421</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124421"/>
		<updated>2017-09-25T22:44:18Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124420</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124420"/>
		<updated>2017-09-25T22:44:11Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Lectures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124419</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124419"/>
		<updated>2017-09-25T22:44:02Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124418</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124418"/>
		<updated>2017-09-25T22:43:54Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124417</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124417"/>
		<updated>2017-09-25T22:43:41Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Lectures C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124416</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124416"/>
		<updated>2017-09-25T22:43:11Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, conditions, loops, pointers, arrays, functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
File input/output, dynamic memory allocation, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console character by character.&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Write a program that dynamically allocates a small array of ints. Fill the array and print its contents. Free the memory after you&#039;re done using it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a program that reads the contents of a whole text file into a dynamically sized array of characters (and outputs the information into a new file).&lt;br /&gt;
Additional info:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator. (You may have to assign it to the end of the array yourself)&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called many times or in unexpected order?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. Write a program that reads an unknown number of integers (each on a separate line) from a file into the stack you created. After reading the whole file, print out all ints that were read (in reverse order).&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124415</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124415"/>
		<updated>2017-09-25T22:32:24Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Lectures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming_2016&amp;diff=124414</id>
		<title>Basics of C/C++ Programming 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming_2016&amp;diff=124414"/>
		<updated>2017-09-25T22:32:01Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a version of the course from autumn 2016. For current information see [[Basics_of_C/C%2B%2B_Programming]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming_2016&amp;diff=124413</id>
		<title>Basics of C/C++ Programming 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming_2016&amp;diff=124413"/>
		<updated>2017-09-25T22:31:46Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
This is a version of the course from autumn 2016. For current information see [[Basics_of_C/C%2B%2B_Programming]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=2016&amp;diff=124412</id>
		<title>2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=2016&amp;diff=124412"/>
		<updated>2017-09-25T22:28:03Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming_2016&amp;diff=124411</id>
		<title>Basics of C/C++ Programming 2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming_2016&amp;diff=124411"/>
		<updated>2017-09-25T22:27:58Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: Created page with &amp;quot; == Introduction==  === Lecturers === Rait Liiv: rait.liiv@itcollege.ee  Janno Tomingas: janno.tomingas@itcollege.ee  == C ==  === Lectures ===  ====== 1. Week. Introduction t...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124410</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124410"/>
		<updated>2017-09-25T22:27:39Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* 2016 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[Basics_of_C/C%2B%2B_Programming 2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=2016&amp;diff=124409</id>
		<title>2016</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=2016&amp;diff=124409"/>
		<updated>2017-09-25T22:26:55Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: Created page with &amp;quot; == Introduction==  === Lecturers === Rait Liiv: rait.liiv@itcollege.ee  Janno Tomingas: janno.tomingas@itcollege.ee  == C ==  === Lectures ===  ====== 1. Week. Introduction t...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124408</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=124408"/>
		<updated>2017-09-25T22:26:30Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
==== [[2016]] ====&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=115672</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=115672"/>
		<updated>2016-12-08T21:03:18Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over-/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=115671</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=115671"/>
		<updated>2016-12-08T21:03:02Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on vulnerabilities related to the following topics:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=115670</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=115670"/>
		<updated>2016-12-08T21:00:46Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Exploits */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 1. Week. Introduction to C and C++ ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 2. Week. Memory, pointers, datatypes ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 4. Week. Stack, heap, pointer, jumps, typedef ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
====== 5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== 8. Week. Const. + Additional leftover from previous lectures. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 9. Week. Templates ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/7f7c58b8-8173-42a4-8b9a-a3941196376a?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 10. Week. Iterator, Casting, ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/bfec4cef-6c38-46c0-9e06-1da985d94a66?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 11. Week. Static, Smart pointers, RAII ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/1b6f336e-52b8-4993-8c6f-de0cd5eb8a49?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
====== 12. Week. Exception, Assembly language ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/c093e098-f789-4600-8b5c-f7995b3abfcb?ec=true&lt;br /&gt;
&lt;br /&gt;
====== 13. Week. Discussion about vulnerabilities and exploiting. ======&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/e479b230-24a1-48d4-bbb1-a4621e1231ac?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Do some research on the following vulnerabilities:&lt;br /&gt;
&lt;br /&gt;
* Buffer overflow (stack smashing, code injection, arc injection),&lt;br /&gt;
* Arithmetic over/underflow,&lt;br /&gt;
* Memory leaks,&lt;br /&gt;
* Double free (and double delete),&lt;br /&gt;
* Formatted output,&lt;br /&gt;
* Concurrency,&lt;br /&gt;
* File I/O (symlinks, hardlinks);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Write an essay, that describes the causes, examples, and mitigation strategies for all of the topics.&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114893</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114893"/>
		<updated>2016-11-27T22:57:03Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Setting up the include and library directories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&#039;&#039;&#039;Setting up the include and library directories:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Useful shorthand macros:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114892</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114892"/>
		<updated>2016-11-27T22:53:23Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project&lt;br /&gt;
&lt;br /&gt;
====== Setting up the include and library directories ======&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;You can use several environment variables to make pointing to directories easier:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  $(SolutionDir) - Points to the directory where your solution file (.sln) is located&lt;br /&gt;
&lt;br /&gt;
  $(ProjectDir) - Points to the directory where your project file (.vcxporoj) is located&lt;br /&gt;
&lt;br /&gt;
  $(ENV_VAR) - Points to wherever a user variable or system variable points to, where ENV_VAR is the name of that variable&lt;br /&gt;
&lt;br /&gt;
A full list of currently available environment variables can be found by pressing the &amp;quot;Macros&amp;gt;&amp;gt;&amp;quot; button when editing project include or library directories.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Include directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Make sure you have at least one .cpp file in your project.&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; C/C++ -&amp;gt; General.&lt;br /&gt;
* Edit Additional Include Directories.&lt;br /&gt;
* Add an entry that points to the SFML include directory.&lt;br /&gt;
* If the previous steps were performed successfully, you should be able to include the SFML header files in your files (#include &amp;quot;SFML/Window.hpp&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Library directories:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; General.&lt;br /&gt;
* Edit Additional Library Directories.&lt;br /&gt;
* Add an entry that points to the SFML Libs/Release directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.lib files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* Go to Project -&amp;gt; Properties -&amp;gt; Linker -&amp;gt; Input.&lt;br /&gt;
* For each SFML module that you use, add the required .lib files to the Additional Dependencies list (System.hpp requires sfml-system.lib). The dependencies for each module can be found at the [http://www.sfml-dev.org/faq.php#build-link SFML FAQs]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;.dll files:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
* For every .lib file that you use, find and copy the corresponding .dll file from the SFML/bin folder into the folder where your program&#039;s .exe file will be built to. (sfml-system.lib -&amp;gt; sfml-system-2.dll)&lt;br /&gt;
* The default build target directory will be the Debug folder under your solution directory.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114891</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114891"/>
		<updated>2016-11-27T22:14:29Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project,&lt;br /&gt;
* Set up the include and library directories;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Implement [https://en.wikipedia.org/wiki/Conway&#039;s_Game_of_Life Conway&#039;s Game of Life] using C++ and SFML.&lt;br /&gt;
&lt;br /&gt;
See Practice 7 for an example of how to set up the project.&lt;br /&gt;
&lt;br /&gt;
====== General info ======&lt;br /&gt;
The game consists of a grid of cells. Each cell is either alive or dead. Every cell interacts with its eight adjacent cells.&lt;br /&gt;
&lt;br /&gt;
Before the start of the game, the user can select which cells are alive or dead.&lt;br /&gt;
&lt;br /&gt;
The user can not change the states of the cells while the automation is running.&lt;br /&gt;
&lt;br /&gt;
Once the game is started, the states of the cells in the next frame are calculated for all cells in the grid based on the following rules:&lt;br /&gt;
* If a live cell has fewer than two live neighbours, it dies,&lt;br /&gt;
* If a live cell has two or three live neighbours, it lives,&lt;br /&gt;
* If a live cell has more than five live neighbours, it dies,&lt;br /&gt;
* If a dead cell has three live neighbours, it becomes alive;&lt;br /&gt;
&lt;br /&gt;
The game calculates and displays new frames until the automation is stopped.&lt;br /&gt;
&lt;br /&gt;
====== Example usage ======&lt;br /&gt;
The user starts up the program and selects some cells to be alive.&lt;br /&gt;
&lt;br /&gt;
The user presses a key to start the game.&lt;br /&gt;
&lt;br /&gt;
The automation runs until the user presses a key to end the game or closes the program.&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114833</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114833"/>
		<updated>2016-11-22T14:02:55Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project,&lt;br /&gt;
* Set up the include and library directories;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114829</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114829"/>
		<updated>2016-11-22T01:59:18Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Exploits */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project,&lt;br /&gt;
* Set up the include and library directories;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language continued, stack smashing&lt;br /&gt;
&lt;br /&gt;
1. Create a function that takes no arguments&lt;br /&gt;
* Call the function&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Using what you have learned:&lt;br /&gt;
* Call the function using assembly,&lt;br /&gt;
* Verify that the function gets called;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Using what you have learned:&lt;br /&gt;
* Create a subtract function,&lt;br /&gt;
* Use assembly to call the subtract function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected and that the value gets stored;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function that internally holds an array of only one void* and takes a void* as a parameter:&lt;br /&gt;
* Write over the bounds of the array and observe what happens,&lt;br /&gt;
* Try passing different pointers to the function;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114692</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114692"/>
		<updated>2016-11-15T14:21:31Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project,&lt;br /&gt;
* Set up the include and library directories;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a integer array d to hold 2 ints,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
9. Using what you have learned:&lt;br /&gt;
* Call the add function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114690</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114690"/>
		<updated>2016-11-15T02:19:03Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practice 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project,&lt;br /&gt;
* Set up the include and library directories;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;br /&gt;
&lt;br /&gt;
Setting up your environment:&lt;br /&gt;
* Create a new empty project,&lt;br /&gt;
* Add a main.cpp file,&lt;br /&gt;
* Under project &amp;quot;Properties -&amp;gt; C/C++ -&amp;gt; Code Generation&amp;quot; set Security Check to Disable Security Check;&lt;br /&gt;
&lt;br /&gt;
To view disassembly:&lt;br /&gt;
* While debugging your program, open the disassembly window at Debug -&amp;gt; Windows -&amp;gt; Disassembly;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create an integer variable i:&lt;br /&gt;
* Assign a value to i,&lt;br /&gt;
* Add 1 to i,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Using what you have learned:&lt;br /&gt;
* Create an integer variable a,&lt;br /&gt;
* Using assembly, assign a value to a,&lt;br /&gt;
* Using assembly, add 1 to a,&lt;br /&gt;
* Verify, that the resulting value is correct;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a character array c to hold 3 characters:&lt;br /&gt;
* Fill in the array one by one,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Using what you have learned:&lt;br /&gt;
* Create a character array d to hold 2 characters,&lt;br /&gt;
* Using assembly, fill the array with data,&lt;br /&gt;
* Verify, that the array is filled with expected values;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Create a simple if:&lt;br /&gt;
* Subtract 1 from int i if i is equal to 2,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Using what you have learned:&lt;br /&gt;
* Create an if conditional, that subtracts 1 from int a if int i and a are equal,&lt;br /&gt;
* Verify, that the conditional works as expected;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Create an add function:&lt;br /&gt;
* The function should return the result of adding two integers passed in as parameters,&lt;br /&gt;
* Call the function and store the result in a variable,&lt;br /&gt;
* Inspect the resulting assembly instructions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
9. Using what you have learned:&lt;br /&gt;
* Call the add function with different values and store the result in a variable,&lt;br /&gt;
* Verify, that the function call works as expected;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114689</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114689"/>
		<updated>2016-11-15T01:29:17Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project,&lt;br /&gt;
* Set up the include and library directories;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Exploits ==&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Assembly language&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114167</id>
		<title>Basics of C/C++ Programming</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Basics_of_C/C%2B%2B_Programming&amp;diff=114167"/>
		<updated>2016-11-08T01:26:49Z</updated>

		<summary type="html">&lt;p&gt;Jtominga: /* Practices */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction==&lt;br /&gt;
&lt;br /&gt;
=== Lecturers ===&lt;br /&gt;
Rait Liiv: rait.liiv@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
Janno Tomingas: janno.tomingas@itcollege.ee&lt;br /&gt;
&lt;br /&gt;
== C ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures ===&lt;br /&gt;
&lt;br /&gt;
1. Week. Introduction to C and C++&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/854d0a23-530c-4b4e-a40a-94b4d613d0a1?ec=true&lt;br /&gt;
&lt;br /&gt;
2. Week. Memory, pointers, datatypes&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c2fd365-3495-4175-a3cb-14b52a001e9e?ec=true&lt;br /&gt;
&lt;br /&gt;
3. Week. Runtime, stack, heap (dynamic) memory, linker, declaration + definition&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/a4f70f62-3569-4abc-bf81-638ef9e0da7f?ec=true&lt;br /&gt;
&lt;br /&gt;
4. Week. Stack, heap, pointer, jumps, typedef&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/8e0deb8d-ffab-4a0a-9456-78428674ccb3?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Write a program, that outputs &amp;quot;Hello, World!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. Write a program, that asks the user for a number and then writes the number back to the user&lt;br /&gt;
&lt;br /&gt;
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Functions, pointers, out variables, function return values as success/error codes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a function that adds two integers, outputs the result via an out variable and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int add(int a, int b, int* out)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a function that swaps two integers and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int swap(int* a, int* b)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;3. Write a function that reverses a string and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int reverse(char* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;4. Write a function that sorts an array of ints and returns 0 to indicate a successful operation.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  int sort(int* string, size_t length)&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
File input/output, dynamic memory allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a program that outputs the contents of a text file into the console.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Always close the file stream after you are done using it.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that reads the contents of a text file into a dynamically sized array and outputs the information into a new file.&lt;br /&gt;
Hint:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Use &amp;quot;fseek&amp;quot;, &amp;quot;ftell&amp;quot; and &amp;quot;rewind&amp;quot; to find out how large the buffer should be.&lt;br /&gt;
&lt;br /&gt;
Make sure you have enough room for a null terminator.&lt;br /&gt;
&lt;br /&gt;
Remember to free the allocated memory after calling malloc or calloc.&lt;br /&gt;
&lt;br /&gt;
Make sure to check for error codes.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Dynamic memory allocation continued, structs, .h/.c files&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an implementation of a stack data structure ([https://en.wikipedia.org/wiki/Stack_(abstract_data_type) Stack (abstract data type)]) that uses a dynamically allocated array for storage.&lt;br /&gt;
* Required functions:&lt;br /&gt;
** init - Initializes stack&#039;s variables and allocates required dynamic memory with an initial(default) size,&lt;br /&gt;
** destroy - Frees all allocated memory and optionally resets other stored information for a stack,&lt;br /&gt;
** push - Adds an element to the top of the stack,&lt;br /&gt;
** peek - Gets the top element of the stack,&lt;br /&gt;
** pop - Gets and removes the top element of the stack;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Describe the stack struct and functions in a separate .h file,&lt;br /&gt;
* Implement the functions in a corresponding .c file,&lt;br /&gt;
* Test your stack with some operations. Remember to check for edge cases;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;Hints:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
*How do you know which element to access?&lt;br /&gt;
*How do you know if an array is full?&lt;br /&gt;
*How should the functions behave when a stack is empty?&lt;br /&gt;
*How should the functions behave when a stack is full?&lt;br /&gt;
*What will happen if any of the functions are called unexpectedly many times?&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Assignment ===&lt;br /&gt;
Write a program that reads values from a file and outputs the result to stdout.&lt;br /&gt;
&lt;br /&gt;
====== Input ======&lt;br /&gt;
Input file&#039;s name is &amp;quot;input.txt&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The file contains index-value pairs of integers on a single line. Integers in a pair are separated with a comma (,) and pairs are separated with a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
All indices between 0 and (count_of_pairs - 1) are guaranteed to be present.&lt;br /&gt;
&lt;br /&gt;
The indices are guaranteed to be unique.&lt;br /&gt;
&lt;br /&gt;
The indices are not guaranteed to appear in an ascending order.&lt;br /&gt;
&lt;br /&gt;
Sample input:&lt;br /&gt;
1,4;0,2;2,8&lt;br /&gt;
&lt;br /&gt;
====== Output ======&lt;br /&gt;
The program should output the differences between consecutive values as the index increases.&lt;br /&gt;
&lt;br /&gt;
Output should be printed as a comma separated list of values on a single line to stdout.&lt;br /&gt;
&lt;br /&gt;
For input:&lt;br /&gt;
 0,1;2,4;1,2&lt;br /&gt;
&lt;br /&gt;
Calculates:&lt;br /&gt;
 0,1 to 1,2 -&amp;gt; 2 - 1 = 1&lt;br /&gt;
 1,2 to 2,4 -&amp;gt; 4 - 2 = 2&lt;br /&gt;
&lt;br /&gt;
And outputs:&lt;br /&gt;
 1,2&lt;br /&gt;
&lt;br /&gt;
====== Examples ======&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
 0,2 -&amp;gt; 0&lt;br /&gt;
 1,2;0,1 -&amp;gt; 1&lt;br /&gt;
 1,4;0,2;2,8 -&amp;gt; 2,4&lt;br /&gt;
 1,4;0,2;2,-2 -&amp;gt; 2,-6&lt;br /&gt;
&lt;br /&gt;
== C++ ==&lt;br /&gt;
&lt;br /&gt;
=== Lectures C++ ===&lt;br /&gt;
&lt;br /&gt;
5, 6, 7 Week. C++, class, namespace, new + delete, reference, libraries, bool.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/6b331ce5-dcc9-4bbf-a490-13d40bef2812?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/4c009949-e8b4-43a0-adc0-8ed055baf7b9?ec=true&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/f994eebc-39c8-4ea8-8056-d358d89b329c?ec=true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. Week. Const. + Additional leftover from previous lectures.&lt;br /&gt;
&lt;br /&gt;
https://echo360.e-ope.ee/ess/echo/presentation/95e5962a-3d0b-489f-a759-86dd7a29f2ef?ec=true&lt;br /&gt;
&lt;br /&gt;
=== Practices ===&lt;br /&gt;
&lt;br /&gt;
====== Practice 1 ======&lt;br /&gt;
Console input/output, strings, references, arrays, new/delete&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;1. Write a simple calculator, that takes a simple binary operation (+,-,*,/) as an input and outputs the result to the console on a new line.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  1 + 2 -&amp;gt; 3&lt;br /&gt;
  3 * 8 -&amp;gt; 24&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;2. Write a program that asks the user for several strings and outputs the total numbers of characters entered.&lt;br /&gt;
* Ask for the number of strings the user will enter,&lt;br /&gt;
* Store all input strings in in an appropriately sized array,&lt;br /&gt;
* Use a function to count the total number of characters entered;&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Input:&lt;br /&gt;
 3&lt;br /&gt;
 one&lt;br /&gt;
 two&lt;br /&gt;
 three&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 11&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====== Practice 2 ======&lt;br /&gt;
Classes, constructors/destructors, member functions, intro to templates, vector&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a class Rectangle, that:&lt;br /&gt;
* Stores the width and height as private member variables,&lt;br /&gt;
* Uses a constructor to set width and height,&lt;br /&gt;
* Has public member functions to calculate and return the area and circumference of the rectangle;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program that uses std::vector to store several Rectangles and computes the total area of all stored rectangles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Convert the stack (Practice 4 of C) from C to C++:&lt;br /&gt;
* Replace the struct with a class,&lt;br /&gt;
* Add member functions,&lt;br /&gt;
* Make use of constructors and destructors,&lt;br /&gt;
* Adjust member functions to return values on success (and, for the bold, throw on failure),&lt;br /&gt;
* Use a class template to describe the datatype stored in the struct;&lt;br /&gt;
&lt;br /&gt;
====== Practice 3 ======&lt;br /&gt;
Inheritance, dynamic polymorphism, unique_ptr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create classes Rectangle and Circle, that:&lt;br /&gt;
* Store necessary data as private member variables,&lt;br /&gt;
* Have a public member function to calculate and return their area;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a program, that:&lt;br /&gt;
* Creates and stores some Rectangles and Circles,&lt;br /&gt;
* Calculates the total area of the shapes;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a base class for previously created objects, called Shape:&lt;br /&gt;
* Create a public virtual member function area,&lt;br /&gt;
* Create a protected member variable to store the number of a Shape&#039;s corners in,&lt;br /&gt;
* Modify both Rectangle and Circle to inherit Shape and override the virtual function,&lt;br /&gt;
* Modify your program to store Shapes in a vector of unique pointers to Shape;&lt;br /&gt;
&lt;br /&gt;
[https://wiki.itcollege.ee/index.php/Basics_of_C/C%2B%2B_Programming_Practice_7_Code Sample code]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Add a class Triangle, that inherits from Shape:&lt;br /&gt;
* Store the necessary data,&lt;br /&gt;
* Create the necessary functions,&lt;br /&gt;
* Use all the Shapes in your program;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add a function to calculate the Shapes&#039; circumference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. (optional) Similarly to the Shapes, create a hierarchy of Animals, that:&lt;br /&gt;
* Know their name,&lt;br /&gt;
* Can write out the sound they make;&lt;br /&gt;
&lt;br /&gt;
Use your Animals in a simple program.&lt;br /&gt;
&lt;br /&gt;
====== Practice 4 ======&lt;br /&gt;
Overloading, template functions, template classes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a new header file:&lt;br /&gt;
* Create a function add - int add (int a, int b),&lt;br /&gt;
* Create separate implementations of the add function for floats, doubles, and strings,&lt;br /&gt;
* Try out the functions;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Template the add function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a simple templated Queue ([https://en.wikipedia.org/wiki/Queue_(abstract_data_type) Queue (abstract data type)]), that:&lt;br /&gt;
* Uses a container to store the items in,&lt;br /&gt;
* Has a member function to add items to the queue (enqueue),&lt;br /&gt;
* Has a member function to get items from the queue (dequeue);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a template class Accumulator, that:&lt;br /&gt;
* Stores an instance of the templated type as a member variable,&lt;br /&gt;
* Sets the initial value of the variable via the constructor,&lt;br /&gt;
* Has a member function to add to the stored value,&lt;br /&gt;
* Has a member function to retrieve stored value;&lt;br /&gt;
You may assume the templated type is not a pointer and has operator+= defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. (optional, self-research) Create a class Distance, that can be used with the Accumulator:&lt;br /&gt;
* Store the value in a member variable,&lt;br /&gt;
* Overload operator+= to support addition between two instances of the Distance class,&lt;br /&gt;
Additional information on operators and operator overloading can be found at [http://en.cppreference.com/w/cpp/language/operators operator overloading].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 5 ======&lt;br /&gt;
Function pointers, lambdas, std::function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create a function that counts the number of odd numbers in a container of ints:&lt;br /&gt;
* Implement the function,&lt;br /&gt;
* Store the function pointer in a variable,&lt;br /&gt;
* Use the function;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Create a lambda that returns the position of the first negative number in a container of ints:&lt;br /&gt;
* Implement the lambda,&lt;br /&gt;
* Store the lambda in a variable,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Create a lambda that calculates the factorial of an int:&lt;br /&gt;
* Implement the lambda capturing the number by value,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Create a lambda that adds all non-negative numbers in a previously defined container of ints:&lt;br /&gt;
* Implement the lambda capturing the container by reference,&lt;br /&gt;
* Use the lambda;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Create a function zero_if, that:&lt;br /&gt;
* Takes a reference to container of ints as its first argument,&lt;br /&gt;
* Takes a comparison function as its second argument (has an integer as its parameter and returns a bool),&lt;br /&gt;
* Returns void,&lt;br /&gt;
* If the comparison function returns true for an int, sets its value to 0;&lt;br /&gt;
When zeroing all odd numbers in a vector&lt;br /&gt;
  [1, 2, 3, 4, 5]&lt;br /&gt;
The function should return&lt;br /&gt;
  [0, 2, 0, 4, 0]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Use the created function with newly created lambdas and functions.&lt;br /&gt;
Sample usage might be to zero all negative integers in a vector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 6 ======&lt;br /&gt;
STL Algorithms, lambdas in use&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Find the largest element in a container of ints.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
2. Sort a vector of ints using:&lt;br /&gt;
* Sort the container into ascending order,&lt;br /&gt;
* Provide a custom Compare function to sort the vector into descending order;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. From a vector of ints remove all negative values (erase-remove):&lt;br /&gt;
* Use std::remove_if to move all elements to be deleted to the end of the vector,&lt;br /&gt;
* Use the vector erase method to delete all the elements from the vector;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. From a vector of strings count the number of strings, that have a length greater than 5 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. From a vector of strings remove all strings that have a length under 3 characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Reverse all strings in a vector of strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Practice 7 ======&lt;br /&gt;
Using external libraries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.sfml-dev.org/ SFML] and create a new project,&lt;br /&gt;
* Set up the include and library directories;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. Create an empty window and an initial game loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Draw a white rectangle somewhere on the window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Handle keyboard arrow events to move the rectangle around.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a simple snake game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Simulate the movement of the snake:&lt;br /&gt;
* Divide the window in a grid to help with movement and collision detection,&lt;br /&gt;
* After each frame, draw a new rectangle to the right from the old one,&lt;br /&gt;
* Make it possible to change the &amp;quot;moving&amp;quot; direction with arrow keys,&lt;br /&gt;
* Do not let the rectangle leave the screen, have it wrap around to the opposite edge instead;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Add the tail:&lt;br /&gt;
* Keep track of how long the snake should be,&lt;br /&gt;
* Start with having one rectangle in a container (for example an std::deque),&lt;br /&gt;
* Add the new rectangle (see part 4) to the start of the container each turn,&lt;br /&gt;
* Remove the last rectangle once the tail grows too long;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Add collision checking:&lt;br /&gt;
* Once the first rectangle (head of the snake) overlaps with either food or its tail, perform an action,&lt;br /&gt;
* If the head overlaps with tail, end the game,&lt;br /&gt;
* If the head overlaps with food, grow the tail;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Add food:&lt;br /&gt;
* At the start of the game, spawn the food at a random unoccupied location on the screen,&lt;br /&gt;
* When the snake eats the food, spawn more food;&lt;/div&gt;</summary>
		<author><name>Jtominga</name></author>
	</entry>
</feed>