From 1ae6715e5a33c818fabc0268409610f5c4b59250 Mon Sep 17 00:00:00 2001 From: ganome Date: Sun, 25 Aug 2024 15:42:07 -0600 Subject: [PATCH] Week 1 Day 3 --- .gitignore | 10 +++++++ .vscode/settings.json | 3 +- cpp/ANSI/W1/Day3/3.1/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.1/main.cpp | 19 +++++++++++++ cpp/ANSI/W1/Day3/3.2/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.2/main.cpp | 19 +++++++++++++ cpp/ANSI/W1/Day3/3.3/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.3/main.cpp | 21 ++++++++++++++ cpp/ANSI/W1/Day3/3.4/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.4/main.cpp | 16 +++++++++++ cpp/ANSI/W1/Day3/3.5/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.5/main.cpp | 17 ++++++++++++ cpp/ANSI/W1/Day3/3.6/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.6/main.cpp | 9 ++++++ cpp/ANSI/W1/Day3/3.7/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.7/main.cpp | 9 ++++++ cpp/ANSI/W1/Day3/3.8/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.8/main.cpp | 19 +++++++++++++ cpp/ANSI/W1/Day3/3.9/Makefile | 13 +++++++++ cpp/ANSI/W1/Day3/3.9/main.cpp | 25 +++++++++++++++++ cpp/ANSI/W1/Day3/Ex.SpecialChars/main.cpp | 22 +++++++++++++++ cpp/ANSI/W1/Day3/Quiz/quiz.txt | 34 +++++++++++++++++++++++ cpp/vulkan/HelloTriangle/main.cpp | 4 +-- 23 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 cpp/ANSI/W1/Day3/3.1/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.1/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.2/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.2/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.3/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.3/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.4/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.4/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.5/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.5/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.6/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.6/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.7/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.7/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.8/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.8/main.cpp create mode 100644 cpp/ANSI/W1/Day3/3.9/Makefile create mode 100644 cpp/ANSI/W1/Day3/3.9/main.cpp create mode 100644 cpp/ANSI/W1/Day3/Ex.SpecialChars/main.cpp create mode 100644 cpp/ANSI/W1/Day3/Quiz/quiz.txt diff --git a/.gitignore b/.gitignore index 31e7a7e..a311db0 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,13 @@ cpp/ANSI/W1/Day2/2.5/comments cpp/ANSI/W1/Day2/2.6/functions cpp/ANSI/W1/Day2/2.7/function-math cpp/ANSI/W1/Day2/Ex.5/function-math +cpp/ANSI/W1/Day3/3.1/sizeofvars +cpp/ANSI/W1/Day3/3.2/variableusage +cpp/ANSI/W1/Day3/3.4/overflow +cpp/ANSI/W1/Day3/3.3/typedef +cpp/ANSI/W1/Day3/3.5/overflowint +cpp/ANSI/W1/Day3/3.6/printchars +cpp/ANSI/W1/Day3/3.7/printchars2 +cpp/ANSI/W1/Day3/3.8/enumeratedconstants +cpp/ANSI/W1/Day3/3.9/enumeratedconstants2 +cpp/ANSI/W1/Day3/Ex.SpecialChars/specialchars diff --git a/.vscode/settings.json b/.vscode/settings.json index f50e6dd..8b983b4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,6 +14,7 @@ "format": "cpp", "initializer_list": "cpp", "span": "cpp", - "ostream": "cpp" + "ostream": "cpp", + "iostream": "cpp" } } \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.1/Makefile b/cpp/ANSI/W1/Day3/3.1/Makefile new file mode 100644 index 0000000..473c35a --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.1/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o sizeofvars main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: sizeofvars + ./sizeofvars + +clean: + rm -f sizeofvars diff --git a/cpp/ANSI/W1/Day3/3.1/main.cpp b/cpp/ANSI/W1/Day3/3.1/main.cpp new file mode 100644 index 0000000..ae5cc90 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.1/main.cpp @@ -0,0 +1,19 @@ +// Show the size of variable types on localhost +#include + +int main() +{ + using std::cout; + + cout << "The size of an int is:\t\t" << sizeof(int) << " bytes.\n"; + cout << "The size of a short int is:\t" << sizeof(short) << " bytes.\n"; + cout << "The size of a long int is:\t" << sizeof(long) << " bytes.\n"; + cout << "The size of a char is:\t\t" << sizeof(char) << " bytes.\n"; + cout << "The size of a float is:\t\t" << sizeof(float) << " bytes.\n"; + cout << "The size of a _Float16 is:\t" << sizeof(_Float16) << " bytes.\n"; + cout << "The size of a __float128 is:\t" << sizeof(__float128) << " bytes.\n"; + cout << "The size of a double is:\t" << sizeof(double) << " bytes.\n"; + cout << "The size of a bool is:\t\t" << sizeof(bool) << " bytes.\n"; + + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.2/Makefile b/cpp/ANSI/W1/Day3/3.2/Makefile new file mode 100644 index 0000000..f50aab8 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.2/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o variableusage main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: variableusage + ./variableusage + +clean: + rm -f variableusage diff --git a/cpp/ANSI/W1/Day3/3.2/main.cpp b/cpp/ANSI/W1/Day3/3.2/main.cpp new file mode 100644 index 0000000..45f1363 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.2/main.cpp @@ -0,0 +1,19 @@ +// Demonstration on how to use variables +#include + +int main() +{ + using namespace std; + unsigned short int Width = 5, Length; + Length = 10; + + // create an unsigned short and initialize with results + // of multiplying length by width + unsigned short int Area = (Width * Length); + + cout << "Width:\t" << Width << endl; + cout << "Length:\t" << Length << endl; + cout << "Area:\t" << Area << endl; + + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.3/Makefile b/cpp/ANSI/W1/Day3/3.3/Makefile new file mode 100644 index 0000000..a512df6 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.3/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o typedef main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: typedef + ./typedef + +clean: + rm -f typedef diff --git a/cpp/ANSI/W1/Day3/3.3/main.cpp b/cpp/ANSI/W1/Day3/3.3/main.cpp new file mode 100644 index 0000000..78514cd --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.3/main.cpp @@ -0,0 +1,21 @@ +// Demonstration on what a typedef is how to declare one. +#include + +typedef unsigned short int USHORT; + +int main() +{ + using namespace std; + USHORT Width = 5, Length; + Length = 10; + + // create an unsigned short and initialize with results + // of multiplying length by width + unsigned short int Area = (Width * Length); + + cout << "Width:\t" << Width << endl; + cout << "Length:\t" << Length << endl; + cout << "Area:\t" << Area << endl; + + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.4/Makefile b/cpp/ANSI/W1/Day3/3.4/Makefile new file mode 100644 index 0000000..cba8e79 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.4/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o overflow main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: overflow + ./overflow + +clean: + rm -f overflow diff --git a/cpp/ANSI/W1/Day3/3.4/main.cpp b/cpp/ANSI/W1/Day3/3.4/main.cpp new file mode 100644 index 0000000..59c30d7 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.4/main.cpp @@ -0,0 +1,16 @@ +// Demonstrating buffer overflow with unsigned short int +#include + +int main() +{ + using namespace std; + + unsigned short int smallNumber = 65535; + cout << "small number:\t" << smallNumber << endl; + smallNumber++; + cout << "small number:\t" << smallNumber << endl; + smallNumber++; + cout << "small number:\t" << smallNumber << endl; + + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.5/Makefile b/cpp/ANSI/W1/Day3/3.5/Makefile new file mode 100644 index 0000000..5ade328 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.5/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o overflowint main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: overflowint + ./overflowint + +clean: + rm -f overflowint diff --git a/cpp/ANSI/W1/Day3/3.5/main.cpp b/cpp/ANSI/W1/Day3/3.5/main.cpp new file mode 100644 index 0000000..19d110c --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.5/main.cpp @@ -0,0 +1,17 @@ +// Demonstrating another overflow for a signed short int +#include + +int main() +{ + using namespace std; + + short int smallNumber = 32767; + + cout << "small number:\t" << smallNumber << endl; + smallNumber++; + cout << "small number:\t" << smallNumber << endl; + smallNumber++; + cout << "small number:\t" << smallNumber << endl; + + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.6/Makefile b/cpp/ANSI/W1/Day3/3.6/Makefile new file mode 100644 index 0000000..f17299d --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.6/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o printchars main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: printchars + ./printchars + +clean: + rm -f printchars diff --git a/cpp/ANSI/W1/Day3/3.6/main.cpp b/cpp/ANSI/W1/Day3/3.6/main.cpp new file mode 100644 index 0000000..f5d20b3 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.6/main.cpp @@ -0,0 +1,9 @@ +// Demonstrate printing characters based on numbers +#include + +int main() +{ + for (int i = 0; i<128; i++) + std::cout << "i is equal to:\t" << i << "---: " << (char) i << std::endl; + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.7/Makefile b/cpp/ANSI/W1/Day3/3.7/Makefile new file mode 100644 index 0000000..d14f298 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.7/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o printchars2 main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: printchars2 + ./printchars2 + +clean: + rm -f printchars2 diff --git a/cpp/ANSI/W1/Day3/3.7/main.cpp b/cpp/ANSI/W1/Day3/3.7/main.cpp new file mode 100644 index 0000000..8e7be57 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.7/main.cpp @@ -0,0 +1,9 @@ +// Demonstrate printing characters with numbers take 2 +#include + +int main() +{ + for (unsigned char i = 0; i<128; i++) + std::cout << "i is equal to:\t" << i << std::endl; + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.8/Makefile b/cpp/ANSI/W1/Day3/3.8/Makefile new file mode 100644 index 0000000..a41ee52 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.8/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o enumeratedconstants main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: enumeratedconstants + ./enumeratedconstants + +clean: + rm -f enumeratedconstants diff --git a/cpp/ANSI/W1/Day3/3.8/main.cpp b/cpp/ANSI/W1/Day3/3.8/main.cpp new file mode 100644 index 0000000..d540444 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.8/main.cpp @@ -0,0 +1,19 @@ +// Demonstrate enumerated constants +#include + +using namespace std; + +int main() +{ + enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; + + Days today; + today = Sunday; + + if (today == Sunday || today == Saturday) + cout << "\nGotta love the weekends!\n"; + else + cout << "\nBack to work.\n"; + + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/3.9/Makefile b/cpp/ANSI/W1/Day3/3.9/Makefile new file mode 100644 index 0000000..e5f0095 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.9/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o enumeratedconstants2 main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: enumeratedconstants2 + ./enumeratedconstants2 + +clean: + rm -f enumeratedconstants2 diff --git a/cpp/ANSI/W1/Day3/3.9/main.cpp b/cpp/ANSI/W1/Day3/3.9/main.cpp new file mode 100644 index 0000000..4f18347 --- /dev/null +++ b/cpp/ANSI/W1/Day3/3.9/main.cpp @@ -0,0 +1,25 @@ +// Same as before but with a const int list +#include + +int main() +{ + +const int Sunday = 0; +const int Monday = 1; +const int Tuesday = 2; +const int Wednesday = 3; +const int Thursday = 4; +const int Friday = 5; +const int Saturday = 6; + +int today; +today = Monday; + +if (today == Sunday || today == Saturday) +std::cout << "\nGotta’ love the weekends!\n"; + +else +std::cout << "\nBack to work.\n"; + +return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/Ex.SpecialChars/main.cpp b/cpp/ANSI/W1/Day3/Ex.SpecialChars/main.cpp new file mode 100644 index 0000000..b4b4b2d --- /dev/null +++ b/cpp/ANSI/W1/Day3/Ex.SpecialChars/main.cpp @@ -0,0 +1,22 @@ +// List of special chars that can be used in chat with cout +#include + +using namespace std; + +int main() +{ + cout << "the \\a character is an ALERT (bell)" << endl; + cout << "The \\b character is a backspace..\b" << endl; + cout << "the \\f operater is for form feed \fTest after the flag" << endl; + cout << "the \\n operator is a newline character.\n"; + cout << "\rthe \\r operator is a Carraige return.\n\r"; + cout << "the \\t operator is a \tTab" << endl; + cout << "the \\v operator is a vertial \vtab\n"; + cout << "the \\' operator is a single quote character \'Quotation\'\n"; + cout << "the \\\" operator is for double \"quotes\"\n"; + cout << "the \? operator is for Question Mark\n"; + cout << "the \\ operator is for Backslash\n"; + cout << "the \\000 operator is for Octal Notation \101\101\n"; + cout << "the \\xhhh is for Hexadecimal Notation \xFF\xAA\n"; + return 0; +} \ No newline at end of file diff --git a/cpp/ANSI/W1/Day3/Quiz/quiz.txt b/cpp/ANSI/W1/Day3/Quiz/quiz.txt new file mode 100644 index 0000000..b6b525f --- /dev/null +++ b/cpp/ANSI/W1/Day3/Quiz/quiz.txt @@ -0,0 +1,34 @@ +1. What is the difference between an integer variable and a floating-point variable? + +2. What are the differences between an unsigned short int and a long int? + +3. What are the advantages of using a symbolic constant rather than a literal constant? + +4. What are the advantages of using the const keyword rather than #define? + +5. What makes for a good or bad variable name? + +6. Given this enum, what is the value of BLUE? +enum COLOR { WHITE, BLACK = 100, RED, BLUE, GREEN = 300 }; + +7. Which of the following variable names are good, which are bad, and which are +invalid? +a. Age +b. !ex +c. R79J +d. TotalIncome +e. __Invalid + +-------------------------------------------------------------------------------- +1. What would be the correct variable type in which to store the following +information? +a. Your age +b. The area of your backyard +c. The number of stars in the galaxy +d. The average rainfall for the month of January + +2. Create good variable names for this information. + +3. Declare a constant for pi as 3.14159. + +4. Declare a float variable and initialize it using your pi constant. \ No newline at end of file diff --git a/cpp/vulkan/HelloTriangle/main.cpp b/cpp/vulkan/HelloTriangle/main.cpp index d13be09..eaa00e7 100644 --- a/cpp/vulkan/HelloTriangle/main.cpp +++ b/cpp/vulkan/HelloTriangle/main.cpp @@ -10,8 +10,8 @@ class HelloTriangleApplication { public: void run() { + initVulkan(); initWindow(); - initVulkan(); mainLoop(); cleanup(); } @@ -48,6 +48,6 @@ int main() { return EXIT_FAILURE; } -// std::cout << "Success!!!"; + std::cout << "Success!!!\n"; return EXIT_SUCCESS; } \ No newline at end of file