summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-08-16 22:09:58 +0200
committerOskar <[email protected]>2024-08-16 22:09:58 +0200
commitaa9b47d8f1a8b3fac4d80276401e6d0884edb86a (patch)
tree19fc006b979a0202b5095291896fd5679c4a5036
parentbfa29c55fd58912845b5a6684489231a4d4e675e (diff)
more
-rw-r--r--4p10.cpp21
-rw-r--r--4p11.cpp25
-rw-r--r--4p12.cpp23
-rw-r--r--4p8.cpp17
-rw-r--r--4p9.cpp38
5 files changed, 124 insertions, 0 deletions
diff --git a/4p10.cpp b/4p10.cpp
new file mode 100644
index 0000000..5e18c6b
--- /dev/null
+++ b/4p10.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+
+/*
+ *
+ * 4.10
+ *
+ *
+ */
+
+int main () {
+
+ int val;
+ while(std::cin >> val && val != 42) {
+ }
+
+ if(val == 42) {
+ std::cout << "We found 42!" << std::endl;
+ }
+
+ return 0;
+}
diff --git a/4p11.cpp b/4p11.cpp
new file mode 100644
index 0000000..308ef2c
--- /dev/null
+++ b/4p11.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+
+/*
+ *
+ * 4.11
+ *
+ *
+ */
+
+int main () {
+
+ int a = 0;
+ int b = 0;
+ int c = 0;
+ int d = 0;
+ if(std::cin >> a >> b >> c >> d) {} else { return -1; }
+
+ if(a > b && b > c && c > d) {
+ std::cout << "True!" << std::endl;
+ } else {
+ std::cout << "False!" << std::endl;
+ }
+
+ return 0;
+}
diff --git a/4p12.cpp b/4p12.cpp
new file mode 100644
index 0000000..74442e4
--- /dev/null
+++ b/4p12.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+
+/*
+ *
+ * 4.12
+ *
+ *
+ */
+
+int main () {
+
+ int i = 1;
+ int j = 9;
+ int k = 10;
+
+ if(i != (j < k)) { // j < k is evaluated first
+ // because j < k now it will return true
+ // When 'i' is NOT true(aka NOT 0) then print below
+ std::cout << "..." << std::endl;
+ }
+
+ return 0;
+}
diff --git a/4p8.cpp b/4p8.cpp
new file mode 100644
index 0000000..46c402a
--- /dev/null
+++ b/4p8.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+
+/*
+ *
+ * 4.8
+ *
+ *
+ */
+
+int main () {
+
+ // AND, OR
+ // AND's right operand is only evaluated if the left operand is True
+ // OR's right operand is only evaluated if the left operand is False
+ // Equality evaluates left and right and then checks if they are equal
+ return 0;
+}
diff --git a/4p9.cpp b/4p9.cpp
new file mode 100644
index 0000000..101f1c9
--- /dev/null
+++ b/4p9.cpp
@@ -0,0 +1,38 @@
+#include <iostream>
+
+/*
+ *
+ * 4.9
+ *
+ *
+ */
+
+int main () {
+ // True if:
+ // the address pointed to isnt null
+ // the first character isnt a null character
+
+ // We can test this by making a string literal, for exmple "Hello world"
+ // We can also test by putting the null character \0 in the string literal
+ // And we can also test by pointing cp at nullptr
+ int choice;
+ const char *hw = "Hello world!";
+ const char *np = nullptr;
+ const char nc = '\0';
+ const char *cp;
+ std::cout << "1: Hello World | 2: nullptr | 3: null character" << std::endl;
+ if(std::cin >> choice) {} else { return -1; }
+
+ if(choice == 1) { cp = hw; }
+ else if(choice == 2) { cp = np; }
+ else if(choice == 3) { cp = &nc; }
+ else { return -1; }
+
+ if (cp && *cp) {
+ std::cout << "valid" << std::endl;
+ } else {
+ std::cout << "not valid" << std::endl;
+ }
+
+ return 0;
+}