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,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.