summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-08-10 23:48:10 +0200
committerOskar <[email protected]>2024-08-10 23:48:10 +0200
commitc6a3ec820eeb105752b833c9f5e44f0244a41c6d (patch)
treec24ee5eb624c1741f3cc469f42666c42b72a0689
parent2ecf623735023e8fc2a4029e4653f0bd591e6052 (diff)
more
-rw-r--r--3p25.cpp42
-rw-r--r--gradeclustering-example.cpp35
2 files changed, 77 insertions, 0 deletions
diff --git a/3p25.cpp b/3p25.cpp
new file mode 100644
index 0000000..44f33de
--- /dev/null
+++ b/3p25.cpp
@@ -0,0 +1,42 @@
+#include <iostream>
+#include <vector>
+#include "sales_data.hpp"
+#include "sales_item.hpp"
+
+/*
+ *
+ * 3.25
+ *
+ * Just a note to myself, i first finished this
+ * exercise by making a begin variable and also a temporary
+ * variable and incrementing on the temporary one, but
+ * of course you can just do everything directly which
+ * created this ugly thing ++*(scores.begin() + grade / 10);
+ * A bit difficult to read, and i do wonder if its faster
+ *
+ */
+
+using std::string;
+using std::cout;
+using std::cin;
+using std::cerr;
+using std::clog;
+using std::endl;
+using std::vector;
+int main () {
+
+ vector<unsigned> scores(11, 0);
+ unsigned grade;
+ while (cin >> grade) {
+ if (grade <= 100) {
+ ++*(scores.begin() + grade / 10);
+ }
+ }
+
+ for(auto i : scores) {
+ cout << i << " ";
+ }
+
+ cout << endl;
+ return 0;
+}
diff --git a/gradeclustering-example.cpp b/gradeclustering-example.cpp
new file mode 100644
index 0000000..cfa2bdd
--- /dev/null
+++ b/gradeclustering-example.cpp
@@ -0,0 +1,35 @@
+#include <iostream>
+#include <vector>
+#include "sales_data.hpp"
+#include "sales_item.hpp"
+
+/*
+ *
+ * original example from book, added printing out the vector
+ *
+ *
+ */
+
+using std::string;
+using std::cout;
+using std::cin;
+using std::cerr;
+using std::clog;
+using std::endl;
+using std::vector;
+int main () {
+
+ vector<unsigned> scores(11, 0);
+ unsigned grade;
+ while (cin >> grade) {
+ if (grade <= 100)
+ ++scores[grade/10];
+ }
+
+ for(auto i : scores) {
+ cout << i << " ";
+ }
+
+ cout << endl;
+ return 0;
+}