1

I'm interested in learning C, and one of the things I like to do when I'm first learning a language is to try a handful of Project Euler questions.

If I were doing this in C#, I would write an interface that all of my questions would implement, and I would include things like a PrintSolution() method and a ProblemStatement property. Then I would create a custom class in individual files for each question, using a naming convention like Problem1.cs... Problem123.cs, etc. Each of these objects would implement the problem interface. This allows me to start fresh with each question instead of writing potentially long methods called SolveProblem1, SolveProblem2, etc. in one file, and then choosing which one to call in main.

Finally, for testing or revisiting a problem, I would have a driver class with a main method, and then to quickly show the solution to any problem I had solved, I could call this (replacing the 1 with the number of the problem I wanted):

Problem1 testProblem = new Problem1(); 
testProblem.PrintSolution();
Console.Read();

I know C isn't an object-oriented language, but is there a similar way to architect a solution in Visual Studio such that I can keep all my code in one location and run the answer to a problem on the fly?

1 Answers1

0

Pointers to functions may help you to achieve the desirable code composition in a procedural world.

Function pointers in C

Community
  • 1
  • 1
Lionishy
  • 188
  • 1
  • 2
  • 10