Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a basic understanding of programming and I currently learning C++. I\'m i

ID: 652781 • Letter: I

Question

I have a basic understanding of programming and I currently learning C++. I'm in the beginning phases of building my own CLI program for ubuntu. However, I have hit a few snags and I was wondering if I could get some clarification. The program I am working on is called "sat" and will be available via command line only. I have the main.cpp.

However, my real question is more of a "best practices" for programming/organization. When my program "sat" is invoked I want it to take additional arguments.

Here is an example:

> sat task subtask
I'm not sure if the task should be in its own task.cpp file for better organization or if it should be a function in the main.cpp? If the task should be in its own file how do you accept arguments in the main.cpp file and reference the other file?

Any thoughts on which method is preferred and reference material to backup the reasoning?

Explanation / Answer

There's some personal preference, and some slight design benefits involved. Accepting arguments and passing them to other modules/functions is not an issue. What is at issue is how well the overall architecture will be represented if you split it up, versus if you keep it all in one file.

The main reason for splitting it up should be whether it makes organizational sense to.

If I have a program that deals with Desk and Pig objects, I can split all the Desk related class declaration and definition code into Desk.h and Desk.cpp. Likewise for Pig. If the interfaces to these objects is well-defined, changing how the Desk object is implemented shouldn't change the way your main program runs. But now I'm getting into object-orientated design.

What I'm saying is that if there is a good reason from a design standpoint to split Task up from the main() function, then you should do it. From your post I'm not so sure what you are trying to achieve.

What may help more than my attempt at an answer is Wikipedia's article on software design.