In section 25.4.3-4 we provided a class Array_ref claimed to make access to elements of an array simpler and safer. In particular, we claimed to handle inheritance correctly. Try a variety of ways to get a Rectangle* into a vector<Circle*> using an Array_ref<Shape*> but no casts or other operations involving undefined behaviour. This ought to be impossible.
Pages
Monday, 5 December 2022
Chapter 25 // Exercise 17 - Principles & Practice Using C++
In section 25.4.3-4 we provided a class Array_ref claimed to make access to elements of an array simpler and safer. In particular, we claimed to handle inheritance correctly. Try a variety of ways to get a Rectangle* into a vector<Circle*> using an Array_ref<Shape*> but no casts or other operations involving undefined behaviour. This ought to be impossible.
Sunday, 4 December 2022
Chapter 25 // Exercise 16 - Principles & Practice Using C++
Formulate 20 coding style rules (don't just copy those in section 25.6). Apply them to a program of more than 300 lines that you recently wrote. Write a short (a page or two) comment on the experience of applying those rules. Did you find errors in the code? Did the code get clearer? Did some code get less clear? Now modify the set of rules based on this experience.
- Dashed lines between functions (I picked this up from work and now I will put bugs on code reviews if people have forgotten dashed lines)
- UpperCamelCase to be used for object creation, enums to use capital snake case and everything else should use lowerCamelCase (this is in direct violation of Bjarne's R302 but he can suck it, camelCaseForever. I also use Hungarian Notation for vectors sometimes because why be completely consistent?)
- All member variables should be prefixed with m
- All global variables should be prefixed with g
- Function argument parameters should be prefixed with p
- Enums should be prefixed with e and be all uppercase afterwards. Example; ePURPLE_CRAYON
- Where a function argument parameter is not modified in the function, it should always be passed by const reference (unless it's cheaper to just pass by const value)
- References should be used over pointers where possible
- Prefer std::vector over raw arrays
- const_cast should not be used
- Prefer ifndef/define over pragma once
- All local variables should be declared as const/constexpr unless they need to be modified
- Commonly used (non-changing) local variables should be declared in a private namespace in the cpp of the file they are used in
- Avoid mixing static member variables with non-static. Either create a namespace or singleton with all static functions/members
- Try to order member variables in descending size order
- Braces {} should always be on their own line. The only exception is 1 line functions in header files (or empty constructors/destructors)
- Avoid post-fix increment/decrement unless the functionality of post-fix is specifically needed. Always prefer pre-fix increment/decrement
- Includes should be in grouped order of local (""), then global (<>). Each group should be in alphabetical order
- Include what you use. Prefer including in the cpp with forward declares in the header. Only include in the header if you must
- Avoid lambda's. Only use them if you must
Saturday, 3 December 2022
Chapter 25 // Exercise 15 - Principles & Practice Using C++
Measure the time (section 26.6.1) it takes to allocate 10,000 objects of random sizes in the [1000:0)-byte range using new; then measure the time it takes to deallocate them using delete.
Friday, 2 December 2022
Chapter 25 // Exercise 14 - Principles & Practice Using C++
Implement a simple vector that can hold at most N elements allocated from a pool. Test of for N === 1000 and integer elements.
Wednesday, 23 November 2022
Chapter 25 // Exercise 13 - Principles & Practice Using C++
Use TEA (section 25.5.6) to communicate "securely" between two computers. Email is minimally acceptable.
Tuesday, 22 November 2022
Chapter 25 // Exercise 12 - Principles & Practice Using C++
Write out the clear text of the example from section 25.5.6.
The Tiny Encryption Algorithm is one of the fastest and most efficient cryptographic algorithms in existence.It was developed by David Wheeler and Roger Needham at the Computer Laboratory of Cambridge University.It is a Feistel cipher which uses operations from mixed (orthogonal) algebraic groups - XOR, ADD and SHIFT in this case.This is a very clever way of providing Shannon's twin properties of diffusion and confusion which arenecessary for a secure block cipher, without the explicit need for P-boxes and S-boxes respectively.It encrypts 64 data bits at a time using a 128-bit key. It seems highly resistant to differentialcryptanalysis, and achieves complete diffusion (where a one bit difference in the plaintext willcause approximately 32 bit differences in the ciphertext) after only six rounds. Performance on amodern desktop computer or workstation is very impressive.
Monday, 21 November 2022
Chapter 25 // Exercise 11 - Principles & Practice Using C++
Repeat the previous exercise, but keep the bits in a bitset<32>.
Sunday, 20 November 2022
Chapter 25 // Exercise 10 - Principles & Practice Using C++
Look at the bitfield example from section 25.5.5. Write an example that initialises a PPN, then reads and prints each field value, then changes each field value (by assigning to the field) and prints the result. Repeat this exercise, but store the PPN information in a 32-bit unsigned integer and use bit-manipulation operators (section 25.5.4) to access the bits in the word.
Saturday, 19 November 2022
Chapter 25 // Exercise 9 - Principles & Practice Using C++
Friday, 18 November 2022
Chapter 25 // Exercise 8 - Principles & Practice Using C++
Thursday, 17 November 2022
Chapter 25 // Exercise 7 - Principles & Practice Using C++
Wednesday, 16 November 2022
Chapter 25 // Exercise 5, 6 - Principles & Practice Using C++
Tuesday, 15 November 2022
Chapter 25 // Exercise 4 - Principles & Practice Using C++
Monday, 25 July 2022
Chapter 25 // Exercise 3 - Principles & Practice Using C++
Sunday, 24 July 2022
Chapter 25 // Exercise 2 - Principles & Practice Using C++
Thursday, 21 July 2022
Chapter 25 // Exercise 1 - Principles & Practice Using C++
void infinite()
{
unsigned char mx = 160; // very large
for(signed char i = 0; i < max; ++i) cout << int(i) << '\n';
}
Run it and explain why.
Monday, 20 June 2022
Chapter 25 // Drill 3, 4, 5 - Principles & Practice Using C++
- Every bit set
- The lowest (least significant bit) set
- The highest (most significant bit) set
- The lowest byte set
- The highest byte set
- Every second bit set (and the lowest bit 1)
- Every second bit set (and the lowest bit 0)
Sunday, 19 June 2022
Chapter 25 // Drill 1, 2 - Principles & Practice Using C++
Saturday, 18 June 2022
Chapter 24 // Exercise 12 - Principles & Practice Using C++
Friday, 17 June 2022
Chapter 24 // Exercise 11 - Principles & Practice Using C++
Thursday, 16 June 2022
Chapter 24 // Exercise 10 - Principles & Practice Using C++
Wednesday, 15 June 2022
Chapter 24 // Exercise 9 - Principles & Practice Using C++
https://en.cppreference.com/w/cpp/meta
Tuesday, 14 June 2022
Chapter 24 // Exercise 8 - Principles & Practice Using C++
Monday, 13 June 2022
Chapter 24 // Exercise 7 - Principles & Practice Using C++
In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Sunday, 12 June 2022
Chapter 24 // Exercise 6 - Principles & Practice Using C++
Saturday, 11 June 2022
Chapter 24 // Exercise 5 - Principles & Practice Using C++
Friday, 10 June 2022
Chapter 24 // Exercise 4 - Principles & Practice Using C++
Thursday, 9 June 2022
Chapter 24 // Exercise 3 - Principles & Practice Using C++
Wednesday, 8 June 2022
Chapter 24 // Exercise 2 - Principles & Practice Using C++
Tuesday, 7 June 2022
Chapter 24 // Exercise 1 - Principles & Practice Using C++
Monday, 6 June 2022
Chapter 24 // Drill 8 - Principles & Practice Using C++
Sunday, 5 June 2022
Chapter 24 // Drill 7 - Principles & Practice Using C++
Saturday, 4 June 2022
Chapter 24 // Drill 6 - Principles & Practice Using C++
Friday, 3 June 2022
Chapter 24 // Drill 5 - Principles & Practice Using C++
In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Thursday, 2 June 2022
Chapter 24 // Drill 4 - Principles & Practice Using C++
In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Wednesday, 1 June 2022
Chapter 24 // Drills 1, 2, 3 - Principles & Practice Using C++
In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Tuesday, 31 May 2022
[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint
- Replace the cubes with actual "notes"
- Create random spawn points for the notes
- Create a sprint mechanic + realistic jump
- Add sprint and notes to HUD widget
- Change it to night time
- Create a flashlight
- Create a battery mechanic
- Executable
Monday, 30 May 2022
Chapter 23 // Exercises 15 , 16- Principles & Practice Using C++
In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Sunday, 29 May 2022
Chapter 23 // Exercise 14 - Principles & Practice Using C++
In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Saturday, 28 May 2022
Chapter 23 // Exercise 13 - Principles & Practice Using C++
In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.