diff --git a/librerie/exercise5/zmytest/test.cpp b/librerie/exercise5/zmytest/test.cpp index 926b895..c1cd4a1 100755 --- a/librerie/exercise5/zmytest/test.cpp +++ b/librerie/exercise5/zmytest/test.cpp @@ -72,13 +72,12 @@ void UseChosenType(Implementation chosenImplementation, DataType chosenDataType) }else if(chosenDataType == DataType::ffloat){ MatrixVec mtx; mtx = GenerateFloatMat(mtx); - //FloatFunctions(mtx); + FloatFunctions(mtx); }else if(chosenDataType == DataType::sstring){ MatrixVec mtx; mtx = GenerateStringsMat(mtx); - - //StringFunctions(mtx); + StringFunctions(mtx); } }else if(chosenImplementation == Implementation::yale){ if(chosenDataType == DataType::integer){ @@ -89,12 +88,12 @@ void UseChosenType(Implementation chosenImplementation, DataType chosenDataType) }else if(chosenDataType == DataType::ffloat){ MatrixCSR mtx; mtx = GenerateFloatMat(mtx); - // FloatFunctions(mtx); + FloatFunctions(mtx); }else if(chosenDataType == DataType::sstring){ MatrixCSR mtx; mtx = GenerateStringsMat(mtx); - //StringFunctions(mtx); + StringFunctions(mtx); } } } @@ -148,6 +147,102 @@ void IntegerFunctions(T& mtx){ }while(choice!=8 && choice!=9); } +template +void FloatFunctions(T& mtx){ + unsigned short int choice; + do{ + std::cout< "; + std::cin>>std::ws; + std::cin>>choice; + std::cout< +void StringFunctions(T& mtx){ + unsigned short int choice; + do{ + std::cout< "; + std::cin>>std::ws; + std::cin>>choice; + std::cout< void Resize(T& mtx){ ulong rows, columns; @@ -197,6 +292,69 @@ void Insert(T& mtx){ } } +template +void ConcatLessThan(T& mtx){ + int n; + string concatenated = ""; + void (*func)(const string&, const void*, void*) = ConcatAString; + + cout<<" Concatenate all elements of the tree whose length is less or equal than "; + cin>>ws>>n; + + mtx.FoldPreOrder(func, (void*)&n, (void*)&concatenated); + cout<<"\n The result is "<< concatenated << endl << endl; +} +void ConcatAString(const string& data, const void* par, void* acc){ + if( ((int)data.length()) <= ((*(int*)par)) ){ + *(string*)acc = *(string*)acc + "-" + data; + } +} + +template +void HeadConcat(T& mtx){ + void (*fun)(string&, void*) = HeadConcatMapAux; + string par; + + cout<<" Concatenate in front the following string: "; + cin>>ws; + cin>>par; + + mtx.MapPreOrder(fun,(void*)&par); + cout<<" Done.\n"; +} +void HeadConcatMapAux(string& data, void* par){ + data = *(string*)par + data; +} + +template +void SumElementsGreaterThan(T& mtx){ + float n, acc = 0; + void (*func)(const float&, const void*, void*) = AccumulateSum; + + cout<<" Sum all elements of the matrix whose value is greater than "; + cin>>ws>>n; + + mtx.FoldPreOrder(func, (void*)&n, (void*)&acc); + cout<<"\n The result is "< (*(float*)par)){ + *(float*)acc += data; + } +} + +template +void CubeElements(T& mtx){ + void (*fun)(float&, void*) = Exponentiation; + float par = 3; + mtx.MapPreOrder(fun,(void*)&par); + cout<<" Done.\n"; +} +void Exponentiation(float& data, void* par){ + data = (-1.0F) * pow(data , *(float*)par ); +} + template void Double(T& mtx){ void (*fun)(int&, void*) = MultiplyAnElement; diff --git a/librerie/exercise5/zmytest/test.hpp b/librerie/exercise5/zmytest/test.hpp index e7dd8b0..db9d91d 100755 --- a/librerie/exercise5/zmytest/test.hpp +++ b/librerie/exercise5/zmytest/test.hpp @@ -35,6 +35,22 @@ template void Read(const T&); template void Resize(T& mtx); +template +void FloatFunctions(T&); +template +void SumElementsGreaterThan(T&); +void AccumulateSum(const float&, const void*, void*); +template +void CubeElements(T&); +void Exponentiation(float&, void*); +template +void StringFunctions(T&); +template +void ConcatLessThan(T&); +void ConcatAString(const string&, const void*, void*); +template +void HeadConcat(T&); +void HeadConcatMapAux(string&, void*); /* ----- generator functions ----- */ DataType ChooseDataType(); //choose data type