For an integer specified as the target, 6 other integers and four
operations (addition, subtraction, multiplication and Develop a class
that finds out how to calculate using partition with the C ++
programming language.
As an example, if the target number is 302 and the given numbers are
2, 3, 7, 10, 25, and 50, your class would say "(((2 + 10) * 3) * 7)
+50)" Or a different equivalent solution should generate as std :: string.
********************************************************************* // NameSurname.hpp
#include "INumberSearch.h" namespace Name Surname { class NumberSearch: public INumberSearch { public: … // Number to reach
(302) void SetTargetNumber (const int value) ( // TODO } //
Accept numbers as a space separated values: “2 3 7 10 25 50” void
SetInputNumbers (const std :: string & values) ( // TODO } //
Return result as a string ready to evaluate: “(((2 + 10) * 3) * 7)
+50)” const std :: string & GetSolution () ( // TODO } … }; } // namespace NameSurname
The definition of the specified interface class is as follows: class INumberSearch { virtual ~ INumberSearch () {} virtual void
SetTargetNumber (const int value) = 0; virtual void SetInputNumbers
(const std :: string & values) = 0; virtual const std :: string &
GetSolution () = 0; };
Conditions and criteria: [1] Only the .hpp file containing the solution class should be passed. Other additional class definitions
that may be needed, It can be done in the same file in user namespace.
[2] With modern C ++ (C ++ 11 or C ++ 14) without using an external
class library (Qt, Boost, etc.) will be developed. [3] The user class
will be accessed by using the interface class in the verifications to
be made. [4] In the result value showing the calculations, the order
of operation will not be considered, whether the solution is provided
or not will be checked. If more than one solution is found, it is
sufficient to return to the first solution. [5] In order to ignore the
operator priorities, all operations in the solution are should be
grouped. [6] The results of the division between integers should only
be used in the solution if they are integers. [7] Input numbers must
be used once during calculation; all numbers must be used is not
Can you help with the solution of the problem? I would like to thanks
a lot in advance for your helping and taking time.
Show what you have done, using code tags. Reformat the original post with code code tags and proper formatting so it makes more sense. Show any errors or warnings from compilation verbatim.
This is not a homework site. In other words show some effort on your part, not just dump copy/paste.
What have you attempted so far? What C++ issues are you having?
For the algorithm to find the calculation, how would you do this using pen & paper? Before starting to code, you should do a program design - including the algorithm - and then code from the design.
If you don't know how to find the calculation manually, you won't be able to program it.
does it have to write all the extra () pairs? Its unreadable!
there are surely ways to avoid a full brute force solution, but you can start there, modern computers are so fast that every possible combination of 6 numbers is still only a second's worth of work.
this is the sort of thing that a single stand-alone function can solve easily. a class with an interface on it is insanely overengineered.