Advanced C++ exercises.

Hello everyone. I'm a computer engineering student, actually on the third semester. By now I think I can code in a pretty good level using c++. But I would like some exercises recommendation.

In class we pretty much just do console applications. I learned c++ through them, but now I feel that I'm stuck in this kind of codes. If you guys could recommend me topics or something like that, that you think is good to practice, I would appreciate.

Thanks.

P.S : I already studied basic and object oriented C++. So anything beyond that I would appreciate.
- Do you know how to use source control (e.g., Git)? Learn!
- Do you know how to use a build system (e.g., CMake)? Learn!
Those will almost certainly pay off more in the long term than another C++ exercise at this juncture.

- Find any real life open-source project that interests you. Contribute to it.

- Clone the video game Asteroids (or something similar). Use libraries of your choice. I like SDL2 even though it is written in C.

- Write a program that performs symbolic differentiation of algebraic expressions (i.e., solves your elementary calculus homework).
Do this by parsing some input language, then manipulate the expression tree using the language of term rewriting.

- Implement this snippet from one of @Duthomhas's recent posts:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// N.B.: this header file
#include <duthomhas/for>
#include <iostream>
#include <vector>

int main()
{
  std::vector <int> xs{ 10, 20, 30 };
  std::vector <int> ys{ 40, 50, 60 };
  int dot_product = 0;

  for (auto [x, y] : xs, ys)
    dot_product += x * y;

  std::cout << dot_product << "\n";
}

Part of this exercise is staring at it for a little while before noticing how it works.

The iterator used to traverse the range should offer an interface that accurately reflects the properties of xs and ys. See https://en.cppreference.com/w/cpp/iterator#Iterator_categories for more information.

This one will require a bit more language-technical knowledge than the prior ones.

- Implement std::bind.
Last edited on
@mbozzi,

Good suggestions about using source control and a build system. Would adding learning to debug be too much of an advanced stretch as well?
Thanks. That's a good suggestion.

Maybe add "learn to test code" as well?
Last edited on
Using source control and debugging are two areas I don't do, being a solo hobbyist programmer.

Using an IDE to write, build and test I do.
In class we pretty much just do console applications. I learned c++ through them, but now I feel that I'm stuck in this kind of codes.

That is what C/C++ does, no fancy GUI stuff.

GUI frameworks are available, either 3rd party or "builtin," depending on your operating system.

There's Qt, WxWidgets, FLTK to name a few that are third party libraries that extend what your app can do. There are others I can't remember off the top of my head at the moment.

Then there's Win32. Creates native GUI apps that run on Windows.

mbozzi gave one very good suggestions that would work best in a GUI framework. Clone a video game.

You haven't mentioned what OS and compiler you use. Knowing that could help us refine suggestions.
In a lecture by Stroustrup around 2017, he discusses his approach to teaching C++ to new students.

He observed this tendency to get stuck in console programs and how it depresses enthusiasm of most students, so he decided to include some GUI (using FLTK) in his early teaching courses.

His book, C++ Principles and Practices, is his "text" for this level (through upper intermediate, more advanced than the OP suggests). It includes a discussion and examples uses for FLTK.

Although I'm not enthused about FLTK itself, it is simple, cross platform GUI.

The book itself is recommendable for someone looking to exceed what colleges generally teach about C++. It covers C++14.

Other suggestions here are excellent. I would suggest downloading boost, learn to build it, experiment with some of the libraries there and note that some of modern C++ came from (or through) boost.

@Furry Guy lists the top GUI frameworks (not much else is worth the time). In the 21st century it hardly makes sense to write Windows only applications, which obviates frameworks for Windows only, like MFC, ATL, etc.

Make sure you've fully toured the modern standard library. Josuttis's books are good for this.

Now, on the point of cloning a video game, be mindful that turn based game are more suitable for GUI, but for real time games (especially 3d, but even 2D), GUI isn't so suitable at this point. The old style arcade games, like PACMAN, can be done in GUI frameworks, but ultimately they're not designed for any real time graphics. For that you should look into game engines.

Unfortunately one of the best all around options uses C# for scripting (Unity). It does support native plugins, though, which means you can write for Unity in C++ with some awareness of how to interface C++ to C# code (calling both ways, passing data).

Unreal is all C++ (though they have "painted" scripting options for non-programmers). It is, however, a bit heavy on graphics resources, and while the results are beautiful, it takes more from the hardware just to use it than Unity, and doesn't target mobile devices as well. Both are worthy studies, though.

There are other "programming only" game engines, but they're usually much farther behind in both technology and device coverage. Few use them, and there are too many to list. Sometimes what you need is the real time rendering capability for a tool, like an architectural addon to some modeling software, and for that you can use a rendering engine like Ogre3D.

If you have scientific interests, you may benefit from a number of libraries aimed at such purposes, like Eigen.

The main theme is to explore.



Thanks for the help guys, especially @Niccolo and @mbozzi. I'll absorb what you guys told me.

@Furry Guy, I use Dev C++ on windows.

A friend of mine recommended Stroutstrup to, I'll look for his books.
Last edited on
Make sure your DevC++ is this one -> https://sourceforge.net/projects/orwelldevcpp/

And NOT this one -> https://www.bloodshed.net/devcpp.html
The latter was abandoned in 2005, and last ran on XP.
I'll emphasize studying the standard library, especially the containers. Understand what each container is useful for and how it performs. That will help you learn some fundamentals of computer science, which is essential to writing efficient code.
DevC++, even the Orwell fork, is really outdated. Last release was 2015, the included compiler is even older.

C++14 compatibility is spotty, you can forget being able to use C++17 or later.

DevC++ looks like it will never be updated.

With Windows you can use Visual Studio 2017 or 2019, both are free with the Community edition. Both are up-to-date for supporting all the current C++ standard. (C++17)

Another IDE is Code::Blocks. Last release of the IDE was December 2017, though upgrading the compiler isn't that hard.

You could also get stand-alone compilers like GCC or LLVM and write/build/test/debug your programs the old fashioned way. From a command prompt.
I support @Furry Guy's suggestion of Visual Studio.

Just adding that adding Clang (LLVM C++ compiler) to VS is as simple as checking the option at install (or updating with that later).

Clang has some C++17 support slightly ahead of Microsoft's compiler, and some of the optimizations from Clang are vastly superior.
I've pretty much dropped GCC from my builds these days, except as required by Clang for building on nixen (and testing on Windows with MSYS2). My preferred go-to compilers are VS2019 and Clang.

I prefer to do everything by hand from the terminal/command prompt, but you can get along with just about any decent IDE -- good ones like Code::Blocks will let you target any installed compiler.
Topic archived. No new replies allowed.