summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-10-05 16:01:36 +0200
committerOskar <[email protected]>2024-10-05 16:01:36 +0200
commit6d33273f62fb78c481babeda6317d0138974ff02 (patch)
tree7e70ab616485b1ed5bfdc1621f50c498e28d2d13
parentd5fcdab87a013b2c919b66ea9a52b469620ca49f (diff)
more
-rw-r--r--8p4.cpp36
-rw-r--r--8p5.cpp36
-rw-r--r--8p6.cpp46
3 files changed, 118 insertions, 0 deletions
diff --git a/8p4.cpp b/8p4.cpp
new file mode 100644
index 0000000..68a4355
--- /dev/null
+++ b/8p4.cpp
@@ -0,0 +1,36 @@
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <string>
+
+/*
+ *
+ * 8.4
+ *
+ *
+ */
+
+int main (int argc, char **argv) {
+
+ if(argc < 2 || argc > 2) {
+ return 1;
+ }
+
+ std::ifstream file(argv[1]);
+ if(file.fail()) {
+ return 1;
+ }
+
+ std::vector<std::string> fvec;
+ std::string tmp;
+ while(std::getline(file, tmp)) {
+ fvec.push_back(tmp);
+ }
+
+ for(auto a : fvec) {
+ std::cout << a << "\n";
+ }
+
+ std::cout << std::ends;
+ return 0;
+}
diff --git a/8p5.cpp b/8p5.cpp
new file mode 100644
index 0000000..17c6223
--- /dev/null
+++ b/8p5.cpp
@@ -0,0 +1,36 @@
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+
+/*
+ *
+ * 8.5
+ *
+ *
+ */
+
+int main (int argc, char **argv) {
+
+ if(argc < 2 || argc > 2) {
+ return 1;
+ }
+
+ std::ifstream file(argv[1]);
+ if(file.fail()) {
+ return 1;
+ }
+
+ std::vector<std::string> svec;
+ std::string tmp;
+ while(file >> tmp) {
+ svec.push_back(tmp);
+ }
+
+ for(auto a : svec) {
+ std::cout << a << "\n";
+ }
+
+ std::cout << std::ends;
+ return 0;
+}
diff --git a/8p6.cpp b/8p6.cpp
new file mode 100644
index 0000000..a069b2d
--- /dev/null
+++ b/8p6.cpp
@@ -0,0 +1,46 @@
+#include <iostream>
+#include <fstream>
+#include "sales_data.hpp"
+
+/*
+ *
+ * 8.6
+ *
+ *
+ */
+
+int main (int argc, char **argv) {
+
+ if(argc < 2 || argc > 2) {
+ return -1;
+ }
+
+ std::fstream file(argv[1]);
+ if(file.fail()) {
+ return -1;
+ }
+
+ SalesData total;
+ // variable to hold the running sum
+ if (read(file, total)) { // read the first transaction
+ SalesData trans;
+ // variable to hold data for the next transaction
+ while(read(file, trans)) {
+ // read the remaining transactions
+ if (total.isbn() == trans.isbn())
+ // check the isbns
+ total.combine(trans); // update the running total
+ else {
+ print(std::cout, total) << std::endl; // print the results
+ total = trans;
+ // process the next book
+ }
+ }
+ print(std::cout, total) << std::endl;
+ // print the last transaction
+ } else {
+ // there was no input
+ std::cerr << "No data?!" << std::endl;
+ // notify the user
+ }
+}