From 7aac5c6dc29079971a5c964762cdb294782b14d5 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 29 Jul 2024 15:22:18 +0200 Subject: more --- 1p23.cpp | 30 ++++++++++++++++++++++++++++++ 1p24.cpp | 30 ++++++++++++++++++++++++++++++ 1p5p2-example.cpp | 25 +++++++++++++++++++++++++ 1p6.cpp | 32 ++++++++++++++++++++++++++++++++ 2p10.cpp | 24 ++++++++++++++++++++++++ 2p12.cpp | 20 ++++++++++++++++++++ 2p13.cpp | 18 ++++++++++++++++++ 2p3-2p4.cpp | 22 ++++++++++++++++++++++ 2p6-2p7-2p8.cpp | 23 +++++++++++++++++++++++ 2p9.cpp | 15 +++++++++++++++ Makefile | 4 ++-- 11 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 1p23.cpp create mode 100644 1p24.cpp create mode 100644 1p5p2-example.cpp create mode 100644 1p6.cpp create mode 100644 2p10.cpp create mode 100644 2p12.cpp create mode 100644 2p13.cpp create mode 100644 2p3-2p4.cpp create mode 100644 2p6-2p7-2p8.cpp create mode 100644 2p9.cpp diff --git a/1p23.cpp b/1p23.cpp new file mode 100644 index 0000000..bb9336e --- /dev/null +++ b/1p23.cpp @@ -0,0 +1,30 @@ +#include +#include "sales_item.hpp" + +/* + * + * 1.24 exercise + * + * + */ + +int main () { + + Sales_item Item; + Sales_item CurItem; + if(std::cin >> CurItem) { + int Count = 1; + while(std::cin >> Item) { + if(Item.isbn() == CurItem.isbn()) { + Count++; + } else { + std::cout << "ISBN: " << CurItem.isbn() << " has " << Count << " transactions" << std::endl; + CurItem = Item; + Count = 1; + } + } + std::cout << "ISBN: " << CurItem.isbn() << " has " << Count << " transactions" << std::endl; + } + + return 0; +} diff --git a/1p24.cpp b/1p24.cpp new file mode 100644 index 0000000..bb9336e --- /dev/null +++ b/1p24.cpp @@ -0,0 +1,30 @@ +#include +#include "sales_item.hpp" + +/* + * + * 1.24 exercise + * + * + */ + +int main () { + + Sales_item Item; + Sales_item CurItem; + if(std::cin >> CurItem) { + int Count = 1; + while(std::cin >> Item) { + if(Item.isbn() == CurItem.isbn()) { + Count++; + } else { + std::cout << "ISBN: " << CurItem.isbn() << " has " << Count << " transactions" << std::endl; + CurItem = Item; + Count = 1; + } + } + std::cout << "ISBN: " << CurItem.isbn() << " has " << Count << " transactions" << std::endl; + } + + return 0; +} diff --git a/1p5p2-example.cpp b/1p5p2-example.cpp new file mode 100644 index 0000000..53ed4bc --- /dev/null +++ b/1p5p2-example.cpp @@ -0,0 +1,25 @@ +#include +#include "sales_item.hpp" + +/* + * + * 1.5.2 example + * + * + */ + +int main() { + + Sales_item item1, item2; + std::cin >> item1 >> item2; + if (item1.isbn() == item2.isbn()) { + std::cout << item1 + item2 << std::endl; + return 0; + } else { + std::cerr << "Data must refer to same ISBN" + << std::endl; + return -1; + } + + return 0; +} diff --git a/1p6.cpp b/1p6.cpp new file mode 100644 index 0000000..71dfd28 --- /dev/null +++ b/1p6.cpp @@ -0,0 +1,32 @@ +#include +#include "sales_item.hpp" + +/* + * + * 1.6 example + * + * + */ + +int main () { + + Sales_item Total; + Sales_item Trans; + if(std::cin >> Total) { + while(std::cin >> Trans) { + if(Trans.isbn() == Total.isbn()) { + Total += Trans; + } else { + std::cout << Total << std::endl; + Total = Trans; + } + } + + std::cout << Total << std::endl; + } else { + std::cerr << "Error" << std::endl; + return -1; + } + + return 0; +} diff --git a/2p10.cpp b/2p10.cpp new file mode 100644 index 0000000..394a0f8 --- /dev/null +++ b/2p10.cpp @@ -0,0 +1,24 @@ +#include +#include "sales_item.hpp" + +/* + * + * 2.10 + * + * + */ + +std::string gl_string; // "" +int gl_val; // 0 + +int main () { + + std::string l_string; // "" + //int l_val; // Undefined behavior + + std::cout << gl_string << std::endl; + std::cout << gl_val << std::endl; + std::cout << l_string << std::endl; + //std::cout << l_val << std::endl; + return 0; +} diff --git a/2p12.cpp b/2p12.cpp new file mode 100644 index 0000000..73eef5c --- /dev/null +++ b/2p12.cpp @@ -0,0 +1,20 @@ +#include +#include "sales_item.hpp" + +/* + * + * 2.12 + * + * + */ + +int main () { + + //int double = 3.14; // Invalid + //int catch-22 = 1; // Invalid + double Double = 3.14; + int __ = 99; // HOW IS THIS VALID + //int 1_or_2 = 2; // Invalid + std::cout << Double << "\n" << __ << std::endl; + return 0; +} diff --git a/2p13.cpp b/2p13.cpp new file mode 100644 index 0000000..2fdb562 --- /dev/null +++ b/2p13.cpp @@ -0,0 +1,18 @@ +#include +#include "sales_item.hpp" + +/* + * 2.13 + * Program does not compile using as many flags as i do. Which is probably a really good idea though. + * + * + */ + +int gi = 42; +int main () { + + int i = 100; + int j = i; + std::cout << gi << " " << i << " " << j << std::endl; + return 0; +} diff --git a/2p3-2p4.cpp b/2p3-2p4.cpp new file mode 100644 index 0000000..dcc0c86 --- /dev/null +++ b/2p3-2p4.cpp @@ -0,0 +1,22 @@ +#include +#include "sales_item.hpp" + +/* + * + * 2.3 and 2.4 + * + * + */ + +int main () { + + unsigned u = 10, u2 = 42; + std::cout << u2 - u << std::endl; // 32 + std::cout << u - u2 << std::endl; // big ass number + int i = 10, i2 = 42; + std::cout << i2 - i << std::endl; // 32 + std::cout << i - i2 << std::endl; // -32 + std::cout << i - u << std::endl; // 0 + std::cout << u - i << std::endl; // 0 + return 0; +} diff --git a/2p6-2p7-2p8.cpp b/2p6-2p7-2p8.cpp new file mode 100644 index 0000000..adec444 --- /dev/null +++ b/2p6-2p7-2p8.cpp @@ -0,0 +1,23 @@ +#include +#include "sales_item.hpp" + +/* + * + * 2.6, 2.7, 2.8 + * + * + */ + +int main () { + + int month1 = 9; + int day1 = 7; + //int month2 = 09; // Invalid! + //int day2 = 07; + std::cout << "month1: " << month1 << " day1: " << day1 << std::endl; + std::cout << "Who goes with F\145rgus?\012"; + std::cout << "2M\n"; + std::cout << "2\tM\n"; + + return 0; +} diff --git a/2p9.cpp b/2p9.cpp new file mode 100644 index 0000000..e4c48ba --- /dev/null +++ b/2p9.cpp @@ -0,0 +1,15 @@ +#include +#include "sales_item.hpp" + +/* + * + * 2.9 + * + * + */ + +int main () { + + // Depends completely on what compiler options are enabled. I have tons of flags enabled to prevent myself from stupid mistakes. + return 0; +} diff --git a/Makefile b/Makefile index 40ebce8..e171277 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC1=clang++ CC2=g++ -CFLAGS_CLANG=-O0 -Wfatal-errors -Wall -Werror -Wextra -g3 -fsanitize=address -fsanitize=leak -Wpedantic -Wformat=2 -Wshadow -fno-common -std=c++11 -CFLAGS_GCC=-O0 -Wfatal-errors -Wall -Werror -Wextra -g3 -fsanitize=address -fsanitize=leak -Wpedantic -Wformat=2 -Wshadow -fno-common -std=c++11 -Wformat-truncation=2 -Wformat-overflow +CFLAGS_CLANG=-O0 -Wfatal-errors -Wall -Werror -Wextra -g3 -fsanitize=address -fsanitize=leak -Wpedantic -Wformat=2 -Wshadow -fno-common -std=c++2b +CFLAGS_GCC=-O0 -Wfatal-errors -Wall -Werror -Wextra -g3 -fsanitize=address -fsanitize=leak -Wpedantic -Wformat=2 -Wshadow -fno-common -std=c++2b -Wformat-truncation=2 -Wformat-overflow BINDIR=bin SRCS=$(wildcard *.cpp) OBJS_CLANG=$(patsubst %.cpp, $(BINDIR)/clang/%, $(SRCS)) -- cgit v1.2.3