It is no secret that CSE 2341 – Data Structures – is a very demanding course. The course requires a great deal of dedication and perseverance. I have received a few requests about what to do over winter break in terms of review and prep. This blog post has some suggestions and links to possibly useful info.
Binary Trees and Binary Search Trees
Trees are a very important data structure, especially binary trees and its variants. Please watch the videos linked below to get up to speed on Trees, Binary Trees, Binary Search Trees.
- Data Structures: Introduction to Trees
- Data Structures: Binary Trees
- Data Structures: Binary Search Trees
- Binary Search Trees: Implementation in C/C++
C++ and Catch – Adding your Own Main Method
When you begin coding on a project, it is perfectly acceptable and even advisable to allow the Catch library to generate the main method for you. That is what the #define CATCH_CONFIG_MAIN (very first line in the tests.cpp file) directive tells Catch to do.
As you transition from implementing the data structures to implementing a higher-level project, you will want to eventually create your own main method. Here is how to transition to using your own main without getting rid of tests and testing.
In QtCreator, follow these steps
- Add a new cpp file to your project that will contain your main driver. If you still have the original main.cpp that was added when you created the project, that is fine to use as well; make sure it is listed in the project explorer on the left side of the code window.
- Comment out#define CATCH_CONFIG_MAIN at the top of the tests.cpp file. This will tell the Catch library NOT to generate its own main method.
- In your main driver file, copy and paste the following code (to start with). Read the comments throughout to help you understand what is going on.
//CATCH_CONFIG_RUNNER tells the catch library that this //project will now explicitly call for the tests to be run. #define CATCH_CONFIG_RUNNER #include "catch.hpp" //A macro used in main to determine if you want to run //the tests or not. If you don't want to run your tests, //change true to false in the line below. #define TEST true /* * runCatchTests will cause Catch to go ahead and * run your tests (that are contained in the tests.cpp file. * to do that, it needs access to the command line * args - argc and argv. It returns an integer that * ultimately gets passed back up to the operating system. * See the if statement at the top of main for * a better overview. */ int runCatchTests(int argc, char* const argv[]) { //This line of code causes the Catch library to //run the tests in the project. return Catch::Session().run(argc, argv); } int main( int argc, char* const argv[] ) { //If the TEST macro is defined to be true, //runCatchTests will be called and immediately //return causing the program to terminate. Change TEST //to false in the macro def at the top of this file //to skip tests and run the rest of your code. if (TEST) { return runCatchTests(argc, argv); } //start working on other parts of your project here. return 0; }
Once you’ve added that code, rebuild your project (Build menu| Rebuild All) then execute your project. Your tests should run as normal.
Every Kid Should Know How to Code
There’s no arguing with the fact that technology is all around us. So many things have microprocessors in them now that it becomes quite challenging to consider existence without them. Knowing how to interact with and efficiently make use of technology is a MUST for our future leaders (not to sound cliche’ or anything). This also means more that just being able to efficiently read as many Facebook posts as possible or how to find the cheapest flights possible to a chosen destination.
You can imagine how happy I was to read a blog post that hinted at the fact that we really need to be teaching every kid how to code (well, it was actually much more than just a hint…). I feel like the following quote really sums up how I feel about this:
I believe that we should be teaching all our kids to code – every single one, to the ultimate benefit of each of them, their lives and whatever jobs they come to do. But first, we need to tackle an overarching problem – “normal people” simply don’t understand what it means to be able to code.
The last sentence really hits the nail on the head. I would argue that people that know how to code recognize the importance of that skill. Its the rest of the population that we really need to convince. The post goes on to make a great point though: its not about learning a particular programming language. Its more about learning to think logically and how to express that logic
Anyhow, Coding for Success was a fantastic read. Check it out….