From 16ff383ffa8b4a6799ca4647d1a11c1cb78c37a0 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 2 Feb 2020 10:56:32 +0100 Subject: lab 03/07/19 B --- I_anno/Programmazione_1/ex12.cc | 4 +- I_anno/Programmazione_1/ex13.cc | 3 +- I_anno/Programmazione_1/h9_3.cc | 1 + I_anno/Programmazione_1/h9_6.cc | 4 +- I_anno/Programmazione_1/lab_28_02_19.cc | 162 -------------------------------- 5 files changed, 5 insertions(+), 169 deletions(-) delete mode 100644 I_anno/Programmazione_1/lab_28_02_19.cc (limited to 'I_anno/Programmazione_1') diff --git a/I_anno/Programmazione_1/ex12.cc b/I_anno/Programmazione_1/ex12.cc index deb48ef..ab20cef 100644 --- a/I_anno/Programmazione_1/ex12.cc +++ b/I_anno/Programmazione_1/ex12.cc @@ -35,11 +35,11 @@ string* func(string a[N][N], short k, string s) { int main() { string a[N][N] = { - {"aab", "bbc", "dde"}, + {"aab", "bbc", "4de"}, {"xyb", "bbc", "yz3"}, {"47x", "1y_", "23g"}, }; - string* x = func(a, 3, "bb"); + string* x = func(a, 1, "4"); for(int i = 0; i < N; ++i) cout << x[i] << ' '; diff --git a/I_anno/Programmazione_1/ex13.cc b/I_anno/Programmazione_1/ex13.cc index bc0a6b5..f9f19fa 100644 --- a/I_anno/Programmazione_1/ex13.cc +++ b/I_anno/Programmazione_1/ex13.cc @@ -2,8 +2,6 @@ #include #include #include -#define K2 2 -#define N2 3 using namespace std; template @@ -26,6 +24,7 @@ unique_ptr func(int (&A)[K][N], int (&B)[N][K]) { } int main() { + const int N2 = 3, K2 = 2; int A[K2][N2] = { {3, 7, 10}, {5, 12, 32}, diff --git a/I_anno/Programmazione_1/h9_3.cc b/I_anno/Programmazione_1/h9_3.cc index 9745560..c9ef418 100644 --- a/I_anno/Programmazione_1/h9_3.cc +++ b/I_anno/Programmazione_1/h9_3.cc @@ -4,6 +4,7 @@ // Dato array V=NxM e uno grande W, trovare il numero di elementi presenti in W che sono compresi in ogni riga di V int main() { + std::cout << __cplusplus; const auto N = 4, M = 4, L = 3; int V[N][M] = { {3, 1, 5, 50}, diff --git a/I_anno/Programmazione_1/h9_6.cc b/I_anno/Programmazione_1/h9_6.cc index e8afa45..d889c43 100644 --- a/I_anno/Programmazione_1/h9_6.cc +++ b/I_anno/Programmazione_1/h9_6.cc @@ -14,8 +14,7 @@ int main() { for(auto i = 0; i < N; ++i) { bool finish{false}; - int index{0}; - for(auto j = 0; j < M-1; ++j) { + for(auto j = 0, index = 0; j < M-1; ++j, ++index) { int sum{0}; for(auto zz = index; zz < index+z; ++zz) { sum+=V[i][zz]; @@ -25,7 +24,6 @@ int main() { break; } } - index++; if(finish) break; } } diff --git a/I_anno/Programmazione_1/lab_28_02_19.cc b/I_anno/Programmazione_1/lab_28_02_19.cc deleted file mode 100644 index 4639f66..0000000 --- a/I_anno/Programmazione_1/lab_28_02_19.cc +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include -#define DIM 50 -using namespace std; - -class A { -public: - A(short m, char c) : len{m} { - ptr = new char[len]; - srand(time(NULL)); - for(int i = 0; i < m; ++i) { - ptr[i] = static_cast(rand()%(c-'a'+1) + 'a'); - } - } - A(const A& a) = default; - ~A() { - delete ptr; - } - - virtual string elab(short a, char c) = 0; - virtual void print(ostream& o) = 0; - short getLen() { - return len; - } - - char& operator[](int i) { - return ptr[i]; - } - -protected: - char get(short i) { - if(i > len) - return ptr[0]; - - return ptr[i]; - } - -private: - char* ptr; - short len; -}; - -class B : public A { -public: - B(short m, double y, char c) : A{m, c}, x{y} {} - double foo(short s) { - return sin(x+s)/log(x+s); - } - - string elab(short a, char c) { - string st{}; - for(int i = 0; i < getLen(); ++i) { - auto ch = get(i); - if(abs(ch-c) <= a) { - st+=ch; - } - } - - return st; - } - - void print(ostream& os) { - os << "B ptr=["; - for(int i = 0; i < getLen(); ++i) - os << get(i) << ' '; - - os << "], x=" << x << ", elab(5, z)=" << elab(5, 'z'); - } - -private: - double x; -}; - -template -class C : public A { -public: - C(short n, double k, char c) : A{n, c} { - if(typeid(T) == typeid(short)) - y = static_cast(100*k); - else - y = k; - } - - string elab(short a, char c) { - string st{}; - if(getLen() >= a) { - if(a >= 1) { - for(int i = 0; i < getLen(); st+=c, ++i); - } - } else { - for(int i = 0; i < getLen(); st += get(i++)); - } - - return st; - } - - double g(short w) { - return sin(w+y); - } - - void print(ostream& os) { - os << "C<" << typeid(T).name() << "> ptr=["; - for(int i = 0; i < getLen(); ++i) - os << get(i) << ' '; - - os << "], y=" << y << ", elab(5, z)=" << elab(5, 'z'); - } -private: - T y; -}; - -ostream& operator<<(ostream& os, A& a) { - a.print(os); - - return os; -} - -int main() { - srand(time(NULL)); - - A *vett[DIM]; - short cb{}, cc{}; - double sumb{}, sumc{}; - - for(int i=0; i(*(vett[i])); - sumb+=temp.foo(5); - ++cb; - break; - } - case 1: - vett[i]= new C(n, (double) rand()/RAND_MAX, rand()%('z' - 'a' + 1) + 'a'); - break; - case 2: - { - vett[i]= new C(n, (double) rand()/RAND_MAX, rand()%('z' - 'a' + 1) + 'a'); - auto temp = dynamic_cast&>(*(vett[i])); - sumc+=temp.g(5); - ++cc; - } - } - } - - for(int i=0; i