#include "test.hpp" #include #include void menu(){ DataType chosenDataType; Implementation chosenImplementation; unsigned short int choice; do{ std::cout< "; std::cin>>std::ws; std::cin>>choice; }while(choice!=1 && choice!=2); if(choice==1){ lasdtest(); }else if(choice==2){ chosenImplementation = ChooseImplementation(); chosenDataType = ChooseDataType(); UseChosenType(chosenImplementation, chosenDataType); } } DataType ChooseDataType(){ unsigned short int choice; do{ std::cout<<"\nChoose a data type:"< "; std::cin>>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; } Implementation ChooseImplementation(){ unsigned short int choice; do{ std::cout<<"\nChoose an implementation for the binary tree:"< "; std::cin>>std::ws; std::cin>>choice; }while(!(choice>0 && choice<3)); if(choice==1) return Implementation::vector; else if(choice==2) return Implementation::yale; } void UseChosenType(Implementation chosenImplementation, DataType chosenDataType){ if(chosenImplementation == Implementation::vector){ if(chosenDataType == DataType::integer){ MatrixVec mtx; mtx = GenerateIntegerMat(mtx); cout<<"\nThe matrix has been randomly generated.\n"; IntegerFunctions(mtx); }else if(chosenDataType == DataType::ffloat){ MatrixVec mtx; mtx = GenerateFloatMat(mtx); cout<<"\nThe matrix has been randomly generated.\n"; FloatFunctions(mtx); }else if(chosenDataType == DataType::sstring){ MatrixVec mtx; mtx = GenerateStringsMat(mtx); cout<<"\nThe matrix has been randomly generated.\n"; StringFunctions(mtx); } }else if(chosenImplementation == Implementation::yale){ if(chosenDataType == DataType::integer){ MatrixCSR mtx; mtx = GenerateIntegerMat(mtx); cout<<"\nThe matrix has been randomly generated.\n"; IntegerFunctions(mtx); }else if(chosenDataType == DataType::ffloat){ MatrixCSR mtx; mtx = GenerateFloatMat(mtx); cout<<"\nThe matrix has been randomly generated.\n"; FloatFunctions(mtx); }else if(chosenDataType == DataType::sstring){ MatrixCSR mtx; mtx = GenerateStringsMat(mtx); cout<<"\nThe matrix has been randomly generated.\n"; StringFunctions(mtx); } } } template void IntegerFunctions(T& mtx){ unsigned short int choice; do{ std::cout< "; std::cin>>std::ws; std::cin>>choice; std::cout< 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; cout<<" The current dimension of the matrix is " << mtx.RowNumber() << " x " << mtx.ColumnNumber() << endl; cout<<" New dimension: \n"; cout<<" Rows: "; cin>>rows; cout<<" Columns: "; cin>>columns; mtx.RowResize(rows); mtx.ColumnResize(columns); cout<<" Done."; } template void Read(const T& mtx){ ulong row,column; cout<<" Insert the position of the element to read: \n"; cout<<" Row: "; cin>>row; cout<<" Column: "; cin>>column; try{ cout<<" The element in this position is: "< void Insert(T& mtx){ ulong row,column; cout<<" Insert the position of the element to insert: \n"; cout<<" Row: "; cin>>row; cout<<" Column: "; cin>>column; cout<<" Insert the element: "; try{ cin>>mtx(row,column); }catch(out_of_range exc){ cout< 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; int par = 2; mtx.MapPreOrder(fun,(void*)&par); cout<<" Done.\n"; } void MultiplyAnElement(int& data, void* par){ data *= *(int*)par; } template void ProductsElementsLessThan(T& mtx){ int n, acc=1; void (*func)(const int&, const void*, void*) = AccumulateProduct; cout<<" Multipy all elements of the matrix whose value is less than "; cin>>ws>>n; mtx.FoldPreOrder(func, (void*)&n, (void*)&acc); cout<<"\n The result is "< class Matrix, typename Data> void CheckExistence(Matrix& mtx){ Data elementToLookFor; cout<<"\n\n Check existence in the matrix of: "; cin>>ws; cin>>elementToLookFor; cout<<" The element " << ( (mtx.FoldableContainer::Exists(elementToLookFor))? "does" : "does not") << " exist\n\n"; } template