CISP 400代做、代写C++程序语言、代做STL、代写C++代做Python程序|帮做C/C++编程

CISP 400 – Lab Assignment #11Due December 20, 2018 at 11:59 PMNO EXTENSIONS ARE AVAILABLE FOR THIS ASSIGNMENT UNDER ANYCIRCUMSTANCEThis exercise is an attempt to work with a relatively simple template, as well as using the StandardTemplate Library (STL) from C++. Although this is only intended as a primer, it should give you thebasics and give you an idea of the power and functionality available with these features.This lab involves: Templates. The Standard Template Library (STL)CLASS: DataListThe main class that we will write, we will call DataList. It accepts one type parameter (templateparameter, declared using the template keyword, which we shall refer to as TD) so that it may becustomized. Strictly speaking, the only requirement for this class or data type is that it must becompatible with the this functionality (string and int).It will contain, as a private member, one vector, that we will name data, that uses type TD.It will have a virtual destructor that is empty. It does not need a constructor, but you can provide ablank one if you prefer.It will have several public member functions.Function: append – this function will take an element of type TD and will add it onto the data vector.It must use a method that increases the memory available to the vector if there is insufficient roomcurrently there. It should be able to function indefinitely, e.g. it does not have some specific limit setby the programmer, such as 5 or 6. Technically it does have a limit, but you do not need to worry aboutthat for our purposes.Function: printContents – this function will use an appropriate iterator to progress through the vector.At each element, it will use cout to print each element, on its own separate line. It will continue until itruns out of elements to print, and then it will exit. NOTE: If you are having problems with declaringthe iterator, see the TIPS section.Function: sortContents – this function will take the data vector and sort it using the STL sort function.Function: scrambleContents – this function will take the data vector and shuffle it using the STLshuffle function.Function: isPresent – this function takes one parameter of type TD, and uses the STL to search thevector for the appropriate value. It returns a bool that is true if the parameter has been found, or false ifit has not been found.In addition to the class member functions, we will have one major utility function, which will be anindependent template function, which is not part of our template class.FUNCTION: processListThis function will be a template function that takes one type parameter that we will refer to as type T.The function itself takes two parameters of whatever type is specified by T. These parameters must notbe passed by reference, because we will be passing constants to them, although in a more complicatedsituation involving classes being used as the data type, passing by reference might be much moredesirable. One will be named ‘stop,’ which will be used to determine when we stop taking input. Theother will be named ‘findit.’ Remember, both are of type T, which the template system will compileinto whatever data type the user desires.The function will have a local variable, a DataList instance, which takes the template type specified byT.This function will have an input loop. It will take input, of type T, from the user. It will check to see ifit is equal to the ‘stop’ variable, e.g. if we are working with int, and the stop value is -999, then theprogram will compare user input to stop, and check if the user input -999. If it is, then the input loopterminates. If not, it will append whatever data it has to the DataList object using the appropriatepublic member function.Once it is done, it will print out a copy of the contents of the DataList.It will then scramble (randomly shuffle) the DataList, and print out the contents.It will then sort the DataList and print out the contents.Finally it will search the DataList, and report to the user whether or not the ‘findit’ value has beenfound in the CISP 400作业代做、代写C++程序语言作业、代做STL留学生作业、代写C++实验作业 代做Python程序|帮做Cdata list.Main function:This function will have several constants defined (or you can define them globally if you would like):const string SEARCH_VALUE_STR = “banana”;const string STOP_VALUE_STR = “END”;const int SEARCH_VALUE_INT = 5;const int STOP_VALUE_INT = -999;This function will have a brief menu that asks the user what type of data they want to input – int orstring. It then passes the appropriate const values to the processList function (see the specific name forwhat is appropriate, and match it to the name of the parameter), and exits.TIPS: I have provided many examples and a lot of example code. A great deal more is available onthe Internet. Make use of it.? Do not try to make this program particularly fancy. Be straightforward. There are a lot of waysto go off into nowhere with templates. Considering this is probably your first time using themit’s best just to get it done and make sure it’s right. Less is often more. The “type” parameter is the parameter in angular brackets that you declare with the templatekeyword. Usually it is referred to as ‘T’ in simple situations involving templates. I havereferred to it as type ‘TD’ for the DataList class, and type ‘T’ for the processList() templatefunction. Remember to pass the type parameter to the appropriate places, e.g. make sure youuse the type parameter in the code to processList to declare your instance of DataList. Put all of this code in one file. The compiler does an extremely bad job of providing feedback when there are templateproblems, especially with the STL. Train yourself to ignore the error messages that do notspecifically mention your code. You are seeing a lot of detail that is of no practical use to you. The only time you should write code to differentiate between int and string should be the main()function. As everything else is either a template function or a template class, you should beable to write code for both int and string only once. Do NOT write separate code for each data type. This will receive little or no credit. It wouldbe better to provide partially functioning template code than perfect code that does not properlyuse templates. Remember to declare all iterator objects for STL containers (vector, etc.) using the scopeoperator, passing along appropriate type parameters, and to use the typename keyword in frontof the declaration as needed. See the slides on how to use the ‘shuffle’ STL function. You will probably need a seed for therandom number generator. In order to get this, add #include to the top of the program,and when you need the value, use a call to the ‘time()’ function. Specifically, use‘time(NULL)’, since we do not want to pass it a specific parameter for our purposes. This isnot perfect C++, as it uses a C library function, but it is not worth the time digging around tofind the best C++ way to do this. If all else fails, just give a seed of value ‘1’, as in, the literalinteger value 1 (this will mean that the randomization order will always come out exactly thesame for a given input, but that’s OK for this). Remember: for the searching, sorting, and scrambling STL functions, the .begin() and .end()member functions are your friends. Also look at the examples I have given for a for-loopinvolving iterator objects and these functions. Use the ‘using namespace std’ declaration at the beginning of the program, even if you do notusually use it. STL can be very unforgiving if you make errors during compilation andotherwise you will be chasing down scope operators left and right. You will not be markeddown if you do not do this, but I do not want to spend an hour untangling the error messagesbecause of a typo resulting from something that simple, and I do not want you to take the timeto do that, either. If you are having problems with declaring the appropriate vector iterator in the printContents()function, consider using the ‘typename’ keyword in front of the iterator declaration. C++ cansometimes get confused, when using templates within templates, in terms of what it should treatas a data type, and the typename keyword can sometimes clarify the issue.转自:http://ass.3daixie.com/2018122139915695.html

你可能感兴趣的:(CISP 400代做、代写C++程序语言、代做STL、代写C++代做Python程序|帮做C/C++编程)