I have a final project for C++ class that requires us to demonstrat each thing that we've learned, a list of 24 things that range from using binary numbers, to loops to passing arrays and polymorphism and recursion.
What I would really like to try is to make a simple demo program of each of these items in independant programs,and let the user choose and run each program from a menu. I don't quite know how to implement this, but I was wondering if I can use namespaces and put each program choice in main in a separate namespace. I also get extra points if I can put all the 24 items in the order they were given, which makes a menu driven program ideal.
Or if there is a better way to implement this sort of design, I'd sure appreciate any input.

I don't think that putting them in separate programs is really what you should do, because that's very weird (and could be challenging a bit).

I think that if you want to pursue your idea of the "24 items into 24 blocks of code", then you should create each item as a header / cpp-file duo (or more). Something like this:



void execute_item1();



#include "item1.hpp"

void execute_item1() {
  // ... code for item 1 (e.g., like the "main()" of your item1 program).


#include "item1.hpp"
#include "item2.hpp"
#include "item3.hpp"

int main() {

  while(true) {
    int item_chosen = 0;
    std::cout << "Please enter item to execute: ";
    std::cin >> item_chosen;

    switch(item_chosen) {
      case 0:
        return 0;
      case 1:
      case 2:


        std::cerr << "Error, invalid choice!" << std::endl;


Then you just compile all your cpp files and linked them together. That's the "C++ way" of doing things.

Also, I would note that I doubt that your professor really just wants you to copy-paste your last 24 assignments into a single project. There isn't much "learning" involved in doing that. My guess is that he wants you to come up with a more complete and coherent project that happens to exercise all of your learned skills. That's just something to think about.

This question has already been answered. Start a new discussion instead.