Week1 Day 1&2 ANSI C++
This commit is contained in:
parent
455c25abb8
commit
8ef4e679ce
8
.gitignore
vendored
8
.gitignore
vendored
@ -25,3 +25,11 @@ cpp/vscode/helloworld
|
||||
cpp/vulkan/vulkantest/VulkanTest
|
||||
cpp/ANSI/W1/Day1/1.1/helloworld
|
||||
cpp/vulkan/HelloTriangle/HelloTriangle
|
||||
cpp/ANSI/W1/Day2/2.1/helloworld
|
||||
cpp/ANSI/W1/Day2/2.2/cout
|
||||
cpp/ANSI/W1/Day1/Ex.1/math
|
||||
cpp/ANSI/W1/Day2/2.3/keyword
|
||||
cpp/ANSI/W1/Day2/2.4/namespace-std
|
||||
cpp/ANSI/W1/Day2/2.5/comments
|
||||
cpp/ANSI/W1/Day2/2.6/functions
|
||||
cpp/ANSI/W1/Day2/2.7/function-math
|
||||
|
||||
19
.vscode/settings.json
vendored
Normal file
19
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"hash_map": "cpp",
|
||||
"chrono": "cpp",
|
||||
"deque": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"list": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"string_view": "cpp",
|
||||
"format": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"span": "cpp",
|
||||
"ostream": "cpp"
|
||||
}
|
||||
}
|
||||
13
cpp/ANSI/W1/Day1/Ex.1/Makefile
Normal file
13
cpp/ANSI/W1/Day1/Ex.1/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
CFLAGS = -std=c++11 -O2
|
||||
LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
|
||||
|
||||
1.1: main.cpp
|
||||
c++ $(CFLAGS) -o math main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: math
|
||||
./math
|
||||
|
||||
clean:
|
||||
rm -f math
|
||||
11
cpp/ANSI/W1/Day1/Ex.1/main.cpp
Normal file
11
cpp/ANSI/W1/Day1/Ex.1/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 5;
|
||||
int y = 7;
|
||||
std::cout << std::endl;
|
||||
std::cout << x + y << " " << x * y << std::endl; // Added the std::endl on this line because the line below no longer exists in the standard
|
||||
// std::cout << std::end; //This no longer exists in the current C++ standard
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day2/2.1/Makefile
Normal file
13
cpp/ANSI/W1/Day2/2.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 helloworld main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: helloworld
|
||||
./helloworld
|
||||
|
||||
clean:
|
||||
rm -f helloworld
|
||||
7
cpp/ANSI/W1/Day2/2.1/main.cpp
Normal file
7
cpp/ANSI/W1/Day2/2.1/main.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello World!\n";
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day2/2.2/Makefile
Normal file
13
cpp/ANSI/W1/Day2/2.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 cout main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: cout
|
||||
./cout
|
||||
|
||||
clean:
|
||||
rm -f cout
|
||||
22
cpp/ANSI/W1/Day2/2.2/main.cpp
Normal file
22
cpp/ANSI/W1/Day2/2.2/main.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Listing 2.2 using std::cout
|
||||
#include <iostream>
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello there.\n";
|
||||
std::cout << "Here is 5: " << 5 << "\n";
|
||||
std::cout << "The manipulator std::endl ";
|
||||
std::cout << "writes a new line to the scren.";
|
||||
std::cout << std::endl;
|
||||
std::cout << "Here is a very big number:\t" << 70000;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Here is the sum of 8 and 5:\t";
|
||||
std::cout << 8+5 << std::endl;
|
||||
std::cout << "Here's a fraction:\t\t";
|
||||
std::cout << (float) 5/8 << std::endl;
|
||||
std::cout << "And a very very vig number:\t";
|
||||
std::cout << (double) 7000 * 7000 << std::endl;
|
||||
std::cout << "Don't forget to replace Jesse Liberty ";
|
||||
std::cout << "with your name...\n";
|
||||
std::cout << "Ganome is a C++ programmer!\n";
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day2/2.3/Makefile
Normal file
13
cpp/ANSI/W1/Day2/2.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 keyword main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: keyword
|
||||
./keyword
|
||||
|
||||
clean:
|
||||
rm -f keyword
|
||||
25
cpp/ANSI/W1/Day2/2.3/main.cpp
Normal file
25
cpp/ANSI/W1/Day2/2.3/main.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Listing 2.3 - using the keyword
|
||||
#include <iostream>
|
||||
int main()
|
||||
{
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
cout << "Hello there.\n";
|
||||
cout << "Here is 5:\t" << 5 << "\n";
|
||||
cout << "The manipulator endl ";
|
||||
cout << "writes a new line to the screen.";
|
||||
cout << endl;
|
||||
cout << "Here is a very big number:\t" << 70000000;
|
||||
cout << endl;
|
||||
cout << "Here is the sum of 8 and 5:\t";
|
||||
cout << 8+5 << endl;
|
||||
cout << "Here's a fraction:\t\t";
|
||||
cout << 5/8 << endl;
|
||||
cout << "And a very big number:\t\t";
|
||||
cout << 7000 * 6000 << endl;
|
||||
cout << "Dont forget to replace Jesse Liberty ";
|
||||
cout << "with your name...\n";
|
||||
cout << "Ganome is a C++ programmer!\n";
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day2/2.4/Makefile
Normal file
13
cpp/ANSI/W1/Day2/2.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 namespace-std main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: namespace-std
|
||||
./namespace-std
|
||||
|
||||
clean:
|
||||
rm -f namespace-std
|
||||
24
cpp/ANSI/W1/Day2/2.4/main.cpp
Normal file
24
cpp/ANSI/W1/Day2/2.4/main.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Listing 2.4 - using the namespace std
|
||||
#include <iostream>
|
||||
int main()
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
cout << "Hello there.\n";
|
||||
cout << "Here is 5:\t" << 5 << "\n";
|
||||
cout << "The manipulator endl ";
|
||||
cout << "writes a new line to the screen.";
|
||||
cout << endl;
|
||||
cout << "Here is a very big number:\t" << 70000000;
|
||||
cout << endl;
|
||||
cout << "Here is the sum of 8 and 5:\t";
|
||||
cout << 8+5 << endl;
|
||||
cout << "Here's a fraction:\t\t";
|
||||
cout << 5/8 << endl;
|
||||
cout << "And a very big number:\t\t";
|
||||
cout << 7000 * 6000 << endl;
|
||||
cout << "Dont forget to replace Jesse Liberty ";
|
||||
cout << "with your name...\n";
|
||||
cout << "Ganome is a C++ programmer!\n";
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day2/2.5/Makefile
Normal file
13
cpp/ANSI/W1/Day2/2.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 comments main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: comments
|
||||
./comments
|
||||
|
||||
clean:
|
||||
rm -f comments
|
||||
17
cpp/ANSI/W1/Day2/2.5/main.cpp
Normal file
17
cpp/ANSI/W1/Day2/2.5/main.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
using std::cout;
|
||||
|
||||
/* This is a comment
|
||||
and it extends until the closing
|
||||
star-slash comment mark */
|
||||
cout << "Hello World!\n";
|
||||
//This comment ends at the end of this line!
|
||||
cout << "That comment ended\n";
|
||||
|
||||
// double-slash comments cal also be alone on a line
|
||||
/* as can slas-star comments */
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day2/2.6/Makefile
Normal file
13
cpp/ANSI/W1/Day2/2.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 functions main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: functions
|
||||
./functions
|
||||
|
||||
clean:
|
||||
rm -f functions
|
||||
20
cpp/ANSI/W1/Day2/2.6/main.cpp
Normal file
20
cpp/ANSI/W1/Day2/2.6/main.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
// Demonstrating a call to a function
|
||||
#include <iostream>
|
||||
|
||||
/* function Demonstration Function
|
||||
prints out a useful message */
|
||||
void DemonstrationFunction()
|
||||
{
|
||||
std::cout << "In Demo Function\n";
|
||||
}
|
||||
|
||||
/* function main - prints out a message, then
|
||||
calls DemonstrationFunction(), then prints out
|
||||
a second message*/
|
||||
int main()
|
||||
{
|
||||
std::cout << "In main\n";
|
||||
DemonstrationFunction();
|
||||
std::cout << "Back in Main\n";
|
||||
return 0;
|
||||
}
|
||||
13
cpp/ANSI/W1/Day2/2.7/Makefile
Normal file
13
cpp/ANSI/W1/Day2/2.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 function-math main.cpp $(LDFLAGS)
|
||||
|
||||
.PHONY: test clean
|
||||
|
||||
test: function-math
|
||||
./function-math
|
||||
|
||||
clean:
|
||||
rm -f function-math
|
||||
24
cpp/ANSI/W1/Day2/2.7/main.cpp
Normal file
24
cpp/ANSI/W1/Day2/2.7/main.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Demonstrate some math using a function
|
||||
#include <iostream>
|
||||
int Add( int first, int second)
|
||||
{
|
||||
std::cout << "In Add() function, recived " << first << " and " << second << "\n";
|
||||
return(first + second);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
cout << "I'm in the main() function!\n";
|
||||
int a, b, c; // Declare some variables adding
|
||||
cout << "Enter two numbers: ";
|
||||
cin >> a;
|
||||
cin >> b;
|
||||
cout << "\nCalling Add() Function from main()\n";
|
||||
c=Add(a,b);
|
||||
cout << "\nBack in Main()\n";
|
||||
cout << "c was set to:\t" << c;
|
||||
cout << "\nExiting...\n\n";
|
||||
return 0;
|
||||
}
|
||||
9
cpp/ANSI/W1/Day2/Quiz/quiz.txt
Normal file
9
cpp/ANSI/W1/Day2/Quiz/quiz.txt
Normal file
@ -0,0 +1,9 @@
|
||||
1. What is the difference between the compiler and the preprocessor?
|
||||
|
||||
2. Why is the function main() special?
|
||||
|
||||
3. What are the two types of comments, and how do they differ?
|
||||
|
||||
4. Can comments be nested?
|
||||
|
||||
5. Can comments be longer than one line?
|
||||
Loading…
x
Reference in New Issue
Block a user