From f279107065146a4940f5e73602a1c3c09e58b31d Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 18 Oct 2020 18:56:43 +0200 Subject: chore: name of first year folder --- I_anno/Programmazione_1/lab_28_02_19_C.cc | 185 ------------------------------ 1 file changed, 185 deletions(-) delete mode 100644 I_anno/Programmazione_1/lab_28_02_19_C.cc (limited to 'I_anno/Programmazione_1/lab_28_02_19_C.cc') diff --git a/I_anno/Programmazione_1/lab_28_02_19_C.cc b/I_anno/Programmazione_1/lab_28_02_19_C.cc deleted file mode 100644 index ac53815..0000000 --- a/I_anno/Programmazione_1/lab_28_02_19_C.cc +++ /dev/null @@ -1,185 +0,0 @@ -#include -#include -#include -#define DIM 10 - -using namespace std; - -class A { -public: - A(short m) : len{m} { - srand(time(NULL)); - base = new char[len]; - for(int i = 0; i < len; ++i) { - base[i] = rand()%('z'-'a'+1)+'a'; - } - } - - ~A() { - delete base; - } - - short getLen() { - return len; - } - - virtual string extract(short x) = 0; - virtual void print(ostream& os) = 0; - -protected: - char get(short i) { - return base[i]; - } - -private: - char* base; - short len; -}; - -class B : public A { -public: - B(short m, double p) : A{m} { - for(int i = 0; i < m; ++i) { - switch(get(i)) { - case 'a': - case 'e': - case 'i': - case 'o': - case 'u': - str+=get(i); - } - } - } - - double foo(short s) { - return sin(k+s)/log(s+1); - } - - string extract(short x) override { - string x2{""}; - short inserted{}; - set chars_a; - for(int i = 0; i < getLen(); ++i) - chars_a.insert(get(i)); - - while(inserted < x) { - char r_char = rand()%('z'-'a'+1)+'a'; - if(chars_a.find(r_char) != chars_a.end()) { - x2+=r_char; - ++inserted; - } - } - - return x2; - } - - void print(ostream& os) override { - os << "B: base=["; - for(int i = 0; i < getLen(); ++i) { - os << get(i) << ' '; - } - os << "], str=" << str << ", k=" << k; - } - -private: - string str; - double k; -}; - -class C : public A { -public: - C(short n, int k) : A{n}, y{k} {} - - double g(short w) { - return sin(w+y); - } - - string extract(short x) override { - string x2{""}; - char* narr = new char[x]; - short counter_narr{}; - - for(int i = 0; i < getLen(); ++i) { - switch(get(i)) { - case 'a': - case 'e': - case 'i': - case 'o': - case 'u': - break; - default: - narr[counter_narr++] = get(i); - } - } - for(int i = 0; i < x; ++i) - x2+=narr[i]; - - delete[] narr; - - return x2; - } - - void print(ostream& os) override { - os << "C: base=["; - for(int i = 0; i < getLen(); ++i) { - os << get(i) << ' '; - } - os << "], y=" << y; - } - - C operator++(int) { - C temp{*this}; - - y++; - - return temp; - } -private: - int y; -}; - -ostream& operator<<(ostream& os, A& a) { - a.print(os); - - return os; -} - -int main() { - A *vett[DIM]; - - double sum{}; - short i_c{-1}; - for(int i=0; i(vett[i]); - sum+=cref->g(5); - i_c = i; - break; - } - case 1: { - vett[i]= new B(n, rand()/(double) RAND_MAX); - auto bref = dynamic_cast(vett[i]); - sum+=bref->foo(5); - break; - } - } - } - - for(int i=0; i