diff options
-rw-r--r-- | 7p1.cpp | 33 | ||||
-rw-r--r-- | const-pointer-tests.cpp | 24 | ||||
-rw-r--r-- | sales_data.hpp | 6 |
3 files changed, 63 insertions, 0 deletions
@@ -0,0 +1,33 @@ +#include <iostream> +#include "sales_data.hpp" + +/* + * + * 7.1 + * + * + * Not really sure if we're supposed to add the data of the + * other members but i assume not because now i literally + * just changed 1.24 to fit the sales_data format + */ + +int main () { + + SalesData Item; + SalesData CurItem; + if(std::cin >> CurItem.BookNo >> CurItem.UnitsSold >> CurItem.Revenue) { + int Count = 1; + while(std::cin >> Item.BookNo >> Item.UnitsSold >> Item.Revenue) { + if(Item.BookNo == CurItem.BookNo) { + Count++; + } else { + std::cout << "ISBN: " << CurItem.BookNo << " has " << Count << " transactions" << std::endl; + CurItem = Item; + Count = 1; + } + } + std::cout << "ISBN: " << CurItem.BookNo << " has " << Count << " transactions" << std::endl; + } + + return 0; +} diff --git a/const-pointer-tests.cpp b/const-pointer-tests.cpp new file mode 100644 index 0000000..dceda16 --- /dev/null +++ b/const-pointer-tests.cpp @@ -0,0 +1,24 @@ +#include <iostream> + +/* + * + * Trying to make sense of const + * + * + */ + +int main () { + int a = 0; + int b = 0; + int c = 0; + int const* pointer1 = &a; // Cannot change underlying object, can point to other object (Please for the love of god dont use this version its so confusing, use pointer3 version instead because its the same thing and much more clear + int *const pointer2 = &b; // Can change underlying object, can not point to new object + const int* pointer3 = &c; // Cannot change underlying object, can point to other object + std::cout << pointer1 << "\n" + << pointer2 << "\n" + << pointer3 << std::endl; + + const int *const pointer4 = &a; // Cannot change underlying object, cannot point to another object + std::cout << pointer4 << std::endl; + return 0; +} diff --git a/sales_data.hpp b/sales_data.hpp index cce4469..31929af 100644 --- a/sales_data.hpp +++ b/sales_data.hpp @@ -2,9 +2,15 @@ #define SALES_DATA_H #include <string> struct SalesData { + std::string isbn() const { return BookNo; } + SalesData &combine(const SalesData); + double avg_price() const; std::string BookNo; unsigned int UnitsSold = 0; double Revenue = 0.0; }; +SalesData add(const SalesData&, const SalesData&); +std::ostream &print(std::ostream&, const SalesData&); +std::istream &read(std::istream&, SalesData&); #endif |