Skip to content

Commit 41e9842

Browse files
committed
Generated on 2021-02-25
1 parent 18263dc commit 41e9842

File tree

179 files changed

+4347
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+4347
-0
lines changed

headers/01-hellow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// 01-hellow.cpp : prints a line of text to the console
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int main() {
7+
cout << "Hello, World!" << '\n';
8+
}

headers/01-title.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// 01-title.cpp : output the title page of a well-known book
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int main() {
7+
cout << 1+R"(
8+
Alice's
9+
Adventures In
10+
Wonderland
11+
12+
by
13+
LEWIS CARROLL
14+
)";
15+
}

headers/02-assign.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// 02-assign.cpp : assign to local variables
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int main() {
7+
int i = 1, j = 2;
8+
unsigned k;
9+
cout << "(1) i = " << i << ", j = " << j << ", k = " << k << '\n';
10+
i = j;
11+
j = 3;
12+
k = -1;
13+
cout << "(2) i = " << i << ", j = " << j << ", k = " << k << '\n';
14+
}

headers/02-constants.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// 02-constants.cpp : introducing the const keyword
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
const double PI = 3.14159265358979;
7+
8+
int main() {
9+
auto const APPROX_E = 3;
10+
cout << "pi is almost exactly " << PI
11+
<< "e is approximately " << APPROX_E
12+
<< '\n';
13+
}

headers/02-constexpr.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// 02-constexpr.cpp : introducing the constexpr keyword
2+
3+
#include <iostream>
4+
#include <cmath>
5+
using namespace std;
6+
7+
const double PI1 = acos(-1.0); // acos is not (yet) constexpr
8+
constexpr double PI2 = 22.0 / 7.0;
9+
10+
// the following line does not compile and has been commented out
11+
//static_assert(PI1 > 3.141 && PI1 < 3.143);
12+
static_assert(PI2 > 3.141 && PI2 < 3.143);
13+
14+
int main() {
15+
cout << "PI1 = " << PI1 << '\n';
16+
cout << "PI2 = " << PI2 << '\n';
17+
}

headers/02-height.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// 02-height.cpp : define the same variable name in two different namespaces
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
namespace Wonderland {
7+
auto alice_height_m{ 0.15 };
8+
}
9+
10+
namespace VictorianEngland {
11+
auto alice_height_m{ 0.9 };
12+
}
13+
14+
int main() {
15+
cout << "Alice\'s height varies between "
16+
<< Wonderland::alice_height_m
17+
<< "m and "
18+
<< VictorianEngland::alice_height_m
19+
<< "m.\n";
20+
}

headers/02-references.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// 02-references.cpp : introducing l-value references
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int alice_age{ 9 };
7+
8+
int main() {
9+
cout << "Alice\'s age is " << alice_age << '\n';
10+
int& alice_age_ref = alice_age;
11+
alice_age_ref = 10;
12+
cout << "Alice\'s age is now " << alice_age << '\n';
13+
}

headers/02-scopes.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// 02-scopes.cpp : define three variables with the same name in one program
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
auto a{ 1.5f };
7+
8+
int main() {
9+
cout << "(1) " << a << '\n';
10+
auto a{ 2u };
11+
cout << "(2) " << a << '\n';
12+
{
13+
auto a{ 2.5 };
14+
cout << "(3) " << a << '\n';
15+
}
16+
}

headers/02-swap.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// 02-swap.cpp : attempt to swap the values of an int and a double
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int main() {
7+
int a = 1;
8+
double b = 2.5;
9+
cout << "(1) a = " << a << ", b = " << b << '\n';
10+
a = 2.5;
11+
b = 1;
12+
cout << "(2) a = " << a << ", b = " << b << '\n';
13+
}

headers/02-uniform.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 02-uniform.cpp : avoid compiler error with uniform initialization and explicit narrowing cast
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int main() {
7+
// int c = { 2.5 }; // Error: this does NOT compile
8+
int c = { static_cast<int>(2.5) }; // while this does
9+
double d = { 1 }; // and so does this
10+
cout << "c = " << c << ", d = " << d << '\n';
11+
}

0 commit comments

Comments
 (0)