#include"test.hpp" #include #include #include "../zlasdtest/test.hpp" void menu(){ unsigned short int choice; DataStructure chosenDataStructure; DataType chosenDataType; do{ std::cout<<"1. Use your tests (to be used by the professor)"<>std::ws; std::cin>>choice; }while(choice!=1 && choice!=2); switch(choice){ case 1: lasdtest(); break; case 2: chosenDataStructure = ChooseDataStructure(); chosenDataType = ChooseDataType(); UseChosenType(chosenDataStructure,chosenDataType); break; default: std::cout<<"An error has occurred"<>std::ws; std::cin>>choice; }while(choice!=1 && choice!=2); if(choice == 1) return DataStructure::vector; else if(choice == 2) return DataStructure::list; } DataType ChooseDataType(){ unsigned short int choice; do{ std::cout<<"Choose a data type:"<>std::ws; std::cin>>choice; }while(!(choice>0 && choice<4)); if(choice==1) return DataType::integer; else if(choice==2) return DataType::ffloat; else if(choice==3) return DataType::sstring; } void UseChosenType(DataStructure chosenDataStructure, DataType chosenDataType){ if(chosenDataStructure == DataStructure::vector){ if(chosenDataType == DataType::integer){ lasd::Vector myvec; myvec = generateVectorOfIntegers(); VectorIntegerFunctions(myvec); }else if(chosenDataType == DataType::ffloat){ lasd::Vector myvec; myvec = generateVectorOfFloat(); VectorFloatFunctions(myvec); }else if(chosenDataType == DataType::sstring){ lasd::Vector myvec; myvec = generateVectorOfStrings(); VectorStringFunctions(myvec); } }else if(chosenDataStructure == DataStructure::list){ if(chosenDataType == DataType::integer){ lasd::List mylist; mylist = generateListOfIntegers(); ListIntegerFunctions(mylist); }else if(chosenDataType == DataType::ffloat){ lasd::List mylist; mylist = generateListOfFloat(); ListFloatFunctions(mylist); }else if(chosenDataType == DataType::sstring){ lasd::List mylist; mylist = generateListOfStrings(); ListStringFunctions(mylist); } } } /* ********** VECTOR FUNCTIONS ********** */ void VectorIntegerFunctions(lasd::Vector myvec){ unsigned short int choice; do{ std::cout<<"Choose one of the following options:"<>std::ws; std::cin>>choice; switch(choice){ case 1: ShowFirstElement(myvec); break; case 2: ShowLastElement(myvec); break; case 3: ShowElementWithASpecificIndex(myvec); break; case 4: ShowAllElements(myvec); break; case 5: CheckElementExists(myvec); break; case 6: SumLessThan(myvec); break; case 7: DoubleIntegers(myvec); break; case 8: std::cout< myvec){ unsigned short int choice; do{ std::cout<<"Choose one of the following options:"<>std::ws; std::cin>>choice; switch(choice){ case 1: ShowFirstElement(myvec); break; case 2: ShowLastElement(myvec); break; case 3: ShowElementWithASpecificIndex(myvec); break; case 4: ShowAllElements(myvec); break; case 5: CheckElementExists(myvec); break; case 6: ProductMoreThan(myvec); break; case 7: SquareFloats(myvec); break; case 8: std::cout< myvec){ unsigned short int choice; do{ std::cout<<"Choose one of the following options:"<>std::ws; std::cin>>choice; switch(choice){ case 1: ShowFirstElement(myvec); break; case 2: ShowLastElement(myvec); break; case 3: ShowElementWithASpecificIndex(myvec); break; case 4: ShowAllElements(myvec); break; case 5: CheckElementExists(myvec); break; case 6: ConcatLessThan(myvec); break; case 7: Uppercase(myvec); break; case 8: std::cout< void ShowFirstElement(lasd::Vector& vec){ std::cout< void ShowLastElement(lasd::Vector& vec){ std::cout< void ShowElementWithASpecificIndex(lasd::Vector& vec){ ulong index; std::cout<<"Insert the index: "; std::cin>>std::ws; std::cin>>index; try{ std::cout< void ShowAllElements(lasd::Vector& vec){ void (*AuxMapPreOrder) (Data&, void*) = PrintSingleElement; std::cout<<"The vector contains:"< void PrintSingleElement(Data& data, void* _){ std::cout << data << " "; } template void CheckElementExists(lasd::Vector& vec){ Data element; std::cout<<"What element do you wanna check its exsistence on? "; std::cin>>std::ws; std::cin>>element; if(vec.Exists(element)) std::cout<<"The element exists"<& vec){ int pivot; ulong acc=0; void (*func)(const int&, const void*, void*) = AccumulateSum; std::cout<<"Which element do you choose to performa a sum under it? "; std::cin>>std::ws; std::cin>>pivot; vec.FoldPreOrder(func, (void*)&pivot, (void*)&acc); std::cout<<"The result of the sum is "<& vec){ void (*fun)(int&, void*) = DoubleAnInteger; vec.MapPreOrder(fun, nullptr); std::cout<& vec){ float pivot, acc=1; void (*func)(const float&, const void*, void*) = AccumulateProduct; std::cout<<"Which element do you choose to perform a product above it? "; std::cin>>std::ws; std::cin>>pivot; vec.FoldPreOrder(func, (void*)&pivot, (void*)&acc); std::cout<<"The result of the product is "< (*(float*)par)){ *(float*)acc *= data; } } void SquareFloats(lasd::Vector& vec){ void (*fun)(float&, void*) = SquareAFloat; vec.MapPreOrder(fun, nullptr); std::cout<& vec){ ulong pivot; std::string acc = ""; void (*func)(const std::string&, const void*, void*) = ConcatAux; std::cout<<"Concat elements whose length is less than: "; std::cin>>std::ws; std::cin>>pivot; vec.FoldPreOrder(func, (void*)&pivot, (void*)&acc); std::cout<<"The concatenated string is "<& vec){ void (*fun)(std::string&, void*) = UppercaseAString; vec.MapPreOrder(fun, nullptr); std::cout<<"The uppercased strings are: "< mylist){ unsigned short int choice; do{ std::cout<<"Choose one of the following options:"<>std::ws; std::cin>>choice; switch(choice){ case 1: ShowFirstElement(mylist); break; case 2: ShowLastElement(mylist); break; case 3: ShowElementWithASpecificIndex(mylist); break; case 4: ShowAllElements(mylist); break; case 5: CheckElementExists(mylist); break; case 6: SumLessThan(mylist); break; case 7: DoubleIntegers(mylist); break; case 8: std::cout< mylist){ unsigned short int choice; do{ std::cout<<"Choose one of the following options:"<>std::ws; std::cin>>choice; switch(choice){ case 1: ShowFirstElement(mylist); break; case 2: ShowLastElement(mylist); break; case 3: ShowElementWithASpecificIndex(mylist); break; case 4: ShowAllElements(mylist); break; case 5: CheckElementExists(mylist); break; case 6: ProductMoreThan(mylist); break; case 7: SquareFloats(mylist); break; case 8: std::cout< mylist){ unsigned short int choice; do{ std::cout<<"Choose one of the following options:"<>std::ws; std::cin>>choice; switch(choice){ case 1: ShowFirstElement(mylist); break; case 2: ShowLastElement(mylist); break; case 3: ShowElementWithASpecificIndex(mylist); break; case 4: ShowAllElements(mylist); break; case 5: CheckElementExists(mylist); break; case 6: ConcatLessThan(mylist); break; case 7: Uppercase(mylist); break; case 8: std::cout< void ShowFirstElement(lasd::List& list){ std::cout< void ShowLastElement(lasd::List& list){ std::cout< void ShowElementWithASpecificIndex(lasd::List& list){ ulong index; std::cout<<"Insert the index: "; std::cin>>std::ws; std::cin>>index; try{ std::cout< void ShowAllElements(lasd::List& list){ void (*AuxMapPreOrder) (Data&, void*) = PrintSingleElement; std::cout<<"The list contains:"< void CheckElementExists(lasd::List& list){ Data element; std::cout<<"What element do you wanna check its exsistence on? "; std::cin>>std::ws; std::cin>>element; if(list.Exists(element)) std::cout<<"The element exists"<& list){ int pivot; ulong acc=0; void (*func)(const int&, const void*, void*) = AccumulateSum; std::cout<<"Which element do you choose to performa a sum under it? "; std::cin>>std::ws; std::cin>>pivot; list.FoldPreOrder(func, (void*)&pivot, (void*)&acc); std::cout<<"The result of the sum is "<& list){ void (*fun)(int&, void*) = DoubleAnInteger; list.MapPreOrder(fun, nullptr); std::cout<& list){ float pivot, acc=1; void (*func)(const float&, const void*, void*) = AccumulateProduct; std::cout<<"Which element do you choose to perform a product above it? "; std::cin>>std::ws; std::cin>>pivot; list.FoldPreOrder(func, (void*)&pivot, (void*)&acc); std::cout<<"The result of the product is "<& list){ void (*fun)(float&, void*) = SquareAFloat; list.MapPreOrder(fun, nullptr); std::cout<& list){ ulong pivot; std::string acc = ""; void (*func)(const std::string&, const void*, void*) = ConcatAux; std::cout<<"Concat elements whose length is less than: "; std::cin>>std::ws; std::cin>>pivot; list.FoldPreOrder(func, (void*)&pivot, (void*)&acc); std::cout<<"The concatenated string is "<& list){ void (*fun)(std::string&, void*) = UppercaseAString; list.MapPreOrder(fun, nullptr); std::cout<<"The uppercased strings are: "< generateListOfStrings(){ ulong dim = getDimension(); lasd::List mylist = lasd::List(); std::default_random_engine gen(std::random_device{}()); std::uniform_int_distribution dist(1,5); for(unsigned long i = 0; i < dim; ++i){ mylist.InsertAtFront(generateRandomString(dist(gen))); } std::cout< generateListOfFloat(){ ulong dim = getDimension(); lasd::List mylist = lasd::List(); std::default_random_engine gen(std::random_device{}()); std::uniform_real_distribution distr(0,5); for(unsigned long i = 0; i < dim; ++i){ mylist.InsertAtFront((round(distr(gen)*10000))/100); } std::cout< generateListOfIntegers(){ ulong dim = getDimension(); lasd::List mylist = lasd::List(); std::default_random_engine gen(std::random_device{}()); std::uniform_int_distribution dist(0,1000); for(ulong i=0 ; i generateVectorOfIntegers(){ ulong dim = getDimension(); lasd::Vector myvec = lasd::Vector(dim); std::default_random_engine gen(std::random_device{}()); std::uniform_int_distribution dist(0,1000); for(ulong i = 0 ; i generateVectorOfFloat(){ ulong dim = getDimension(); lasd::Vector myvec = lasd::Vector(dim); std::default_random_engine gen(std::random_device{}()); std::uniform_real_distribution distr(0,5); for(unsigned long i = 0; i < dim; ++i){ myvec[i] = (round(distr(gen)*10000))/100; } std::cout< generateVectorOfStrings(){ ulong dim = getDimension(); lasd::Vector myvec = lasd::Vector(dim); std::default_random_engine gen(std::random_device{}()); std::uniform_int_distribution dist(1,5); for(unsigned long i = 0; i < dim; ++i){ myvec[i] = generateRandomString(dist(gen)); } std::cout< character('a','z'); char newString[dim+1]; for(int i=0;i>dimension; return dimension; }