summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-05-08 09:49:45 +0200
committerGitHub <noreply@github.com>2017-05-08 09:49:45 +0200
commit9ac0d6a1a3009edae1af988a482c3b58951c59fd (patch)
tree81281c886ea3f20c11caf2741461591cd9071ad9 /cpp
parent64ca40e3a2f77adb872900d386b6bfeaf3583960 (diff)
Add files via upload
Diffstat (limited to 'cpp')
-rw-r--r--cpp/compito.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/cpp/compito.cpp b/cpp/compito.cpp
new file mode 100644
index 0000000..ce3863d
--- /dev/null
+++ b/cpp/compito.cpp
@@ -0,0 +1,101 @@
+#include <iostream>
+#define N 5
+
+using namespace std;
+
+struct puntiVendita {
+ string citta;
+ float entrate;
+ float uscite;
+};
+
+struct puntiVendita pV[N];
+bool utili(struct puntiVendita p);
+void carica();
+void ord();
+void visualizza();
+
+int main()
+{
+ carica();
+
+ for(int i = 0; i < N; i++) {
+ if(!utili(pV[i]))
+ cout << "Attenzione" << endl;
+ }
+
+ ord();
+ visualizza();
+
+ return 0;
+}
+
+bool utili(struct puntiVendita p)
+{
+ return ((p.uscite > p.entrate) ? false : true);
+}
+
+void carica()
+{
+ pV[0].citta = "Catania";
+ pV[0].entrate = 380;
+ pV[0].uscite = 245;
+ pV[1].citta = "Ragusa";
+ pV[1].entrate = 231;
+ pV[1].uscite = 175;
+ pV[2].citta = "Siracusa";
+ pV[2].entrate = 214;
+ pV[2].uscite = 227;
+ pV[3].citta = "Messina";
+ pV[3].entrate = 294;
+ pV[3].uscite = 189;
+ pV[4].citta = "Enna";
+ pV[4].entrate = 145;
+ pV[4].uscite = 175;
+}
+
+void ord()
+{
+ struct puntiVendita t;
+ bool s;
+ int last = N-1;
+
+ do {
+ s = false;
+
+ for(int i = 0; i < last; i++) {
+ if(pV[i].entrate > pV[i+1].entrate) {
+ t.citta = pV[i].citta;
+ t.entrate = pV[i].entrate;
+ t.uscite = pV[i].uscite;
+
+ pV[i].citta = pV[i+1].citta;
+ pV[i].entrate = pV[i+1].entrate;
+ pV[i].uscite = pV[i+1].uscite;
+
+
+ pV[i+1].citta = t.citta;
+ pV[i+1].entrate = t.entrate;
+ pV[i+1].uscite = t.uscite;
+
+ s = true;
+ }
+ }
+
+ last--;
+ } while(s);
+}
+
+void visualizza()
+{
+ for(auto i : pV) {
+ cout << i.entrate << endl;
+ }
+}
+
+
+
+
+
+
+