diff --git a/librerie/exercise5/build.sh b/librerie/exercise5/build.sh index 7a68d4a..5ccdfe1 100755 --- a/librerie/exercise5/build.sh +++ b/librerie/exercise5/build.sh @@ -1,7 +1,7 @@ #! /bin/bash -g++ -g -o main \ +g++-10 -g -o main \ zlasdtest/exercise1/simpletest.cpp zlasdtest/exercise1/fulltest.cpp \ zlasdtest/exercise2/simpletest.cpp zlasdtest/exercise2/fulltest.cpp \ zlasdtest/exercise3/simpletest.cpp zlasdtest/exercise3/fulltest.cpp \ diff --git a/librerie/exercise5/matrix/csr/matrixcsr.cpp b/librerie/exercise5/matrix/csr/matrixcsr.cpp index bd987ce..757a07a 100755 --- a/librerie/exercise5/matrix/csr/matrixcsr.cpp +++ b/librerie/exercise5/matrix/csr/matrixcsr.cpp @@ -293,20 +293,12 @@ void MatrixCSR::debug(){ tmp = tmp->next; } - std::cout << "R VECTOR:" << '\n'; + std::cout << "\nR VECTOR:" << '\n'; for(ulong i=0; i class MatrixCSR : virtual public List>, virtual public Matrix{ // Must extend Matrix -public: //CAMBIARE A PROTETTO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +protected: using Matrix::rows; using Matrix::columns; @@ -35,47 +35,23 @@ public: //CAMBIARE A PROTETTO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | next */ -//public: +public: - // Default constructor MatrixCSR(); - - /* ************************************************************************ */ - - // Specific constructors MatrixCSR(const ulong, const ulong); // A matrix of some specified dimension - /* ************************************************************************ */ - - // Copy constructor MatrixCSR(const MatrixCSR&); - - // Move constructor MatrixCSR(MatrixCSR&&) noexcept; - /* ************************************************************************ */ - - // Destructor virtual ~MatrixCSR(); - /* ************************************************************************ */ - // Copy assignment MatrixCSR& operator=(const MatrixCSR&); - - // Move assignment MatrixCSR& operator=(MatrixCSR&&) noexcept; - /* ************************************************************************ */ - - // Comparison operators bool operator==(const MatrixCSR&) const noexcept; bool operator!=(const MatrixCSR&) const noexcept; - /* ************************************************************************ */ - - // Specific member functions (inherited from Matrix) - void RowResize(const ulong&) override; // Override Matrix member void ColumnResize(const ulong&) override; // Override Matrix member @@ -84,23 +60,14 @@ public: //CAMBIARE A PROTETTO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Data& operator()(const ulong, const ulong) override; // Override Matrix member (mutable access to the element; throw out_of_range when out of range) const Data& operator()(const ulong, const ulong) const override; // Override Matrix member (immutable access to the element; throw out_of_range when out of range and length_error when not present) - /* ************************************************************************ */ - - // Specific member functions (inherited from Container) - void Clear() override; // Override Container member /* ************************************************************************ */ // Specific member functions (inherited from MappableContainer) - virtual void MapPreOrder(const typename MappableContainer::MapFunctor, void*) override; // Override MappableContainer member - virtual void MapPostOrder(const typename MappableContainer::MapFunctor, void*) override; // Override MappableContainer member - - /* ************************************************************************ */ - - // Specific member functions (inherited from FoldableContainer) - + virtual void MapPreOrder(const typename MappableContainer::MapFunctor, void*) override; // Override MappableContainer member + virtual void MapPostOrder(const typename MappableContainer::MapFunctor, void*) override; // Override MappableContainer member virtual void FoldPreOrder(const typename FoldableContainer::FoldFunctor, const void*, void*) const override; // Override FoldableContainer member virtual void FoldPostOrder(const typename FoldableContainer::FoldFunctor, const void*, void*) const override; // Override FoldableContainer member diff --git a/librerie/exercise5/zlasdtest/test.cpp b/librerie/exercise5/zlasdtest/test.cpp index 9d6a50c..443ad27 100755 --- a/librerie/exercise5/zlasdtest/test.cpp +++ b/librerie/exercise5/zlasdtest/test.cpp @@ -19,14 +19,14 @@ using namespace std; void lasdtest() { cout << endl << "~*~#~*~ Welcome to the LASD Test Suite ~*~#~*~ " << endl; - // testSimpleExercise1(); - // testFullExercise1(); - // testSimpleExercise2(); - // testFullExercise2(); - // testSimpleExercise3(); - // testFullExercise3(); - // testSimpleExercise4(); - // testFullExercise4(); + testSimpleExercise1(); + testFullExercise1(); + testSimpleExercise2(); + testFullExercise2(); + testSimpleExercise3(); + testFullExercise3(); + testSimpleExercise4(); + testFullExercise4(); testSimpleExercise5(); testFullExercise5(); cout << endl << "Goodbye!" << endl; diff --git a/librerie/exercise5/zmytest/test.cpp b/librerie/exercise5/zmytest/test.cpp index c6b8bb5..926b895 100755 --- a/librerie/exercise5/zmytest/test.cpp +++ b/librerie/exercise5/zmytest/test.cpp @@ -1,28 +1,13 @@ #include "test.hpp" -#include"../matrix/matrix.hpp" -#include"../matrix/csr/matrixcsr.hpp" -#include"../matrix/vec/matrixvec.hpp" -#include "../zlasdtest/test.hpp" -#include -using namespace std; -using namespace lasd; +#include +#include -void ciao (MatrixCSR& a, MatrixCSR& b) -{ - std::cout << "A" << '\n'; - MatrixCSR c(std::move(a)); - - std::cout << "B" << '\n'; - a=std::move(b); - a.debug(); - - std::cout << "C" << '\n'; - b=std::move(c); -} - void menu(){ + DataType chosenDataType; + Implementation chosenImplementation; + unsigned short int choice; do{ @@ -35,7 +20,364 @@ void menu(){ }while(choice!=1 && choice!=2); if(choice==1){ lasdtest(); - }else{ - + }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); + IntegerFunctions(mtx); + + }else if(chosenDataType == DataType::ffloat){ + MatrixVec mtx; + mtx = GenerateFloatMat(mtx); + //FloatFunctions(mtx); + + }else if(chosenDataType == DataType::sstring){ + MatrixVec mtx; + mtx = GenerateStringsMat(mtx); + + //StringFunctions(mtx); + } + }else if(chosenImplementation == Implementation::yale){ + if(chosenDataType == DataType::integer){ + MatrixCSR mtx; + mtx = GenerateIntegerMat(mtx); + IntegerFunctions(mtx); + + }else if(chosenDataType == DataType::ffloat){ + MatrixCSR mtx; + mtx = GenerateFloatMat(mtx); + // FloatFunctions(mtx); + + }else if(chosenDataType == DataType::sstring){ + MatrixCSR mtx; + mtx = GenerateStringsMat(mtx); + //StringFunctions(mtx); + } + } +} + + +template +void IntegerFunctions(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 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<<"\nThe result is "< class Matrix, typename Data> +void CheckExistence(Matrix& mtx){ + Data elementToLookFor; + cout<<"\n\nCheck existence in the matrix of: "; + cin>>ws; + cin>>elementToLookFor; + cout<<"The element " << ( (mtx.FoldableContainer::Exists(elementToLookFor))? "does" : "does not") << " exist\n\n"; +} + +template