Pure Programmer
Blue Matrix


Cluster Map

Selection

L1

This page is under construction. Please come back later.

Selection1.cpp
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	cout << "Start..." << endl;
	if (argc != 3) {
		cout << "You need at least two command line arguments!" << endl;
	}
	cout << "Finish..." << endl;
	return 0;
}

Output
$ g++ -std=c++17 Selection1.cpp -o Selection1 -lfmt $ ./Selection1 abc Start... You need at least two command line arguments! Finish... $ g++ -std=c++17 Selection1.cpp -o Selection1 -lfmt $ ./Selection1 abc 123 Start... Finish...
Selection2.cpp
#include "Utils.hpp"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	int const x = Utils::stoiWithDefault(string(argv[1]), 0);
	cout << "Start..." << endl;
	if (x > 10) {
		cout << "Greater than 10" << endl;
	} else {
		cout << "Less than or equal to 10" << endl;
	}
	cout << "Finish..." << endl;
	return 0;
}

Output
$ g++ -std=c++17 Selection2.cpp -o Selection2 -lfmt $ ./Selection2 8 Start... Less than or equal to 10 Finish... $ g++ -std=c++17 Selection2.cpp -o Selection2 -lfmt $ ./Selection2 12 Start... Greater than 10 Finish...
Selection3.cpp
#include "Utils.hpp"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	int const x = Utils::stoiWithDefault(string(argv[1]), 0);
	cout << "Start..." << endl;
	if (x > 1000) {
		cout << "Greater than 1000" << endl;
	} else if (x > 100) {
		cout << "Greater than 100 but less than or equal to 1000" << endl;
	} else {
		cout << "Less than or equal to 100" << endl;
	}
	cout << "Finish..." << endl;
	return 0;
}

Output
$ g++ -std=c++17 Selection3.cpp -o Selection3 -lfmt $ ./Selection3 12 Start... Less than or equal to 100 Finish... $ g++ -std=c++17 Selection3.cpp -o Selection3 -lfmt $ ./Selection3 120 Start... Greater than 100 but less than or equal to 1000 Finish... $ g++ -std=c++17 Selection3.cpp -o Selection3 -lfmt $ ./Selection3 1200 Start... Greater than 1000 Finish...
Selection4.cpp
#include "Utils.hpp"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	int const x = Utils::stoiWithDefault(string(argv[1]), 0);
	switch (x) {
		case 1:
			cout << "One" << endl;
			break;
		case 2:
			cout << "Two" << endl;
			break;
		case 3:
		case 4:
			cout << "Three or Four" << endl;
			break;
		default:
			cout << "Just don't know!" << endl;
			break;
	}
	return 0;
}

Output
$ g++ -std=c++17 Selection4.cpp -o Selection4 -lfmt $ ./Selection4 0 Just don't know! $ g++ -std=c++17 Selection4.cpp -o Selection4 -lfmt $ ./Selection4 1 One $ g++ -std=c++17 Selection4.cpp -o Selection4 -lfmt $ ./Selection4 2 Two $ g++ -std=c++17 Selection4.cpp -o Selection4 -lfmt $ ./Selection4 3 Three or Four $ g++ -std=c++17 Selection4.cpp -o Selection4 -lfmt $ ./Selection4 4 Three or Four
Selection5.cpp
#include "Utils.hpp"
#include <cctype>
#include <fmt/format.h>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
	char x = string(argv[1])[0];
	x = (char)tolower(x);
	switch (x) {
		case 'a':
		case 'e':
		case 'i':
		case 'o':
		case 'u':
			cout << fmt::format("{0:c} is a vowel", int(x)) << endl;
			break;
		case 'y':
			cout << "y is sometimes a vowel" << endl;
			break;
		default:
			cout << fmt::format("{0:c} is a consonant", int(x)) << endl;
			break;
	}
	return 0;
}

Output
$ g++ -std=c++17 Selection5.cpp -o Selection5 -lfmt $ ./Selection5 a a is a vowel $ g++ -std=c++17 Selection5.cpp -o Selection5 -lfmt $ ./Selection5 g g is a consonant $ g++ -std=c++17 Selection5.cpp -o Selection5 -lfmt $ ./Selection5 I i is a vowel $ g++ -std=c++17 Selection5.cpp -o Selection5 -lfmt $ ./Selection5 T t is a consonant $ g++ -std=c++17 Selection5.cpp -o Selection5 -lfmt $ ./Selection5 y y is sometimes a vowel
cpp

Questions

Projects

More ★'s indicate higher difficulty level.

References