summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_1
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-02-02 10:56:32 +0100
committerSanto Cariotti <dcariotti24@gmail.com>2020-02-02 10:56:32 +0100
commit16ff383ffa8b4a6799ca4647d1a11c1cb78c37a0 (patch)
tree02d81ff3733553e5a1db1cfc04428ff9bfce1f01 /I_anno/Programmazione_1
parentd7e54927ac774b0fdb7d5b87f05738c600b2c0fe (diff)
lab 03/07/19 B
Diffstat (limited to 'I_anno/Programmazione_1')
-rw-r--r--I_anno/Programmazione_1/ex12.cc4
-rw-r--r--I_anno/Programmazione_1/ex13.cc3
-rw-r--r--I_anno/Programmazione_1/h9_3.cc1
-rw-r--r--I_anno/Programmazione_1/h9_6.cc4
-rw-r--r--I_anno/Programmazione_1/lab_28_02_19.cc162
5 files changed, 5 insertions, 169 deletions
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 <memory>
#include <algorithm>
#include <vector>
-#define K2 2
-#define N2 3
using namespace std;
template<int N, int K>
@@ -26,6 +24,7 @@ unique_ptr<double[]> 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<iostream>
-#include<cstdlib>
-#include<cmath>
-#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<char>(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<typename T>
-class C : public A {
-public:
- C(short n, double k, char c) : A{n, c} {
- if(typeid(T) == typeid(short))
- y = static_cast<int>(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<DIM; i++) {
- short n=1+rand()%10;
- switch(rand()%3) {
- case 0:
- {
- vett[i]= new B(n, (double) rand()/RAND_MAX, rand()%('z' - 'a' + 1) + 'a');
- auto temp = dynamic_cast<B&>(*(vett[i]));
- sumb+=temp.foo(5);
- ++cb;
- break;
- }
- case 1:
- vett[i]= new C<double>(n, (double) rand()/RAND_MAX, rand()%('z' - 'a' + 1) + 'a');
- break;
- case 2:
- {
- vett[i]= new C<short>(n, (double) rand()/RAND_MAX, rand()%('z' - 'a' + 1) + 'a');
- auto temp = dynamic_cast<C<short>&>(*(vett[i]));
- sumc+=temp.g(5);
- ++cc;
- }
- }
- }
-
- for(int i=0; i<DIM; i++) {
- cout << *vett[i] << endl;
- }
-
- cout << "avg(foo(5))=" << sumb/cb << " ";
- cout << "avg(g(5))=" << sumc/cc << endl;
-
- cout << endl;
- cout << *vett[0] << endl;
- (*vett[0])[0] = '$';
- cout << *vett[0] << endl;
- return 0;
-}