dictionary alternative

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 8
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 8

#include "std_lib_facilities.h"

void replace_apostrophes(string& _w, vector<string>& _s_words) {
	if (_w == "can't") {
		_w = "cannot";
	}
	if (_w == "won't") {
		_w = "will";
		_s_words.push_back("not");
	}
	if (_w[_w.size() - 1] == 't' &&
		_w[_w.size() - 2] == '\'' &&
		_w[_w.size() - 3] == 'n') {
		string temp = "";
		for (int i = 0; i < _w.size() - 3; i++) {
			temp += _w[i];
		}
		_w = temp;
		_s_words.push_back("not");
	}
}

void process(ifstream& _ist, ofstream& _ost) {
	while (true) {
		//get chars
		char letter;
		vector<char> c_sentence;
		vector<string> s_words;
		if (_ist.eof()) {
			break;
		}
		while (_ist.get(letter)) {
			c_sentence.push_back(letter);
		}

		//transform char vector into strings
		string temp;
		for (int i = 0; i < c_sentence.size(); i++) {
			if(!isspace(c_sentence[i]) && (!ispunct(c_sentence[i]) || c_sentence[i] == '\'' || c_sentence[i] == '-')){
				temp += tolower(c_sentence[i]);
			}
			else if (isspace(c_sentence[i])) {
				replace_apostrophes(temp, s_words);
				s_words.push_back(temp);
				temp = "";
			}

			if (i == c_sentence.size() - 1) {
				replace_apostrophes(temp, s_words);
				s_words.push_back(temp);
				temp = "";
			}
		}

		//sort and output new sentence without duplicate words
		sort(s_words);
		for (int i = 0; i < s_words.size(); i++) {
			if (i == 0) {
				//cout << s_words[i] << endl;
				_ost << s_words[i] << endl;
			}
			if (i > 0 && s_words[i] != s_words[i - 1]) {
				//cout << s_words[i] << endl;
				_ost << s_words[i] << endl;
			}
		}
	}
}

int main()
try
{
	string iname = "input/p409_8_blind_text.txt";
	ifstream ist{ iname };

	string oname = "output/p409_8_blind_text_output.txt";
	ofstream ost{ oname };

	process(ist, ost);
	cout << "Done!" << endl;
	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
Done!
Please enter a character to exit
Input-File: p409_8_blind_text.txt
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.
Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.
Nullam dictum felis eu pede mollis pretium. Integer tincidunt.
Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim.
Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum.
Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus.
Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt.
Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
Output-File: p409_8_blind_text_output.txt
a
ac
adipiscing
aenean
aliquam
aliquet
amet
ante
arcu
augue
bibendum
blandit
commodo
condimentum
consectetuer
consequat
cras
cum
curabitur
cursus
dapibus
dictum
dis
dolor
donec
dui
duis
eget
eleifend
elementum
elit
enim
eros
et
etiam
eu
faucibus
felis
feugiat
fringilla
hendrerit
id
imperdiet
in
integer
ipsum
justo
laoreet
leo
libero
ligula
lorem
luctus
maecenas
magna
magnis
massa
mauris
metus
mollis
montes
mus
nam
nascetur
natoque
nec
neque
nibh
nisi
nulla
nullam
nunc
odio
orci
parturient
pede
pellentesque
penatibus
phasellus
porttitor
pretium
pulvinar
quam
quis
quisque
rhoncus
ridiculus
rutrum
sagittis
sapien
sed
sem
semper
sit
sociis
sodales
tellus
tempus
tincidunt
ullamcorper
ultricies
ut
varius
vel
velit
venenatis
vitae
vivamus
viverra
vulputate

replace apostrophes

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 7
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 7

#include "std_lib_facilities.h"

void replace_apostrophes(string& _w) {
	if (_w == "can't" || _w == "can't ") {
		_w = "cannot ";
	}
	if (_w == "won't" || _w == "won't ") {
		_w = "will not ";
	}
	//in case word with apostrophe is in the end of the sentence
	if (_w[_w.size() - 1] == ' ') {
		if (_w[_w.size() - 2] == 't' &&
			_w[_w.size() - 3] == '\'' &&
			_w[_w.size() - 4] == 'n') {
			string temp = "";
			for (int i = 0; i < _w.size() - 4; i++) {
				temp += _w[i];
			}
			_w = temp + " not ";
		}
	}
	//in case word is in the beginning or in the middle of the sentence
	else {
		if (_w[_w.size() - 1] == 't' &&
			_w[_w.size() - 2] == '\'' &&
			_w[_w.size() - 3] == 'n') {
			string temp = "";
			for (int i = 0; i < _w.size() - 3; i++) {
				temp += _w[i];
			}
			_w = temp + " not ";
		}
	}
}

void calculate() {
	while (true) {
		//init
		cout << "enter a sentence" << endl;
		char quit;
		if (cin >> quit && quit == 'x') {
			break;
		}
		cin.putback(quit);

		//get chars and print them
		char let;
		vector<char> c_sentence;
		vector<string> s_words;
		while (cin.get(let)) {
			if (let == '\n') {
				break;
			}
			else {
				c_sentence.push_back(let);
			}
		}

		//you entered
		cout << "you entered: ";
		for (char l : c_sentence) {
			cout << l;
		}
		cout << "\n";

		//transform char vector into strings
		string temp;
		for (int i = 0; i < c_sentence.size(); i++) {
			if (!isspace(c_sentence[i])) {
				temp += tolower(c_sentence[i]);
			}
			else {
				if (i != c_sentence.size() - 1) {
					temp += tolower(c_sentence[i]);
				}
				replace_apostrophes(temp);
				s_words.push_back(temp);
				temp = "";
			}
			if (i == c_sentence.size() - 1) {
				replace_apostrophes(temp);
				s_words.push_back(temp);
				temp = "";
			}
		}

		//output new sentence
		for (string w : s_words) {
			cout << w;
		}
		cout << "\n";
	}
}

int main()
try
{
	calculate();
	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
enter a sentence
Can't stop, won't stop writing...
you entered: Can't stop, won't stop writing...
cannot stop, will not stop writing...
enter a sentence

replace punctuation with a whitespace

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 6
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 6

#include "std_lib_facilities.h"

void calculate() {
	while (cin) {
		string s;
		string s_mod;
		char quit;
		cout << "enter string and I will replace punctuation with a whitespace" << endl;
		if (cin >> quit && quit == 'x') {
			break;
		}
		cin.putback(quit);
		if (getline(cin, s)) {
			for (char c : s) {
				if (!ispunct(c)) {
					s_mod += c;
				}
				else {
					s_mod += " ";
				}
			}
			cout << s_mod << endl;
		}
		else {
			cin.clear();
			cout << "enter a valid string or x to quit" << endl;
		}
	}
}

int main()
try
{
	calculate();
	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
enter string and I will replace punctuation with a whitespace
Hello world, how are you today? Hope fine as usual.
Hello world  how are you today  Hope fine as usual
enter string and I will replace punctuation with a whitespace

char classification

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 5
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 5

#include "std_lib_facilities.h"

void calculate() {
	while (cin) {
		string word;
		char quit;
		cout << "enter string or char to decompose and classifie" << endl;
		if (cin >> quit && quit == 'x') {
			break;
		}
		cin.putback(quit);
		if (cin >> word) {
			for (char c : word) {
				if (isspace(c)) {
					cout << c << " is a space." << endl;
				}
				if (isalpha(c)) {
					cout << c << " is a letter." << endl;
				}
				if (isdigit(c)) {
					cout << c << " is a decimal digit." << endl;
				}
				if (isxdigit(c)) {
					cout << c << " is a hexadecimal digit." << endl;
				}
				if (isupper(c)) {
					cout << c << " is an upper case letter." << endl;
				}
				if (islower(c)) {
					cout << c << " is an lower case letter." << endl;
				}
				if (isalnum(c)) {
					cout << c << " is a letter or a decimal digit." << endl;
				}
				if (iscntrl(c)) {
					cout << c << " is a control character." << endl;
				}
				if (ispunct(c)) {
					cout << c << " is not a letter, digit, whitespace or invisible control character." << endl;
				}
				if (isprint(c)) {
					cout << c << " is printable." << endl;
				}
				if (isgraph(c)) {
					cout << c << " is isalpha(c) or isdigit(c) or ispunct(c)." << endl;
				}
			}
		}
		else {
			cin.clear();
			cout << "enter a valid string or x to quit" << endl;
		}
	}
}

int main()
try
{
	calculate();
	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
enter string or char to decompose and classifie
hello
h is a letter.
h is an lower case letter.
h is a letter or a decimal digit.
h is printable.
h is isalpha(c) or isdigit(c) or ispunct(c).
e is a letter.
e is a hexadecimal digit.
e is an lower case letter.
e is a letter or a decimal digit.
e is printable.
e is isalpha(c) or isdigit(c) or ispunct(c).
l is a letter.
l is an lower case letter.
l is a letter or a decimal digit.
l is printable.
l is isalpha(c) or isdigit(c) or ispunct(c).
l is a letter.
l is an lower case letter.
l is a letter or a decimal digit.
l is printable.
l is isalpha(c) or isdigit(c) or ispunct(c).
o is a letter.
o is an lower case letter.
o is a letter or a decimal digit.
o is printable.
o is isalpha(c) or isdigit(c) or ispunct(c).
enter string or char to decompose and classifie

convert hexadecimal, octal and decimal input to decimal

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 4
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 4

#include "std_lib_facilities.h"

void convert() {
	char quit;
	int val;
	char prefix_zero;
	char prefix_x;

	while (cin) {
		if (cin >> quit && quit == 'x') {
			break;
		}
		else {
			cin.putback(quit);
			cin >> prefix_zero;
			if (prefix_zero == '0') {
				if (cin >> prefix_x && prefix_x == 'x') {
					cin.putback(prefix_x);
					cin.putback(prefix_zero);
					cin >> hex >> val;
					cout << setw(4) << "0x" << hex << val
						<< " hexadecimal\tconverts to\t"
						<< dec << val << " decimal" << endl;
				}
				else {
					cin.putback(prefix_x);
					cin.putback(prefix_zero);
					cin >> oct >> val;
					cout << setw(3) << "0" << oct << val
						<< " octal\t\tconverts to\t"
						<< dec << val << " decimal" << endl;
				}
			}
			else {
				cin.putback(prefix_zero);
				cin >> dec >> val;
				cout << setw(6) << val
					<< " decimal\t\tconverts to\t"
					<< val << " decimal" << endl;
			}
		}
	}
}

void calculate() {
	cout << "enter hexadecimals e.: 0x43, octals e.: 0123 or decimals e.: 65" << endl;
	convert();
}

int main()
try
{
	calculate();
	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
enter hexadecimals e.: 0x43, octals e.: 0123 or decimals e.: 65
0x43
  0x43 hexadecimal      converts to     67 decimal
0123
  0123 octal            converts to     83 decimal
65
    65 decimal          converts to     65 decimal

disemvowel text input

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 3
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 2

#include "std_lib_facilities.h"

void lower_case(string& _text) {
	for (char& x : _text) {
		x = tolower(x);
	}
}

void input(vector<string>& _text, string _word) {
	string iname = "input/p408_2_blind_text.txt";
	ifstream ifs{ iname };

	string temp;

	while (getline(ifs, temp)) {
		lower_case(temp);
		_text.push_back(temp);
	}
}

vector<int> find_word(vector<string>& _text, string _word) {
	vector<int> index;
	int count = 0;

	for (string t : _text) {
		for (int i = 0; i < t.size(); i++) {
			string temp;
			if (t[i] == _word[0]) {
				for (int j = 0; j < _word.size(); j++){
					temp += t[i + j];
				}
			}
			if (temp.size() == _word.size()) {
				if (temp == _word) {
					cout << count << " " << t << endl;
					index.push_back(count);
					count++;
				}
			}
		}
	}

	return index;
}

void output(vector<string>& _text, vector<int> _index) {
	string oname = "output/p408_2_blind_text_out.txt";
	ofstream ofs{ oname };

	string temp;
	for (int i = 0; i < _index.size(); i++){
		temp += (to_string(_index[i]) + " " + _text[_index[i]] + "\n");
		
	}

	ofs << temp;
}

int main()
try
{
	vector<string> text;
	vector<int> index;
	string word = "lorem";

	input(text, word);
	index = find_word(text, word);
	output(text, index);

	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
Lrm psm dlr st mt, cnscttr dpscng lt. Ann cmmd lgl gt dlr.
Ann mss. Cm scs ntq pntbs t mgns ds prtrnt mnts, nsctr rdcls ms.
Dnc qm fls, ltrcs nc, pllntsq , prtm qs, sm. Nll cnsqt mss qs nm.
Dnc pd jst, frngll vl, lqt nc, vlptt gt, rc.
In nm jst, rhncs t, mprdt , vnnts vt, jst.
Nllm dctm fls  pd mlls prtm. Intgr tncdnt.
Crs dpbs. Vvms lmntm smpr ns. Ann vlptt lfnd tlls.
Ann l lgl, prtttr , cnsqt vt, lfnd c, nm.
Alqm lrm nt, dpbs n, vvrr qs, fgt , tlls. Phslls vvrr nll t mts vrs lrt.
Qsq rtrm. Ann mprdt. Etm ltrcs ns vl g. Crbtr llmcrpr ltrcs ns. Nm gt d.
Etm rhncs. Mcns tmps, tlls gt cndmntm rhncs, sm qm smpr lbr, st mt dpscng sm nq sd psm.
Nm qm nnc, blndt vl, lcts plvnr, hndrrt d, lrm. Mcns nc d t nt tncdnt tmps.
Dnc vt spn t lbr vnnts fcbs. Nllm qs nt. Etm st mt rc gt rs fcbs tncdnt.
Ds l. Sd frngll mrs st mt nbh. Dnc sdls sgtts mgn. Sd cnsqt, l gt bbndm sdls, g vlt crss nnc,
Please enter a character to exit
Input-File: p408_3_blind_text.txt
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
Output-File: p408_3_blind_text_out.txt
Lrm psm dlr st mt, cnscttr dpscng lt. Ann cmmd lgl gt dlr.
Ann mss. Cm scs ntq pntbs t mgns ds prtrnt mnts, nsctr rdcls ms.
Dnc qm fls, ltrcs nc, pllntsq , prtm qs, sm. Nll cnsqt mss qs nm.
Dnc pd jst, frngll vl, lqt nc, vlptt gt, rc.
In nm jst, rhncs t, mprdt , vnnts vt, jst.
Nllm dctm fls  pd mlls prtm. Intgr tncdnt.
Crs dpbs. Vvms lmntm smpr ns. Ann vlptt lfnd tlls.
Ann l lgl, prtttr , cnsqt vt, lfnd c, nm.
Alqm lrm nt, dpbs n, vvrr qs, fgt , tlls. Phslls vvrr nll t mts vrs lrt.
Qsq rtrm. Ann mprdt. Etm ltrcs ns vl g. Crbtr llmcrpr ltrcs ns. Nm gt d.
Etm rhncs. Mcns tmps, tlls gt cndmntm rhncs, sm qm smpr lbr, st mt dpscng sm nq sd psm.
Nm qm nnc, blndt vl, lcts plvnr, hndrrt d, lrm. Mcns nc d t nt tncdnt tmps.
Dnc vt spn t lbr vnnts fcbs. Nllm qs nt. Etm st mt rc gt rs fcbs tncdnt.
Ds l. Sd frngll mrs st mt nbh. Dnc sdls sgtts mgn. Sd cnsqt, l gt bbndm sdls, g vlt crss nnc,

find word containing line

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 2
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 2

#include "std_lib_facilities.h"

void lower_case(string& _text) {
	for (char& x : _text) {
		x = tolower(x);
	}
}

void input(vector<string>& _text, string _word) {
	string iname = "input/p408_2_blind_text.txt";
	ifstream ifs{ iname };

	string temp;

	while (getline(ifs, temp)) {
		lower_case(temp);
		_text.push_back(temp);
	}
}

vector<int> find_word(vector<string>& _text, string _word) {
	vector<int> index;
	int count = 0;

	for (string t : _text) {
		for (int i = 0; i < t.size(); i++) {
			string temp;
			if (t[i] == _word[0]) {
				for (int j = 0; j < _word.size(); j++){
					temp += t[i + j];
				}
			}
			if (temp.size() == _word.size()) {
				if (temp == _word) {
					cout << count << " " << t << endl;
					index.push_back(count);
					count++;
				}
			}
		}
	}

	return index;
}

void output(vector<string>& _text, vector<int> _index) {
	string oname = "output/p408_2_blind_text_out.txt";
	ofstream ofs{ oname };

	string temp;
	for (int i = 0; i < _index.size(); i++){
		temp += (to_string(_index[i]) + " " + _text[_index[i]] + "\n");
		
	}

	ofs << temp;
}

int main()
try
{
	vector<string> text;
	vector<int> index;
	string word = "lorem";

	input(text, word);
	index = find_word(text, word);
	output(text, index);

	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
0 lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean commodo ligula eget dolor.
1 aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. phasellus viverra nulla ut metus varius laoreet.
2 nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. maecenas nec odio et ante tincidunt tempus.
Please enter a character to exit
Input-File: p408_2_blind_text.txt
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
Output-File: p408_2_blind_text_out.txt
0 lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean commodo ligula eget dolor.
1 aenean massa. cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
2 donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. nulla consequat massa quis enim.

transform text to all lower case letters

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Exercise 1
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Exercise 1

#include "std_lib_facilities.h"

void to_lower_case_out() {
	string iname = "input/p408_1_blind_text.txt";
	ifstream ifs{ iname };

	string temp;
	getline(ifs, temp);

	for (char& x : temp) {
		x = tolower(x);
	}

	string oname = "output/p408_1_blind_text_out.txt";
	ofstream ofs{ oname };
	ofs << temp;
}

int main()
try
{
	to_lower_case_out();
	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
Please enter a character to exit
Input-File: p408_1_blind_text.txt
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
Output-File: p408_1_blind_text_out.txt
lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean commodo ligula eget dolor. aenean massa. cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. nulla consequat massa quis enim. donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. in enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. nullam dictum felis eu pede mollis pretium. integer tincidunt. cras dapibus. vivamus elementum semper nisi. aenean vulputate eleifend tellus. aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. phasellus viverra nulla ut metus varius laoreet. quisque rutrum. aenean imperdiet. etiam ultricies nisi vel augue. curabitur ullamcorper ultricies nisi. nam eget dui. etiam rhoncus. maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. maecenas nec odio et ante tincidunt tempus. donec vitae sapien ut libero venenatis faucibus. nullam quis ante. etiam sit amet orci eget eros faucibus tincidunt. duis leo. sed fringilla mauris sit amet nibh. donec sodales sagittis magna. sed consequat, leo eget bibendum sodales, augue velit cursus nunc,

set output field width

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Drill 10
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Drill 10

#include "std_lib_facilities.h"

int main()
try
{
	int width = 25;
	cout << setw(width) << "last name" << ", "
		<< setw(width) << "first name" << ", "
		<< setw(width) << "number" << ", "
		<< setw(width) << "email" << endl;
	cout << setw(width) << "Siedler" << ", "
		<< setw(width) << "Philipp" << ", "
		<< setw(width) << "07490166091" << ", "
		<< setw(width) << "p.d.siedler@gmail.com" << endl;

	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
                last name,                first name,                    number,                     email
                  Siedler,                   Philipp,               07490166091,     p.d.siedler@gmail.com
Please enter a character to exit

default, fixed and scientific float output

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 11 Drill 9
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 11 Drill 9

#include "std_lib_facilities.h"

void print_num(double _num) {
	int width = 12;
	cout << setw(width) << "defaultfloat\t" << defaultfloat << _num << endl;
	cout << setw(width) << "fixed\t" << fixed <<_num << endl;
	cout << setw(width) << "scientific\t" << scientific << _num << endl;
}

int main()
try
{
	double num = 1234567.89;

	print_num(num);

	keep_window_open();
}
catch (runtime_error e) {
	cout << e.what() << endl;
	keep_window_open();
}
catch (...) {
	cout << "Exiting" << endl;
	keep_window_open();
}
Output:
1234567.89
defaultfloat    1.23457e+06
fixed     1234567.890000
scientific     1.234568e+06
Please enter a character to exit