![]() ![]() I don't see anything else you could do unless you want to get ridiculous and make a coefficient type and an exponent type. You put them in the order people are used to writing them and have named them appropriately. In terms of clarifying which argument to the constructor is the coefficient and which is the exponent, I think you've done what you can. Parsing strings can be error prone, so I tend to dislike this particular solution, but it does make it nice for the caller. In this case the c variables would be coefficients and the e variables would be exponents. ![]() It could be in some format like "c1,e1 c2,e2 " etc. Have a constructor or factory function that takes a string that you parse.)įor (int i = 0 i addTerm(va_arg(ap, term)) ![]() Write a factory function that uses variadic arguments.There are a few other options, though it's not clear that they are better. You ask, "How could I improve this sigma calculator library, so it is easier to use?" You talk about the fact that a user of this class will have to call addTerm repeatedly to make use of it. This code is really straightforward and easy to understand. Term(int coef, int exp) : coef(coef), exp(exp) įor (auto it = poly.begin() it != poly.end() ++it)ĭouble sigma(int start, int end, polynomial rule)ĭouble sigma(int start, int end, term rule)Īlso I feel the performance of the substitute calls are slow, because there are many of them being done. Also when passing values to the term constructor it's unclear which argument is the coefficient and which is the exponent, unless you think about it a little. How could I improve this sigma calculator library, so it is easier to use? For example, the polynomial class is clumsy because I am not able to pass just a list of terms to the constructor, I must use the addTerm function instead. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |