Week 1 Day 3
This commit is contained in:
parent
6846701f11
commit
1ae6715e5a
10
.gitignore
vendored
10
.gitignore
vendored
@ -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
|
||||
|
||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -14,6 +14,7 @@
|
||||
"format": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"span": "cpp",
|
||||
"ostream": "cpp"
|
||||
"ostream": "cpp",
|
||||
"iostream": "cpp"
|
||||
}
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.1/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.1/Makefile
Normal file
@ -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
|
||||
19
cpp/ANSI/W1/Day3/3.1/main.cpp
Normal file
19
cpp/ANSI/W1/Day3/3.1/main.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Show the size of variable types on localhost
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.2/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.2/Makefile
Normal file
@ -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
|
||||
19
cpp/ANSI/W1/Day3/3.2/main.cpp
Normal file
19
cpp/ANSI/W1/Day3/3.2/main.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Demonstration on how to use variables
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.3/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.3/Makefile
Normal file
@ -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
|
||||
21
cpp/ANSI/W1/Day3/3.3/main.cpp
Normal file
21
cpp/ANSI/W1/Day3/3.3/main.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Demonstration on what a typedef is how to declare one.
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.4/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.4/Makefile
Normal file
@ -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
|
||||
16
cpp/ANSI/W1/Day3/3.4/main.cpp
Normal file
16
cpp/ANSI/W1/Day3/3.4/main.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Demonstrating buffer overflow with unsigned short int
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.5/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.5/Makefile
Normal file
@ -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
|
||||
17
cpp/ANSI/W1/Day3/3.5/main.cpp
Normal file
17
cpp/ANSI/W1/Day3/3.5/main.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Demonstrating another overflow for a signed short int
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.6/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.6/Makefile
Normal file
@ -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
|
||||
9
cpp/ANSI/W1/Day3/3.6/main.cpp
Normal file
9
cpp/ANSI/W1/Day3/3.6/main.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// Demonstrate printing characters based on numbers
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i<128; i++)
|
||||
std::cout << "i is equal to:\t" << i << "---: " << (char) i << std::endl;
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.7/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.7/Makefile
Normal file
@ -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
|
||||
9
cpp/ANSI/W1/Day3/3.7/main.cpp
Normal file
9
cpp/ANSI/W1/Day3/3.7/main.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// Demonstrate printing characters with numbers take 2
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
for (unsigned char i = 0; i<128; i++)
|
||||
std::cout << "i is equal to:\t" << i << std::endl;
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.8/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.8/Makefile
Normal file
@ -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
|
||||
19
cpp/ANSI/W1/Day3/3.8/main.cpp
Normal file
19
cpp/ANSI/W1/Day3/3.8/main.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Demonstrate enumerated constants
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day3/3.9/Makefile
Normal file
13
cpp/ANSI/W1/Day3/3.9/Makefile
Normal file
@ -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
|
||||
25
cpp/ANSI/W1/Day3/3.9/main.cpp
Normal file
25
cpp/ANSI/W1/Day3/3.9/main.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Same as before but with a const int list
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
22
cpp/ANSI/W1/Day3/Ex.SpecialChars/main.cpp
Normal file
22
cpp/ANSI/W1/Day3/Ex.SpecialChars/main.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// List of special chars that can be used in chat with cout
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
34
cpp/ANSI/W1/Day3/Quiz/quiz.txt
Normal file
34
cpp/ANSI/W1/Day3/Quiz/quiz.txt
Normal file
@ -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.
|
||||
@ -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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user