Pure Programmer
Blue Matrix


Cluster Map

Iteration

L1

This page is under construction. Please come back later.

Iteration1.cpp
#include "Utils.hpp"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	int max = 5;
	if (argc == 2) {
		max = Utils::stoiWithDefault(string(argv[1]), 5);
	}
	for (int i = 0; i < max; ++i) {
		cout << "Hello, world!" << endl;
	}
	return 0;
}

Output
$ g++ -std=c++17 Iteration1.cpp -o Iteration1 -lfmt $ ./Iteration1 5 Hello, world! Hello, world! Hello, world! Hello, world! Hello, world!
Iteration2.cpp
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	for (int i = 10; i >= 1; --i) {
		cout << i << endl;
	}
	cout << "Blastoff!" << endl;
	return 0;
}

Output
$ g++ -std=c++17 Iteration2.cpp -o Iteration2 -lfmt $ ./Iteration2 10 9 8 7 6 5 4 3 2 1 Blastoff!
Iteration3.cpp
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	cout << "Even numbers up to 100..." << endl;
	for (int i = 2; i <= 100; i += 2) {
		cout << i << endl;
	}
	return 0;
}

Output
$ g++ -std=c++17 Iteration3.cpp -o Iteration3 -lfmt $ ./Iteration3 Even numbers up to 100... 2 4 6 8 10 12 14 16 18 ... 82 84 86 88 90 92 94 96 98 100
Iteration4.cpp
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	cout << "Floating point numbers" << endl;
	for (double d = 1.0; d < 2.01; d += 0.1) {
		cout << d << endl;
	}
	return 0;
}

Output
$ g++ -std=c++17 Iteration4.cpp -o Iteration4 -lfmt $ ./Iteration4 Floating point numbers 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
Iteration5.cpp
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	cout << "Powers of 2 up to 256!" << endl;
	for (int i = 1; i <= 256; i *= 2) {
		cout << i << endl;
	}
	return 0;
}

Output
$ g++ -std=c++17 Iteration5.cpp -o Iteration5 -lfmt $ ./Iteration5 Powers of 2 up to 256! 1 2 4 8 16 32 64 128 256
Iteration6.cpp
#include <clocale>
#include <codecvt>
#include <iostream>
#include <string>

std::locale utf8loc(std::locale(), new std::codecvt_utf8<wchar_t>);
using namespace std;

int main(int argc, char **argv) {
	setlocale(LC_ALL, "en_US.UTF-8");
	wcout.imbue(utf8loc);
	wcin.imbue(utf8loc);

	wstring s = L"Hello, world! 🥰🇺🇸";
	for (auto c : s) {
		wcout << c << endl;
	}
	return 0;
}

Output
$ g++ -std=c++17 Iteration6.cpp -o Iteration6 -lfmt $ ./Iteration6 H e l l o , w o r l d ! 🥰 🇺 🇸

Iterators

cpp

Questions

Projects

More ★'s indicate higher difficulty level.

References